Skip to content

Commit 4760ccf

Browse files
committed
OPENNLP-1708: Introduce new OpenNLP module structure
- defines new Maven module hierarchy - resolves OPENNLP-1709 (API) - resolves OPENNLP-1710 (Core) - resolves OPENNLP-1711 (CLI) - resolves OPENNLP-1712 (Tools) - resolves OPENNLP-1713 (Extensions) - resolves OPENNLP-1717 (API in core/dl) - resolves OPENNLP-1718 (API, RT, etc. in uima & morfologik) Note: tests separated, all passing!
1 parent 32f4ef7 commit 4760ccf

File tree

1,386 files changed

+6092
-1529
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,386 files changed

+6092
-1529
lines changed

opennlp-api/pom.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
-->
21+
22+
<project xmlns="http://maven.apache.org/POM/4.0.0"
23+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
25+
<modelVersion>4.0.0</modelVersion>
26+
<parent>
27+
<groupId>org.apache.opennlp</groupId>
28+
<artifactId>opennlp</artifactId>
29+
<version>3.0.0-SNAPSHOT</version>
30+
</parent>
31+
32+
<artifactId>opennlp-api</artifactId>
33+
<packaging>jar</packaging>
34+
<name>Apache OpenNLP API</name>
35+
36+
<dependencies>
37+
<!-- External dependencies -->
38+
<dependency>
39+
<groupId>org.slf4j</groupId>
40+
<artifactId>slf4j-api</artifactId>
41+
</dependency>
42+
</dependencies>
43+
44+
</project>

opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSample.java renamed to opennlp-api/src/main/java/opennlp/tools/chunker/ChunkSample.java

File renamed without changes.

opennlp-tools/src/main/java/opennlp/tools/chunker/Chunker.java renamed to opennlp-api/src/main/java/opennlp/tools/chunker/Chunker.java

File renamed without changes.

opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerContextGenerator.java renamed to opennlp-api/src/main/java/opennlp/tools/chunker/ChunkerContextGenerator.java

File renamed without changes.

opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerEvaluationMonitor.java renamed to opennlp-api/src/main/java/opennlp/tools/chunker/ChunkerEvaluationMonitor.java

File renamed without changes.

opennlp-tools/src/main/java/opennlp/tools/cmdline/ArgumentParser.java renamed to opennlp-api/src/main/java/opennlp/tools/cmdline/ArgumentParser.java

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public static <T> String createUsage(Class<T> argProxyInterface) {
228228

229229
/**
230230
* Auxiliary record that holds information about an argument. This is used by the
231-
* {@link GenerateManualTool}, which creates a Docbook for the CLI automatically.
231+
* {@code GenerateManualTool}, which creates a Docbook for the CLI automatically.
232232
*/
233233
record Argument(String argument, String value, String description, boolean optional) {
234234

@@ -331,10 +331,10 @@ public static String createUsage(Class<?>... argProxyInterfaces) {
331331
}
332332
}
333333

334-
if (usage.length() > 0)
334+
if (!usage.isEmpty())
335335
usage.setLength(usage.length() - 1);
336336

337-
if (details.length() > 0) {
337+
if (!details.isEmpty()) {
338338
details.setLength(details.length() - 1);
339339
usage.append("\n\nArguments description:\n").append(details);
340340
}
@@ -398,8 +398,8 @@ public static String validateArgumentsLoudly(String[] args, Class<?>... argProxy
398398
for (Class<?> argProxyInterface : argProxyInterfaces) {
399399
for (Method method : argProxyInterface.getMethods()) {
400400
String paramName = methodNameToParameter(method.getName());
401-
int paramIndex = CmdLineUtil.getParameterIndex(paramName, args);
402-
String valueString = CmdLineUtil.getParameter(paramName, args);
401+
int paramIndex = getParameterIndex(paramName, args);
402+
String valueString = getParameter(paramName, args);
403403
if (valueString == null) {
404404
OptionalParameter optionalParam = method.getAnnotation(OptionalParameter.class);
405405

@@ -456,7 +456,7 @@ public static <T> T parse(String[] args, Class<T> argProxyInterface) {
456456
for (Method method : argProxyInterface.getMethods()) {
457457

458458
String parameterName = methodNameToParameter(method.getName());
459-
String valueString = CmdLineUtil.getParameter(parameterName, args);
459+
String valueString = getParameter(parameterName, args);
460460

461461
if (valueString == null) {
462462
OptionalParameter optionalParam = method.getAnnotation(OptionalParameter.class);
@@ -503,10 +503,10 @@ public static <T> String[] filter(String[] args, Class<T> argProxyInterface) {
503503
for (Method method : argProxyInterface.getMethods()) {
504504

505505
String parameterName = methodNameToParameter(method.getName());
506-
int idx = CmdLineUtil.getParameterIndex(parameterName, args);
506+
int idx = getParameterIndex(parameterName, args);
507507
if (-1 < idx) {
508508
parameters.add(parameterName);
509-
String valueString = CmdLineUtil.getParameter(parameterName, args);
509+
String valueString = getParameter(parameterName, args);
510510
if (null != valueString) {
511511
parameters.add(valueString);
512512
}
@@ -515,4 +515,61 @@ public static <T> String[] filter(String[] args, Class<T> argProxyInterface) {
515515

516516
return parameters.toArray(new String[0]);
517517
}
518+
519+
/**
520+
* Retrieves the specified parameter from the specified arguments.
521+
*
522+
* @param param parameter name
523+
* @param args arguments
524+
* @return parameter value
525+
*/
526+
private static Integer getIntParameter(String param, String[] args) {
527+
String value = getParameter(param, args);
528+
529+
try {
530+
if (value != null)
531+
return Integer.parseInt(value);
532+
}
533+
catch (NumberFormatException ignored) {
534+
// in this case return null
535+
}
536+
537+
return null;
538+
}
539+
540+
/**
541+
* Retrieves the specified parameter from the given arguments.
542+
*
543+
* @param param parameter name
544+
* @param args arguments
545+
* @return parameter value
546+
*/
547+
private static String getParameter(String param, String[] args) {
548+
int i = getParameterIndex(param, args);
549+
if (-1 < i) {
550+
i++;
551+
if (i < args.length) {
552+
return args[i];
553+
}
554+
}
555+
556+
return null;
557+
}
558+
559+
/**
560+
* Returns the index of the parameter in the arguments, or {@code -1} if the parameter is not found.
561+
*
562+
* @param param parameter name
563+
* @param args arguments
564+
* @return the index of the parameter in the arguments, or {@code -1} if the parameter is not found
565+
*/
566+
private static int getParameterIndex(String param, String[] args) {
567+
for (int i = 0; i < args.length; i++) {
568+
if (args[i].startsWith("-") && args[i].equals(param)) {
569+
return i;
570+
}
571+
}
572+
573+
return -1;
574+
}
518575
}

opennlp-tools/src/main/java/opennlp/tools/cmdline/ObjectStreamFactory.java renamed to opennlp-api/src/main/java/opennlp/tools/cmdline/ObjectStreamFactory.java

File renamed without changes.

opennlp-tools/src/main/java/opennlp/tools/cmdline/TerminateToolException.java renamed to opennlp-api/src/main/java/opennlp/tools/cmdline/TerminateToolException.java

File renamed without changes.

opennlp-tools/src/main/java/opennlp/tools/cmdline/params/BasicFormatParams.java renamed to opennlp-api/src/main/java/opennlp/tools/cmdline/params/BasicFormatParams.java

File renamed without changes.

opennlp-tools/src/main/java/opennlp/tools/cmdline/params/BasicTrainingParams.java renamed to opennlp-api/src/main/java/opennlp/tools/cmdline/params/BasicTrainingParams.java

File renamed without changes.

0 commit comments

Comments
 (0)