You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by jo...@apache.org on 2017/01/06 21:07:32 UTC
[3/9] opennlp git commit: Correct indentation and white spaces
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java
index 4998545..2eb3585 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java
@@ -49,12 +49,12 @@ public class SentenceDetectorME implements SentenceDetector {
/**
* Constant indicates a sentence split.
*/
- public static final String SPLIT ="s";
+ public static final String SPLIT = "s";
/**
* Constant indicates no sentence split.
*/
- public static final String NO_SPLIT ="n";
+ public static final String NO_SPLIT = "n";
/**
* The maximum entropy model to use to evaluate contexts.
@@ -113,7 +113,7 @@ public class SentenceDetectorME implements SentenceDetector {
}
private static Set<String> getAbbreviations(Dictionary abbreviations) {
- if(abbreviations == null) {
+ if (abbreviations == null) {
return Collections.<String>emptySet();
}
return abbreviations.asStringSet();
@@ -177,7 +177,7 @@ public class SentenceDetectorME implements SentenceDetector {
if (i + 1 < end && enders.get(i + 1) < fws) {
continue;
}
- if(positions.size() > 0 && cint < positions.get(positions.size()-1)) continue;
+ if (positions.size() > 0 && cint < positions.get(positions.size() - 1)) continue;
double[] probs = model.eval(cgen.getContext(sb, cint));
String bestOutcome = model.getBestOutcome(probs);
@@ -205,37 +205,37 @@ public class SentenceDetectorME implements SentenceDetector {
// string does not contain sentence end positions
if (starts.length == 0) {
- // remove leading and trailing whitespace
- int start = 0;
- int end = s.length();
+ // remove leading and trailing whitespace
+ int start = 0;
+ int end = s.length();
- while (start < s.length() && StringUtil.isWhitespace(s.charAt(start)))
- start++;
+ while (start < s.length() && StringUtil.isWhitespace(s.charAt(start)))
+ start++;
- while (end > 0 && StringUtil.isWhitespace(s.charAt(end - 1)))
- end--;
+ while (end > 0 && StringUtil.isWhitespace(s.charAt(end - 1)))
+ end--;
- if (end - start > 0) {
- sentProbs.add(1d);
- return new Span[] {new Span(start, end)};
- }
- else
- return new Span[0];
+ if (end - start > 0) {
+ sentProbs.add(1d);
+ return new Span[] {new Span(start, end)};
+ }
+ else
+ return new Span[0];
}
// Convert the sentence end indexes to spans
boolean leftover = starts[starts.length - 1] != s.length();
- Span[] spans = new Span[leftover? starts.length + 1 : starts.length];
+ Span[] spans = new Span[leftover ? starts.length + 1 : starts.length];
- for (int si=0; si < starts.length; si++) {
+ for (int si = 0; si < starts.length; si++) {
int start;
- if (si==0) {
+ if (si == 0) {
start = 0;
}
else {
- start = starts[si-1];
+ start = starts[si - 1];
}
// A span might contain only white spaces, in this case the length of
@@ -250,9 +250,9 @@ public class SentenceDetectorME implements SentenceDetector {
}
if (leftover) {
- Span span = new Span(starts[starts.length-1],s.length()).trim(s);
+ Span span = new Span(starts[starts.length - 1], s.length()).trim(s);
if (span.length() > 0) {
- spans[spans.length-1] = span;
+ spans[spans.length - 1] = span;
sentProbs.add(1d);
}
}
@@ -261,7 +261,7 @@ public class SentenceDetectorME implements SentenceDetector {
*/
for (int i = 0; i < spans.length; i++) {
double prob = sentProbs.get(i);
- spans[i]= new Span(spans[i], prob);
+ spans[i] = new Span(spans[i], prob);
}
@@ -273,8 +273,7 @@ public class SentenceDetectorME implements SentenceDetector {
* calls to sentDetect().
*
* @return probability for each sentence returned for the most recent
- * call to sentDetect. If not applicable an empty array is
- * returned.
+ * call to sentDetect. If not applicable an empty array is returned.
*/
public double[] getSentenceProbabilities() {
double[] sentProbArray = new double[sentProbs.size()];
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceModel.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceModel.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceModel.java
index 9355f88..cdd0346 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceModel.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceModel.java
@@ -116,7 +116,7 @@ public class SentenceModel extends BaseModel {
if (!ModelUtil.validateOutcomes(getMaxentModel(), SentenceDetectorME.SPLIT,
SentenceDetectorME.NO_SPLIT)) {
throw new InvalidFormatException("The maxent model is not compatible " +
- "with the sentence detector!");
+ "with the sentence detector!");
}
}
@@ -155,7 +155,7 @@ public class SentenceModel extends BaseModel {
}
public static void main(String[] args) throws FileNotFoundException, IOException, InvalidFormatException {
- if (args.length < 3){
+ if (args.length < 3) {
System.err.println("SentenceModel [-abbreviationsDictionary] [-useTokenEnd] languageCode packageName modelName");
System.exit(1);
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceSample.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceSample.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceSample.java
index d168150..71f50db 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceSample.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceSample.java
@@ -78,8 +78,8 @@ public class SentenceSample {
/**
* Retrieves the sentences.
*
- * @return the begin indexes of the sentences
- * in the document.
+ * @return the begin indexes of the sentences in the document.
+
*/
public Span[] getSentences() {
return sentences.toArray(new Span[sentences.size()]);
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/Factory.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/Factory.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/Factory.java
index d182b26..9d4647d 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/Factory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/Factory.java
@@ -52,7 +52,7 @@ public class Factory {
if ("th".equals(languageCode)) {
return new SentenceContextGenerator();
- } else if("pt".equals(languageCode)) {
+ } else if ("pt".equals(languageCode)) {
return new DefaultSDContextGenerator(abbreviations, ptEosCharacters);
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/th/SentenceContextGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/th/SentenceContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/th/SentenceContextGenerator.java
index abf5aa7..baab080 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/th/SentenceContextGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/th/SentenceContextGenerator.java
@@ -43,20 +43,20 @@ public class SentenceContextGenerator extends DefaultSDContextGenerator {
collectFeats.add(buf.toString());
buf.setLength(0);
- collectFeats.add("p1="+prefix.substring(Math.max(prefix.length()-1,0)));
- collectFeats.add("p2="+prefix.substring(Math.max(prefix.length()-2,0)));
- collectFeats.add("p3="+prefix.substring(Math.max(prefix.length()-3,0)));
- collectFeats.add("p4="+prefix.substring(Math.max(prefix.length()-4,0)));
- collectFeats.add("p5="+prefix.substring(Math.max(prefix.length()-5,0)));
- collectFeats.add("p6="+prefix.substring(Math.max(prefix.length()-6,0)));
- collectFeats.add("p7="+prefix.substring(Math.max(prefix.length()-7,0)));
-
- collectFeats.add("n1="+suffix.substring(0,Math.min(1,suffix.length())));
- collectFeats.add("n2="+suffix.substring(0,Math.min(2,suffix.length())));
- collectFeats.add("n3="+suffix.substring(0,Math.min(3,suffix.length())));
- collectFeats.add("n4="+suffix.substring(0,Math.min(4,suffix.length())));
- collectFeats.add("n5="+suffix.substring(0,Math.min(5,suffix.length())));
- collectFeats.add("n6="+suffix.substring(0,Math.min(6,suffix.length())));
- collectFeats.add("n7="+suffix.substring(0,Math.min(7,suffix.length())));
+ collectFeats.add("p1=" + prefix.substring(Math.max(prefix.length() - 1,0)));
+ collectFeats.add("p2=" + prefix.substring(Math.max(prefix.length() - 2,0)));
+ collectFeats.add("p3=" + prefix.substring(Math.max(prefix.length() - 3,0)));
+ collectFeats.add("p4=" + prefix.substring(Math.max(prefix.length() - 4,0)));
+ collectFeats.add("p5=" + prefix.substring(Math.max(prefix.length() - 5,0)));
+ collectFeats.add("p6=" + prefix.substring(Math.max(prefix.length() - 6,0)));
+ collectFeats.add("p7=" + prefix.substring(Math.max(prefix.length() - 7,0)));
+
+ collectFeats.add("n1=" + suffix.substring(0,Math.min(1, suffix.length())));
+ collectFeats.add("n2=" + suffix.substring(0,Math.min(2, suffix.length())));
+ collectFeats.add("n3=" + suffix.substring(0,Math.min(3, suffix.length())));
+ collectFeats.add("n4=" + suffix.substring(0,Math.min(4, suffix.length())));
+ collectFeats.add("n5=" + suffix.substring(0,Math.min(5, suffix.length())));
+ collectFeats.add("n6=" + suffix.substring(0,Math.min(6, suffix.length())));
+ collectFeats.add("n7=" + suffix.substring(0,Math.min(7, suffix.length())));
}
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/tokenize/DefaultTokenContextGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/DefaultTokenContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/DefaultTokenContextGenerator.java
index 8050bdd..99c717d 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/DefaultTokenContextGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/DefaultTokenContextGenerator.java
@@ -91,7 +91,7 @@ public class DefaultTokenContextGenerator implements TokenContextGenerator {
preds.add("p1=bok");
}
addCharPreds("f1", sentence.charAt(index), preds);
- if (index+1 < sentence.length()) {
+ if (index + 1 < sentence.length()) {
addCharPreds("f2", sentence.charAt(index + 1), preds);
preds.add("f12=" + sentence.charAt(index) + sentence.charAt(index + 1));
}
@@ -102,7 +102,7 @@ public class DefaultTokenContextGenerator implements TokenContextGenerator {
preds.add("cc");//character code
}
- if(index == sentence.length() - 1 && inducedAbbreviations.contains(sentence)) {
+ if (index == sentence.length() - 1 && inducedAbbreviations.contains(sentence)) {
preds.add("pabb");
}
@@ -128,16 +128,16 @@ public class DefaultTokenContextGenerator implements TokenContextGenerator {
preds.add(key + "_ws");
}
else {
- if (c=='.' || c=='?' || c=='!') {
+ if (c == '.' || c == '?' || c == '!') {
preds.add(key + "_eos");
}
- else if (c=='`' || c=='"' || c=='\'') {
+ else if (c == '`' || c == '"' || c == '\'') {
preds.add(key + "_quote");
}
- else if (c=='[' || c=='{' || c=='(') {
+ else if (c == '[' || c == '{' || c == '(') {
preds.add(key + "_lp");
}
- else if (c==']' || c=='}' || c==')') {
+ else if (c == ']' || c == '}' || c == ')') {
preds.add(key + "_rp");
}
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/tokenize/DetokenizationDictionary.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/DetokenizationDictionary.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/DetokenizationDictionary.java
index 2fbb4a3..00d2dc7 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/DetokenizationDictionary.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/DetokenizationDictionary.java
@@ -106,7 +106,7 @@ public class DetokenizationDictionary {
}
}
- public DetokenizationDictionary(InputStream in) throws IOException, InvalidFormatException{
+ public DetokenizationDictionary(InputStream in) throws IOException, InvalidFormatException {
DictionarySerializer.create(in, new EntryInserter() {
public void insert(Entry entry) throws InvalidFormatException {
@@ -116,7 +116,7 @@ public class DetokenizationDictionary {
StringList word = entry.getTokens();
if (word.size() != 1)
- throw new InvalidFormatException("Each entry must have exactly one token! "+word);
+ throw new InvalidFormatException("Each entry must have exactly one token! " + word);
// parse operation
Operation operation = Operation.parse(operationString);
@@ -125,7 +125,8 @@ public class DetokenizationDictionary {
throw new InvalidFormatException("Unknown operation type: " + operationString);
operationTable.put(word.getToken(0), operation);
- }});
+ }
+ });
}
DetokenizationDictionary.Operation getOperation(String token) {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/tokenize/DictionaryDetokenizer.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/DictionaryDetokenizer.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/DictionaryDetokenizer.java
index 3be19db..cb38004 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/DictionaryDetokenizer.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/DictionaryDetokenizer.java
@@ -43,8 +43,7 @@ public class DictionaryDetokenizer implements Detokenizer {
Set<String> matchingTokens = new HashSet<String>();
for (int i = 0; i < tokens.length; i++) {
- DetokenizationDictionary.Operation dictOperation =
- dict.getOperation(tokens[i]);
+ DetokenizationDictionary.Operation dictOperation = dict.getOperation(tokens[i]);
if (dictOperation == null) {
operations[i] = Detokenizer.DetokenizationOperation.NO_OPERATION;
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/tokenize/SimpleTokenizer.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/SimpleTokenizer.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/SimpleTokenizer.java
index c3d4b29..03f15ca 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/SimpleTokenizer.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/SimpleTokenizer.java
@@ -38,7 +38,7 @@ public class SimpleTokenizer extends AbstractTokenizer {
/**
* @deprecated Use INSTANCE field instead to obtain an instance, constructor
- * will be made private in the future.
+ * will be made private in the future.
*/
@Deprecated
public SimpleTokenizer() {
@@ -112,8 +112,8 @@ public class SimpleTokenizer extends AbstractTokenizer {
if (tokens.length > 0) {
System.out.print(tokens[0]);
}
- for (int ti=1,tn=tokens.length;ti<tn;ti++) {
- System.out.print(" "+tokens[ti]);
+ for (int ti = 1,tn = tokens.length; ti < tn; ti++) {
+ System.out.print(" " + tokens[ti]);
}
System.out.println();
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokSpanEventStream.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokSpanEventStream.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokSpanEventStream.java
index b9572c6..16b1616 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokSpanEventStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokSpanEventStream.java
@@ -119,8 +119,7 @@ public class TokSpanEventStream extends AbstractEventStream<TokenSample> {
//adjust cSpan to text offsets
cSpan = new Span(cSpan.getStart() + start, cSpan.getEnd() + start);
//should we skip this token
- if (ctok.length() > 1
- && (!skipAlphaNumerics || !alphaNumeric.matcher(ctok).matches())) {
+ if (ctok.length() > 1 && (!skipAlphaNumerics || !alphaNumeric.matcher(ctok).matches())) {
//find offsets of annotated tokens inside of candidate tokens
boolean foundTrainingTokens = false;
@@ -141,7 +140,7 @@ public class TokSpanEventStream extends AbstractEventStream<TokenSample> {
else {
if (logger.isLoggable(Level.WARNING)) {
logger.warning("Bad training token: " + tokens[ti] + " cand: " + cSpan +
- " token="+text.substring(tokens[ti].getStart(), tokens[ti].getEnd()));
+ " token=" + text.substring(tokens[ti].getStart(), tokens[ti].getEnd()));
}
}
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenSample.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenSample.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenSample.java
index 1a40dd5..813eac4 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenSample.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenSample.java
@@ -162,10 +162,10 @@ public class TokenSample {
public static TokenSample parse(String sampleString, String separatorChars) {
if (sampleString == null) {
- throw new IllegalArgumentException("sampleString must not be null!");
+ throw new IllegalArgumentException("sampleString must not be null!");
}
if (separatorChars == null) {
- throw new IllegalArgumentException("separatorChars must not be null!");
+ throw new IllegalArgumentException("separatorChars must not be null!");
}
Span whitespaceTokenSpans[] = WhitespaceTokenizer.INSTANCE.tokenizePos(sampleString);
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenSampleStream.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenSampleStream.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenSampleStream.java
index 19e18c5..3fecaaf 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenSampleStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenSampleStream.java
@@ -51,7 +51,7 @@ public class TokenSampleStream extends FilterObjectStream<String, TokenSample> {
throw new IllegalArgumentException("separatorChars must not be null!");
}
- this.separatorChars= separatorChars;
+ this.separatorChars = separatorChars;
}
public TokenSampleStream(ObjectStream<String> sentences) {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/tokenize/Tokenizer.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/Tokenizer.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/Tokenizer.java
index aae4a83..7564ee3 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/Tokenizer.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/Tokenizer.java
@@ -45,21 +45,21 @@ import opennlp.tools.util.Span;
*/
public interface Tokenizer {
- /**
- * Splits a string into its atomic parts
- *
- * @param s The string to be tokenized.
- * @return The String[] with the individual tokens as the array
- * elements.
- */
- String[] tokenize(String s);
+ /**
+ * Splits a string into its atomic parts
+ *
+ * @param s The string to be tokenized.
+ * @return The String[] with the individual tokens as the array
+ * elements.
+ */
+ String[] tokenize(String s);
- /**
- * Finds the boundaries of atomic parts in a string.
- *
- * @param s The string to be tokenized.
- * @return The Span[] with the spans (offsets into s) for each
- * token as the individuals array elements.
- */
- Span[] tokenizePos(String s);
+ /**
+ * Finds the boundaries of atomic parts in a string.
+ *
+ * @param s The string to be tokenized.
+ * @return The Span[] with the spans (offsets into s) for each
+ * token as the individuals array elements.
+ */
+ Span[] tokenizePos(String s);
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerCrossValidator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerCrossValidator.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerCrossValidator.java
index fe9e4c6..42f4b34 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerCrossValidator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerCrossValidator.java
@@ -52,19 +52,19 @@ public class TokenizerCrossValidator {
CrossValidationPartitioner<TokenSample> partitioner = new CrossValidationPartitioner<>(samples, nFolds);
- while (partitioner.hasNext()) {
+ while (partitioner.hasNext()) {
- CrossValidationPartitioner.TrainingSampleStream<TokenSample> trainingSampleStream =
- partitioner.next();
+ CrossValidationPartitioner.TrainingSampleStream<TokenSample> trainingSampleStream =
+ partitioner.next();
- // Maybe throws IOException if temporary file handling fails ...
- TokenizerModel model = TokenizerME.train(trainingSampleStream, this.factory, params);
+ // Maybe throws IOException if temporary file handling fails ...
+ TokenizerModel model = TokenizerME.train(trainingSampleStream, this.factory, params);
- TokenizerEvaluator evaluator = new TokenizerEvaluator(new TokenizerME(model), listeners);
+ TokenizerEvaluator evaluator = new TokenizerEvaluator(new TokenizerME(model), listeners);
- evaluator.evaluate(trainingSampleStream.getTestSampleStream());
- fmeasure.mergeInto(evaluator.getFMeasure());
- }
+ evaluator.evaluate(trainingSampleStream.getTestSampleStream());
+ fmeasure.mergeInto(evaluator.getFMeasure());
+ }
}
public FMeasure getFMeasure() {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerME.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerME.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerME.java
index 491b6fa..4444e78 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerME.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerME.java
@@ -77,12 +77,12 @@ public class TokenizerME extends AbstractTokenizer {
/**
* Constant indicates a token split.
*/
- public static final String SPLIT ="T";
+ public static final String SPLIT = "T";
/**
* Constant indicates no token split.
*/
- public static final String NO_SPLIT ="F";
+ public static final String NO_SPLIT = "F";
/**
* Alpha-Numeric Pattern
@@ -147,7 +147,7 @@ public class TokenizerME extends AbstractTokenizer {
}
private static Set<String> getAbbreviations(Dictionary abbreviations) {
- if(abbreviations == null) {
+ if (abbreviations == null) {
return Collections.emptySet();
}
return abbreviations.asStringSet();
@@ -158,8 +158,7 @@ public class TokenizerME extends AbstractTokenizer {
* calls to {@link TokenizerME#tokenize(String)} or {@link TokenizerME#tokenizePos(String)}.
*
* @return probability for each token returned for the most recent
- * call to tokenize. If not applicable an empty array is
- * returned.
+ * call to tokenize. If not applicable an empty array is returned.
*/
public double[] getTokenProbabilities() {
double[] tokProbArray = new double[tokProbs.size()];
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerModel.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerModel.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerModel.java
index ed84b4e..497c8af 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerModel.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerModel.java
@@ -145,7 +145,7 @@ public final class TokenizerModel extends BaseModel {
}
public static void main(String[] args) throws IOException {
- if (args.length < 3){
+ if (args.length < 3) {
System.err.println("TokenizerModel [-alphaNumericOptimization] languageCode packageName modelName");
System.exit(1);
}
@@ -167,7 +167,7 @@ public final class TokenizerModel extends BaseModel {
new FileInputStream(modelName))).getModel();
TokenizerModel packageModel = new TokenizerModel(model, null,
- TokenizerFactory.create(null, languageCode, null, alphaNumericOptimization, null));
+ TokenizerFactory.create(null, languageCode, null, alphaNumericOptimization, null));
OutputStream out = null;
try {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/tokenize/WhitespaceTokenStream.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/WhitespaceTokenStream.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/WhitespaceTokenStream.java
index 4644b4e..4f6694f 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/WhitespaceTokenStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/WhitespaceTokenStream.java
@@ -48,7 +48,7 @@ public class WhitespaceTokenStream extends FilterObjectStream<TokenSample, Strin
// Shorten string by one to get rid of last space
if (whitespaceSeparatedTokenString.length() > 0) {
whitespaceSeparatedTokenString.setLength(
- whitespaceSeparatedTokenString.length() -1 );
+ whitespaceSeparatedTokenString.length() - 1 );
}
return whitespaceSeparatedTokenString.toString();
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/tokenize/WhitespaceTokenizer.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/WhitespaceTokenizer.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/WhitespaceTokenizer.java
index d51d7da..05ae04c 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/WhitespaceTokenizer.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/WhitespaceTokenizer.java
@@ -45,7 +45,7 @@ public class WhitespaceTokenizer extends AbstractTokenizer {
public Span[] tokenizePos(String d) {
int tokStart = -1;
- List<Span>tokens = new ArrayList<Span>();
+ List<Span> tokens = new ArrayList<Span>();
boolean inTok = false;
//gather up potential tokens
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/tokenize/lang/Factory.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/lang/Factory.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/lang/Factory.java
index 416621e..ef2a9f8 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/lang/Factory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/lang/Factory.java
@@ -37,7 +37,7 @@ public class Factory {
* @return the alpha numeric pattern for the language or the default pattern.
*/
public Pattern getAlphanumeric(String languageCode) {
- if("pt".equals(languageCode)) {
+ if ("pt".equals(languageCode)) {
return Pattern.compile("^[0-9a-z�������������A-Z�������������]+$");
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/tokenize/lang/en/TokenSampleStream.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/lang/en/TokenSampleStream.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/lang/en/TokenSampleStream.java
index d95d05b..8006d7b 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/lang/en/TokenSampleStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/lang/en/TokenSampleStream.java
@@ -53,14 +53,14 @@ public class TokenSampleStream implements Iterator<TokenSample> {
public TokenSample next() {
String[] tokens = line.split("\\s+");
if (tokens.length == 0) {
- evenq =true;
+ evenq = true;
}
StringBuilder sb = new StringBuilder(line.length());
List<Span> spans = new ArrayList<Span>();
int length = 0;
- for (int ti=0;ti<tokens.length;ti++) {
+ for (int ti = 0; ti < tokens.length; ti++) {
String token = tokens[ti];
- String lastToken = ti -1 >= 0 ? tokens[ti-1] : "";
+ String lastToken = ti - 1 >= 0 ? tokens[ti - 1] : "";
if (token.equals("-LRB-")) {
token = "(";
}
@@ -79,7 +79,7 @@ public class TokenSampleStream implements Iterator<TokenSample> {
else if (!alphaNumeric.matcher(token).find() || token.startsWith("'") || token.equalsIgnoreCase("n't")) {
if ((token.equals("``") || token.equals("--") || token.equals("$") ||
token.equals("(") || token.equals("&") || token.equals("#") ||
- (token.equals("\"") && (evenq && ti != tokens.length-1)))
+ (token.equals("\"") && (evenq && ti != tokens.length - 1)))
&& (!lastToken.equals("(") || !lastToken.equals("{"))) {
//System.out.print(" "+token);
length++;
@@ -99,8 +99,8 @@ public class TokenSampleStream implements Iterator<TokenSample> {
}
}
if (token.equals("\"")) {
- if (ti == tokens.length -1) {
- evenq=true;
+ if (ti == tokens.length - 1) {
+ evenq = true;
}
else {
evenq = !evenq;
@@ -110,8 +110,8 @@ public class TokenSampleStream implements Iterator<TokenSample> {
sb.append(" ");
}
sb.append(token);
- spans.add(new Span(length,length+token.length()));
- length+=token.length();
+ spans.add(new Span(length, length + token.length()));
+ length += token.length();
}
//System.out.println();
try {
@@ -135,32 +135,32 @@ public class TokenSampleStream implements Iterator<TokenSample> {
public static void main(String[] args) throws IOException {
boolean showSpans = false;
- int ai=0;
+ int ai = 0;
while (ai < args.length) {
if (args[ai].equals("-spans")) {
showSpans = true;
}
else {
- System.err.println("Unknown option "+args[ai]);
+ System.err.println("Unknown option " + args[ai]);
usage();
}
ai++;
}
TokenSampleStream tss = new TokenSampleStream(System.in);
- while(tss.hasNext()) {
+ while (tss.hasNext()) {
TokenSample ts = tss.next();
String text = ts.getText();
System.out.println(text);
Span[] tokenSpans = ts.getTokenSpans();
- int ti=0;
+ int ti = 0;
if (showSpans) {
- for (int i=0;i<text.length();i++) {
- if (ti-1 >= 0 && i==tokenSpans[ti-1].getEnd()-1) {
+ for (int i = 0; i < text.length(); i++) {
+ if (ti - 1 >= 0 && i == tokenSpans[ti - 1].getEnd() - 1) {
System.out.print("]");
}
- else if (i==tokenSpans[ti].getStart()) {
+ else if (i == tokenSpans[ti].getStart()) {
ti++;
- if (ti-1 >= 0 && i==tokenSpans[ti-1].getEnd()-1) {
+ if (ti - 1 >= 0 && i == tokenSpans[ti - 1].getEnd() - 1) {
System.out.print("|");
}
else {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/AbstractEventStream.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/AbstractEventStream.java b/opennlp-tools/src/main/java/opennlp/tools/util/AbstractEventStream.java
index c636378..20184ea 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/AbstractEventStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/AbstractEventStream.java
@@ -43,10 +43,10 @@ public abstract class AbstractEventStream<T> implements ObjectStream<Event> {
* Creates events for the provided sample.
*
* @param sample the sample for which training {@link Event}s
- * are be created.
+ * are be created.
*
* @return an {@link Iterator} of training events or
- * an empty {@link Iterator}.
+ * an empty {@link Iterator}.
*/
protected abstract Iterator<Event> createEvents(T sample);
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/BaseToolFactory.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/BaseToolFactory.java b/opennlp-tools/src/main/java/opennlp/tools/util/BaseToolFactory.java
index 499aa8f..448bc85 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/BaseToolFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/BaseToolFactory.java
@@ -46,9 +46,9 @@ public abstract class BaseToolFactory {
public BaseToolFactory() {
}
- /**
- * Initializes the ToolFactory with an artifact provider.
- */
+ /**
+ * Initializes the ToolFactory with an artifact provider.
+ */
protected void init(ArtifactProvider artifactProvider) {
this.artifactProvider = artifactProvider;
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/HashList.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/HashList.java b/opennlp-tools/src/main/java/opennlp/tools/util/HashList.java
index a3ee256..e88a907 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/HashList.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/HashList.java
@@ -70,7 +70,7 @@ public class HashList extends HashMap {
o.add(value);
- if(o.size() == 1)
+ if (o.size() == 1)
return null;
else
return o;
@@ -84,7 +84,7 @@ public class HashList extends HashMap {
else {
boolean r = l.remove(value);
if (l.size() == 0) {
- remove(key);
+ remove(key);
}
return r;
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/Heap.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/Heap.java b/opennlp-tools/src/main/java/opennlp/tools/util/Heap.java
index a27f333..00d79ba 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/Heap.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/Heap.java
@@ -57,11 +57,11 @@ public interface Heap<E> {
*/
int size();
- /**
- * Returns whether the heap is empty.
- * @return true if the heap is empty; false otherwise.
- */
- boolean isEmpty();
+ /**
+ * Returns whether the heap is empty.
+ * @return true if the heap is empty; false otherwise.
+ */
+ boolean isEmpty();
/**
* Returns an iterator over the elements of the heap. No specific ordering of these
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/InputStreamFactory.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/InputStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/util/InputStreamFactory.java
index 41f4872..4a57a49 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/InputStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/InputStreamFactory.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package opennlp.tools.util;
import java.io.IOException;
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/ListHeap.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/ListHeap.java b/opennlp-tools/src/main/java/opennlp/tools/util/ListHeap.java
index 7a60deb..4fdd2e8 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/ListHeap.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/ListHeap.java
@@ -194,13 +194,14 @@ public class ListHeap<E extends Comparable<E>> implements Heap<E> {
@Deprecated
public static void main(String[] args) {
- Heap<Integer> heap = new ListHeap<Integer>(5);
- for (int ai=0;ai<args.length;ai++){
- heap.add(Integer.parseInt(args[ai]));
- }
- while (!heap.isEmpty()) {
- System.out.print(heap.extract()+" ");
- }
- System.out.println();
+ Heap<Integer> heap = new ListHeap<Integer>(5);
+ for (int ai = 0; ai < args.length; ai++) {
+ heap.add(Integer.parseInt(args[ai]));
+ }
+
+ while (!heap.isEmpty()) {
+ System.out.print(heap.extract() + " ");
+ }
+ System.out.println();
}
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/MarkableFileInputStreamFactory.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/MarkableFileInputStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/util/MarkableFileInputStreamFactory.java
index 1dddf35..830e697 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/MarkableFileInputStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/MarkableFileInputStreamFactory.java
@@ -30,7 +30,7 @@ public class MarkableFileInputStreamFactory implements InputStreamFactory {
private File file;
public MarkableFileInputStreamFactory(File file) throws FileNotFoundException {
- if(!file.exists()) {
+ if (!file.exists()) {
throw new FileNotFoundException("File '" + file + "' cannot be found");
}
this.file = file;
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/ObjectStreamUtils.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/ObjectStreamUtils.java b/opennlp-tools/src/main/java/opennlp/tools/util/ObjectStreamUtils.java
index 9ad98dd..0ee8fa5 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/ObjectStreamUtils.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/ObjectStreamUtils.java
@@ -87,7 +87,7 @@ public class ObjectStreamUtils {
/**
* Creates a single concatenated ObjectStream from multiple individual
* ObjectStreams with the same type.
- *
+ *
* @param streams
* @return
*/
@@ -111,7 +111,7 @@ public class ObjectStreamUtils {
object = streams[streamIndex].read();
if (object == null)
- streamIndex++;
+ streamIndex++;
}
return object;
@@ -130,6 +130,7 @@ public class ObjectStreamUtils {
for (ObjectStream<T> stream : streams) {
stream.close();
}
- }};
+ }
+ };
}
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/PlainTextByLineStream.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/PlainTextByLineStream.java b/opennlp-tools/src/main/java/opennlp/tools/util/PlainTextByLineStream.java
index 9c7cdc1..eb3a410 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/PlainTextByLineStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/PlainTextByLineStream.java
@@ -59,7 +59,7 @@ public class PlainTextByLineStream implements ObjectStream<String> {
in = new BufferedReader(new InputStreamReader(inputStreamFactory.createInputStream(), encoding));
}
else if (channel == null) {
- in.reset();
+ in.reset();
}
else {
channel.position(0);
@@ -69,11 +69,11 @@ public class PlainTextByLineStream implements ObjectStream<String> {
public void close() throws IOException {
- if (in != null && channel == null) {
- in.close();
- }
- else if (channel != null) {
- channel.close();
- }
+ if (in != null && channel == null) {
+ in.close();
+ }
+ else if (channel != null) {
+ channel.close();
+ }
}
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/ReverseListIterator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/ReverseListIterator.java b/opennlp-tools/src/main/java/opennlp/tools/util/ReverseListIterator.java
index c7e456d..ee418d1 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/ReverseListIterator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/ReverseListIterator.java
@@ -29,8 +29,8 @@ public class ReverseListIterator<T> implements Iterator<T> {
private List<T> list;
public ReverseListIterator(List<T> list) {
- index = list.size()-1;
- this.list=list;
+ index = list.size() - 1;
+ this.list = list;
}
public T next() {
@@ -38,7 +38,7 @@ public class ReverseListIterator<T> implements Iterator<T> {
}
public boolean hasNext() {
- return index >=0;
+ return index >= 0;
}
public void remove() {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/Sequence.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/Sequence.java b/opennlp-tools/src/main/java/opennlp/tools/util/Sequence.java
index a81d958..4721cc6 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/Sequence.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/Sequence.java
@@ -36,21 +36,21 @@ public class Sequence implements Comparable<Sequence> {
}
public Sequence(Sequence s) {
- outcomes = new ArrayList<String>(s.outcomes.size()+1);
+ outcomes = new ArrayList<String>(s.outcomes.size() + 1);
outcomes.addAll(s.outcomes);
- probs = new ArrayList<Double>(s.probs.size()+1);
+ probs = new ArrayList<Double>(s.probs.size() + 1);
probs.addAll(s.probs);
score = s.score;
}
public Sequence(Sequence s,String outcome, double p) {
- outcomes = new ArrayList<String>(s.outcomes.size()+1);
+ outcomes = new ArrayList<String>(s.outcomes.size() + 1);
outcomes.addAll(s.outcomes);
outcomes.add(outcome);
- probs = new ArrayList<Double>(s.probs.size()+1);
+ probs = new ArrayList<Double>(s.probs.size() + 1);
probs.addAll(s.probs);
probs.add(p);
- score = s.score+Math.log(p);
+ score = s.score + Math.log(p);
}
public Sequence(List<String> outcomes) {
@@ -104,13 +104,13 @@ public class Sequence implements Comparable<Sequence> {
* @param ps a pre-allocated array to use to hold the values of the probabilities of the outcomes for this sequence.
*/
public void getProbs(double[] ps) {
- for (int pi=0,pl=probs.size();pi<pl;pi++) {
+ for (int pi = 0, pl = probs.size(); pi < pl; pi++) {
ps[pi] = probs.get(pi);
}
}
@Override
public String toString() {
- return score + " "+outcomes;
+ return score + " " + outcomes;
}
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/Span.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/Span.java b/opennlp-tools/src/main/java/opennlp/tools/util/Span.java
index 8864114..aae16d0 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/Span.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/Span.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package opennlp.tools.util;
/**
@@ -102,11 +103,12 @@ public class Span implements Comparable<Span> {
public Span(Span span, int offset) {
this(span.start + offset, span.end + offset, span.getType(), span.getProb());
}
-/**
- * Creates a new immutable span based on an existing span, where the existing span did not include the prob
- * @param span the span that has no prob or the prob is incorrect and a new Span must be generated
- * @param prob the probability of the span
- */
+
+ /**
+ * Creates a new immutable span based on an existing span, where the existing span did not include the prob
+ * @param span the span that has no prob or the prob is incorrect and a new Span must be generated
+ * @param prob the probability of the span
+ */
public Span(Span span, double prob) {
this(span.start, span.end, span.getType(), prob);
}
@@ -158,8 +160,7 @@ public class Span implements Comparable<Span> {
*
* @param s The span to compare with this span.
*
- * @return true is the specified span is contained by this span; false
- * otherwise.
+ * @return true is the specified span is contained by this span; false otherwise.
*/
public boolean contains(Span s) {
return start <= s.getStart() && s.getEnd() <= end;
@@ -184,7 +185,7 @@ public class Span implements Comparable<Span> {
* @param s The span to compare with this span.
*
* @return true if the specified span starts with this span and is contained
- * in this span; false otherwise
+ * in this span; false otherwise
*/
public boolean startsWith(Span s) {
return getStart() == s.getStart() && contains(s);
@@ -211,7 +212,7 @@ public class Span implements Comparable<Span> {
* @param s The span to compare with this span.
*
* @return true is the specified span overlaps this span and contains a
- * non-overlapping section; false otherwise.
+ * non-overlapping section; false otherwise.
*/
public boolean crosses(Span s) {
int sstart = s.getStart();
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/StringList.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/StringList.java b/opennlp-tools/src/main/java/opennlp/tools/util/StringList.java
index 000581b..c78a794 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/StringList.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/StringList.java
@@ -50,7 +50,7 @@ public class StringList implements Iterable<String> {
* Token Strings will be replaced by identical internal String object.
*
* @param tokens the string parts of the new {@link StringList}, an empty
- * tokens array or null is not permitted.
+ * tokens array or null is not permitted.
*/
public StringList(String... tokens) {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/StringUtil.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/StringUtil.java b/opennlp-tools/src/main/java/opennlp/tools/util/StringUtil.java
index a3fd49d..c12af70 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/StringUtil.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/StringUtil.java
@@ -38,7 +38,7 @@ public class StringUtil {
*/
public static boolean isWhitespace(char charCode) {
return Character.isWhitespace(charCode) ||
- Character.getType(charCode) == Character.SPACE_SEPARATOR;
+ Character.getType(charCode) == Character.SPACE_SEPARATOR;
}
/**
@@ -102,18 +102,18 @@ public class StringUtil {
}
/**
- * Returns <tt>true</tt> if {@link CharSequence#length()} is
- * <tt>0</tt> or <tt>null</tt>.
- *
- * @return <tt>true</tt> if {@link CharSequence#length()} is <tt>0</tt>, otherwise
- * <tt>false</tt>
- *
- * @since 1.5.1
- */
+ * Returns <tt>true</tt> if {@link CharSequence#length()} is
+ * <tt>0</tt> or <tt>null</tt>.
+ *
+ * @return <tt>true</tt> if {@link CharSequence#length()} is <tt>0</tt>, otherwise
+ * <tt>false</tt>
+ *
+ * @since 1.5.1
+ */
public static boolean isEmpty(CharSequence theString) {
- return theString.length() == 0;
+ return theString.length() == 0;
}
-
+
/**
* Get mininum of three values.
* @param a number a
@@ -122,17 +122,17 @@ public class StringUtil {
* @return the minimum
*/
private static int minimum(int a, int b, int c) {
- int minValue;
- minValue = a;
- if (b < minValue) {
- minValue = b;
- }
- if (c < minValue) {
- minValue = c;
- }
- return minValue;
+ int minValue;
+ minValue = a;
+ if (b < minValue) {
+ minValue = b;
+ }
+ if (c < minValue) {
+ minValue = c;
+ }
+ return minValue;
}
-
+
/**
* Computes the Levenshtein distance of two strings in a matrix.
* Based on pseudo-code provided here:
@@ -149,7 +149,7 @@ public class StringUtil {
int lemmaLength = lemma.length();
int cost;
int[][] distance = new int[wordLength + 1][lemmaLength + 1];
-
+
if (wordLength == 0) {
return distance;
}
@@ -179,71 +179,71 @@ public class StringUtil {
}
return distance;
}
-
+
/**
* Computes the Shortest Edit Script (SES) to convert a word into its lemma.
* This is based on Chrupala's PhD thesis (2008).
- * @param wordForm the token
- * @param lemma the target lemma
- * @param distance the levenshtein distance
- * @param permutations the number of permutations
- */
-public static void computeShortestEditScript(String wordForm, String lemma, int[][] distance, StringBuffer permutations) {
-
+ * @param wordForm the token
+ * @param lemma the target lemma
+ * @param distance the levenshtein distance
+ * @param permutations the number of permutations
+ */
+ public static void computeShortestEditScript(String wordForm, String lemma, int[][] distance, StringBuffer permutations) {
+
int n = distance.length;
int m = distance[0].length;
-
+
int wordFormLength = n - 1;
int lemmaLength = m - 1;
- while(true) {
-
- if (distance[wordFormLength][lemmaLength] == 0) {
- break;
- }
- if ((lemmaLength > 0 && wordFormLength > 0) && (distance[wordFormLength - 1][lemmaLength - 1] < distance[wordFormLength][lemmaLength])) {
- permutations.append('R').append(Integer.toString(wordFormLength - 1)).append(wordForm.charAt(wordFormLength - 1)).append(lemma.charAt(lemmaLength - 1));
- lemmaLength--;
- wordFormLength--;
- continue;
- }
- if (lemmaLength > 0 && (distance[wordFormLength][lemmaLength - 1] < distance[wordFormLength][lemmaLength])) {
- permutations.append('I').append(Integer.toString(wordFormLength)).append(lemma.charAt(lemmaLength - 1));
- lemmaLength--;
- continue;
- }
- if (wordFormLength > 0 && (distance[wordFormLength - 1][lemmaLength] < distance[wordFormLength][lemmaLength])) {
- permutations.append('D').append(Integer.toString(wordFormLength - 1)).append(wordForm.charAt(wordFormLength - 1));
- wordFormLength--;
- continue;
- }
- if ((wordFormLength > 0 && lemmaLength > 0) && (distance[wordFormLength - 1][lemmaLength - 1] == distance[wordFormLength][lemmaLength])) {
- wordFormLength--; lemmaLength--;
- continue ;
- }
- if (wordFormLength > 0 && (distance[wordFormLength - 1][lemmaLength] == distance[wordFormLength][lemmaLength])) {
- wordFormLength--;
- continue;
- }
- if (lemmaLength > 0 && (distance[wordFormLength][lemmaLength - 1] == distance[wordFormLength][lemmaLength])) {
- lemmaLength--;
- continue;
- }
+ while (true) {
+
+ if (distance[wordFormLength][lemmaLength] == 0) {
+ break;
+ }
+ if ((lemmaLength > 0 && wordFormLength > 0) && (distance[wordFormLength - 1][lemmaLength - 1] < distance[wordFormLength][lemmaLength])) {
+ permutations.append('R').append(Integer.toString(wordFormLength - 1)).append(wordForm.charAt(wordFormLength - 1)).append(lemma.charAt(lemmaLength - 1));
+ lemmaLength--;
+ wordFormLength--;
+ continue;
+ }
+ if (lemmaLength > 0 && (distance[wordFormLength][lemmaLength - 1] < distance[wordFormLength][lemmaLength])) {
+ permutations.append('I').append(Integer.toString(wordFormLength)).append(lemma.charAt(lemmaLength - 1));
+ lemmaLength--;
+ continue;
+ }
+ if (wordFormLength > 0 && (distance[wordFormLength - 1][lemmaLength] < distance[wordFormLength][lemmaLength])) {
+ permutations.append('D').append(Integer.toString(wordFormLength - 1)).append(wordForm.charAt(wordFormLength - 1));
+ wordFormLength--;
+ continue;
+ }
+ if ((wordFormLength > 0 && lemmaLength > 0) && (distance[wordFormLength - 1][lemmaLength - 1] == distance[wordFormLength][lemmaLength])) {
+ wordFormLength--; lemmaLength--;
+ continue ;
+ }
+ if (wordFormLength > 0 && (distance[wordFormLength - 1][lemmaLength] == distance[wordFormLength][lemmaLength])) {
+ wordFormLength--;
+ continue;
+ }
+ if (lemmaLength > 0 && (distance[wordFormLength][lemmaLength - 1] == distance[wordFormLength][lemmaLength])) {
+ lemmaLength--;
+ continue;
+ }
}
-}
+ }
-/**
- * Read predicted SES by the lemmatizer model and apply the
- * permutations to obtain the lemma from the wordForm.
- * @param wordForm the wordForm
- * @param permutations the permutations predicted by the lemmatizer model
- * @return the lemma
- */
-public static String decodeShortestEditScript(String wordForm, String permutations) {
-
- StringBuffer lemma = new StringBuffer(wordForm).reverse();
-
- int permIndex = 0;
- while(true) {
+ /**
+ * Read predicted SES by the lemmatizer model and apply the
+ * permutations to obtain the lemma from the wordForm.
+ * @param wordForm the wordForm
+ * @param permutations the permutations predicted by the lemmatizer model
+ * @return the lemma
+ */
+ public static String decodeShortestEditScript(String wordForm, String permutations) {
+
+ StringBuffer lemma = new StringBuffer(wordForm).reverse();
+
+ int permIndex = 0;
+ while (true) {
if (permutations.length() <= permIndex) {
break;
}
@@ -253,75 +253,75 @@ public static String decodeShortestEditScript(String wordForm, String permutatio
//go to the next permutation letter
permIndex++;
if (nextOperation == 'R') {
- String charAtPerm = Character.toString(permutations.charAt(permIndex));
- int charIndex = Integer.parseInt(charAtPerm);
- // go to the next character in the permutation buffer
- // which is the replacement character
- permIndex++;
- char replace = permutations.charAt(permIndex);
- //go to the next char in the permutation buffer
- // which is the candidate character
- permIndex++;
- char with = permutations.charAt(permIndex);
-
- if (lemma.length() <= charIndex) {
- return wordForm;
- }
- if (lemma.charAt(charIndex) == replace) {
- lemma.setCharAt(charIndex, with);
- }
- //System.err.println("-> ROP: " + lemma.toString());
- //go to next permutation
- permIndex++;
-
+ String charAtPerm = Character.toString(permutations.charAt(permIndex));
+ int charIndex = Integer.parseInt(charAtPerm);
+ // go to the next character in the permutation buffer
+ // which is the replacement character
+ permIndex++;
+ char replace = permutations.charAt(permIndex);
+ //go to the next char in the permutation buffer
+ // which is the candidate character
+ permIndex++;
+ char with = permutations.charAt(permIndex);
+
+ if (lemma.length() <= charIndex) {
+ return wordForm;
+ }
+ if (lemma.charAt(charIndex) == replace) {
+ lemma.setCharAt(charIndex, with);
+ }
+ //System.err.println("-> ROP: " + lemma.toString());
+ //go to next permutation
+ permIndex++;
+
} else if (nextOperation == 'I') {
- String charAtPerm = Character.toString(permutations.charAt(permIndex));
- int charIndex = Integer.parseInt(charAtPerm);
- permIndex++;
- //character to be inserted
- char in = permutations.charAt(permIndex);
-
- if (lemma.length() < charIndex) {
- return wordForm;
- }
- lemma.insert(charIndex, in);
- //System.err.println("-> IOP " + lemma.toString());
- //go to next permutation
- permIndex++;
+ String charAtPerm = Character.toString(permutations.charAt(permIndex));
+ int charIndex = Integer.parseInt(charAtPerm);
+ permIndex++;
+ //character to be inserted
+ char in = permutations.charAt(permIndex);
+
+ if (lemma.length() < charIndex) {
+ return wordForm;
+ }
+ lemma.insert(charIndex, in);
+ //System.err.println("-> IOP " + lemma.toString());
+ //go to next permutation
+ permIndex++;
} else if (nextOperation == 'D') {
- String charAtPerm = Character.toString(permutations.charAt(permIndex));
- int charIndex = Integer.parseInt(charAtPerm);
- if (lemma.length() <= charIndex) {
- return wordForm;
- }
- lemma.deleteCharAt(charIndex);
- permIndex++;
- // go to next permutation
- permIndex++;
+ String charAtPerm = Character.toString(permutations.charAt(permIndex));
+ int charIndex = Integer.parseInt(charAtPerm);
+ if (lemma.length() <= charIndex) {
+ return wordForm;
+ }
+ lemma.deleteCharAt(charIndex);
+ permIndex++;
+ // go to next permutation
+ permIndex++;
}
+ }
+ return lemma.reverse().toString();
}
- return lemma.reverse().toString();
-}
-/**
- * Get the SES required to go from a word to a lemma.
- * @param wordForm the word
- * @param lemma the lemma
- * @return the shortest edit script
- */
-public static String getShortestEditScript(String wordForm, String lemma) {
- String reversedWF = new StringBuffer(wordForm.toLowerCase()).reverse().toString();
- String reversedLemma = new StringBuffer(lemma.toLowerCase()).reverse().toString();
- StringBuffer permutations = new StringBuffer();
- String ses;
- if (!reversedWF.equals(reversedLemma)) {
- int[][]levenDistance = StringUtil.levenshteinDistance(reversedWF, reversedLemma);
- StringUtil.computeShortestEditScript(reversedWF, reversedLemma, levenDistance, permutations);
- ses = permutations.toString();
- } else {
- ses = "O";
+ /**
+ * Get the SES required to go from a word to a lemma.
+ * @param wordForm the word
+ * @param lemma the lemma
+ * @return the shortest edit script
+ */
+ public static String getShortestEditScript(String wordForm, String lemma) {
+ String reversedWF = new StringBuffer(wordForm.toLowerCase()).reverse().toString();
+ String reversedLemma = new StringBuffer(lemma.toLowerCase()).reverse().toString();
+ StringBuffer permutations = new StringBuffer();
+ String ses;
+ if (!reversedWF.equals(reversedLemma)) {
+ int[][]levenDistance = StringUtil.levenshteinDistance(reversedWF, reversedLemma);
+ StringUtil.computeShortestEditScript(reversedWF, reversedLemma, levenDistance, permutations);
+ ses = permutations.toString();
+ } else {
+ ses = "O";
+ }
+ return ses;
}
- return ses;
-}
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/TrainingParameters.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/TrainingParameters.java b/opennlp-tools/src/main/java/opennlp/tools/util/TrainingParameters.java
index 3677fc4..9e31bec 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/TrainingParameters.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/TrainingParameters.java
@@ -36,7 +36,7 @@ public class TrainingParameters {
public static final String ITERATIONS_PARAM = "Iterations";
public static final String CUTOFF_PARAM = "Cutoff";
public static final String THREADS_PARAM = "Threads";
-
+
private Map<String, String> parameters = new HashMap<>();
public TrainingParameters() {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/Version.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/Version.java b/opennlp-tools/src/main/java/opennlp/tools/util/Version.java
index 7683b30..6749a57 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/Version.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/Version.java
@@ -150,7 +150,7 @@ public class Version {
* @return the version represented by the string value
*
* @throws NumberFormatException if the string does
- * not contain a valid version
+ * not contain a valid version
*/
public static Version parse(String version) {
@@ -159,7 +159,7 @@ public class Version {
int indexSecondDot = version.indexOf('.', indexFirstDot + 1);
if (indexFirstDot == -1 || indexSecondDot == -1) {
- throw new NumberFormatException("Invalid version format '" + version + "', expected two dots!");
+ throw new NumberFormatException("Invalid version format '" + version + "', expected two dots!");
}
int indexFirstDash = version.indexOf('-');
@@ -191,7 +191,7 @@ public class Version {
// Try to read the version from the version file if it is available,
// otherwise set the version to the development version
- try (InputStream versionIn =
+ try (InputStream versionIn =
Version.class.getResourceAsStream("opennlp.version")) {
if (versionIn != null) {
manifest.load(versionIn);
@@ -200,8 +200,7 @@ public class Version {
// ignore error
}
- String versionString =
- manifest.getProperty("OpenNLP-Version", DEV_VERSION_STRING);
+ String versionString = manifest.getProperty("OpenNLP-Version", DEV_VERSION_STRING);
if (versionString.equals("${pom.version}"))
versionString = DEV_VERSION_STRING;
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/eval/Evaluator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/eval/Evaluator.java b/opennlp-tools/src/main/java/opennlp/tools/util/eval/Evaluator.java
index aa77b98..1075d4c 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/eval/Evaluator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/eval/Evaluator.java
@@ -78,8 +78,8 @@ public abstract class Evaluator<T> {
*/
public void evaluateSample(T sample) {
T predicted = processSample(sample);
- if(!listeners.isEmpty()) {
- if(sample.equals(predicted)) {
+ if (!listeners.isEmpty()) {
+ if (sample.equals(predicted)) {
for (EvaluationMonitor<T> listener : listeners) {
listener.correctlyClassified(sample, predicted);
}
@@ -97,7 +97,7 @@ public abstract class Evaluator<T> {
* {@link #evaluateSample(Object)} method.
*
* @param samples the stream of reference which
- * should be evaluated.
+ * should be evaluated.
*
* @throws IOException IOException
*/
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/eval/Mean.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/eval/Mean.java b/opennlp-tools/src/main/java/opennlp/tools/util/eval/Mean.java
index 95e89d0..9feeb08 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/eval/Mean.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/eval/Mean.java
@@ -37,7 +37,7 @@ public class Mean {
* Adds a value to the arithmetic mean.
*
* @param value the value which should be added
- * to the arithmetic mean.
+ * to the arithmetic mean.
*/
public void add(double value) {
add(value, 1);
@@ -47,10 +47,10 @@ public class Mean {
* Adds a value count times to the arithmetic mean.
*
* @param value the value which should be added
- * to the arithmetic mean.
+ * to the arithmetic mean.
*
* @param count number of times the value should be added to
- * arithmetic mean.
+ * arithmetic mean.
*/
public void add(double value, long count) {
sum += value * count;
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/ext/ExtensionLoader.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/ext/ExtensionLoader.java b/opennlp-tools/src/main/java/opennlp/tools/util/ext/ExtensionLoader.java
index b33d577..8839321 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/ext/ExtensionLoader.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/ext/ExtensionLoader.java
@@ -78,7 +78,7 @@ public class ExtensionLoader {
} catch (NoSuchFieldException | SecurityException e1) {
throw new ExtensionNotLoadedException(e1);
}
- if(instanceField != null) {
+ if (instanceField != null) {
try {
return (T) instanceField.get(null);
} catch (IllegalArgumentException | IllegalAccessException e1) {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/AdaptiveFeatureGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/AdaptiveFeatureGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/AdaptiveFeatureGenerator.java
index 85d9df9..494e7fd 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/AdaptiveFeatureGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/AdaptiveFeatureGenerator.java
@@ -51,11 +51,11 @@ public interface AdaptiveFeatureGenerator {
* @param tokens The tokens of the sentence or other text unit which has been processed.
* @param outcomes The outcomes associated with the specified tokens.
*/
- default void updateAdaptiveData(String[] tokens, String[] outcomes) {};
+ default void updateAdaptiveData(String[] tokens, String[] outcomes) {};
/**
* Informs the feature generator that the context of the adaptive data (typically a document)
* is no longer valid.
*/
- default void clearAdaptiveData() {};
+ default void clearAdaptiveData() {};
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/AdditionalContextFeatureGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/AdditionalContextFeatureGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/AdditionalContextFeatureGenerator.java
index 3606bfc..482eb67 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/AdditionalContextFeatureGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/AdditionalContextFeatureGenerator.java
@@ -28,9 +28,6 @@ public class AdditionalContextFeatureGenerator implements AdaptiveFeatureGenerat
private String[][] additionalContext;
-// public AdditionalContextFeatureGenerator() {
-// }
-
public void createFeatures(List<String> features, String[] tokens, int index, String[] preds) {
if (additionalContext != null && additionalContext.length != 0) {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BigramNameFeatureGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BigramNameFeatureGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BigramNameFeatureGenerator.java
index 779628b..0028ec1 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BigramNameFeatureGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BigramNameFeatureGenerator.java
@@ -25,14 +25,14 @@ public class BigramNameFeatureGenerator implements AdaptiveFeatureGenerator {
String wc = FeatureGeneratorUtil.tokenFeature(tokens[index]);
//bi-gram features
if (index > 0) {
- features.add("pw,w="+tokens[index-1]+","+tokens[index]);
- String pwc = FeatureGeneratorUtil.tokenFeature(tokens[index-1]);
- features.add("pwc,wc="+pwc+","+wc);
+ features.add("pw,w=" + tokens[index - 1] + "," + tokens[index]);
+ String pwc = FeatureGeneratorUtil.tokenFeature(tokens[index - 1]);
+ features.add("pwc,wc=" + pwc + "," + wc);
}
- if (index+1 < tokens.length) {
- features.add("w,nw="+tokens[index]+","+tokens[index+1]);
- String nwc = FeatureGeneratorUtil.tokenFeature(tokens[index+1]);
- features.add("wc,nc="+wc+","+nwc);
+ if (index + 1 < tokens.length) {
+ features.add("w,nw=" + tokens[index] + "," + tokens[index + 1]);
+ String nwc = FeatureGeneratorUtil.tokenFeature(tokens[index + 1]);
+ features.add("wc,nc=" + wc + "," + nwc);
}
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownBigramFeatureGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownBigramFeatureGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownBigramFeatureGenerator.java
index a932e74..8be8a77 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownBigramFeatureGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownBigramFeatureGenerator.java
@@ -26,7 +26,7 @@ public class BrownBigramFeatureGenerator implements AdaptiveFeatureGenerator {
private BrownCluster brownLexicon;
- public BrownBigramFeatureGenerator(BrownCluster dict){
+ public BrownBigramFeatureGenerator(BrownCluster dict) {
this.brownLexicon = dict;
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownCluster.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownCluster.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownCluster.java
index 6a109b0..ad5e64f 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownCluster.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownCluster.java
@@ -76,8 +76,8 @@ public class BrownCluster implements SerializableArtifact {
String[] lineArray = tabPattern.split(line);
if (lineArray.length == 3) {
int freq = Integer.parseInt(lineArray[2]);
- if (freq > 5 ) {
- tokenToClusterMap.put(lineArray[1], lineArray[0]);
+ if (freq > 5 ) {
+ tokenToClusterMap.put(lineArray[1], lineArray[0]);
}
}
else if (lineArray.length == 2) {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownTokenClassFeatureGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownTokenClassFeatureGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownTokenClassFeatureGenerator.java
index db3d774..b1aaf2e 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownTokenClassFeatureGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownTokenClassFeatureGenerator.java
@@ -26,7 +26,7 @@ public class BrownTokenClassFeatureGenerator implements AdaptiveFeatureGenerator
private BrownCluster brownLexicon;
- public BrownTokenClassFeatureGenerator(BrownCluster dict){
+ public BrownTokenClassFeatureGenerator(BrownCluster dict) {
this.brownLexicon = dict;
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownTokenFeatureGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownTokenFeatureGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownTokenFeatureGenerator.java
index f41203f..d29e77a 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownTokenFeatureGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownTokenFeatureGenerator.java
@@ -26,7 +26,7 @@ public class BrownTokenFeatureGenerator implements AdaptiveFeatureGenerator {
private BrownCluster brownLexicon;
- public BrownTokenFeatureGenerator(BrownCluster dict){
+ public BrownTokenFeatureGenerator(BrownCluster dict) {
this.brownLexicon = dict;
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/CachedFeatureGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/CachedFeatureGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/CachedFeatureGenerator.java
index afb0a2c..baedfc9 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/CachedFeatureGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/CachedFeatureGenerator.java
@@ -100,7 +100,8 @@ public class CachedFeatureGenerator implements AdaptiveFeatureGenerator {
@Override
public String toString() {
- return super.toString()+": hits=" + numberOfCacheHits+" misses="+ numberOfCacheMisses+" hit%"+ (numberOfCacheHits > 0 ?
- (double) numberOfCacheHits/(numberOfCacheMisses+numberOfCacheHits) : 0);
+ return super.toString() + ": hits=" + numberOfCacheHits
+ + " misses=" + numberOfCacheMisses + " hit%" + (numberOfCacheHits > 0 ?
+ (double) numberOfCacheHits / (numberOfCacheMisses + numberOfCacheHits) : 0);
}
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/DictionaryFeatureGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/DictionaryFeatureGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/DictionaryFeatureGenerator.java
index 68037ed..ff61d1e 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/DictionaryFeatureGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/DictionaryFeatureGenerator.java
@@ -38,6 +38,7 @@ public class DictionaryFeatureGenerator implements AdaptiveFeatureGenerator {
public DictionaryFeatureGenerator(Dictionary dict) {
this("",dict);
}
+
public DictionaryFeatureGenerator(String prefix, Dictionary dict) {
setDictionary(prefix,dict);
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/GeneratorFactory.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/GeneratorFactory.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/GeneratorFactory.java
index f6cf702..9065fb6 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/GeneratorFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/GeneratorFactory.java
@@ -132,7 +132,7 @@ public class GeneratorFactory {
}
return new AggregatedFeatureGenerator(aggregatedGenerators.toArray(
- new AdaptiveFeatureGenerator[aggregatedGenerators.size()]));
+ new AdaptiveFeatureGenerator[aggregatedGenerators.size()]));
}
static void register(Map<String, XmlFeatureGeneratorFactory> factoryMap) {
@@ -429,17 +429,17 @@ public class GeneratorFactory {
FeatureGeneratorResourceProvider resourceManager) {
String attribute = generatorElement.getAttribute("wordAndClass");
-
+
// Default to true.
boolean generateWordAndClassFeature = true;
-
- if(attribute != "") {
- // Anything other than "true" sets it to false.
- if(!"true".equalsIgnoreCase(attribute)) {
- generateWordAndClassFeature = false;
- }
+
+ if (attribute != "") {
+ // Anything other than "true" sets it to false.
+ if (!"true".equalsIgnoreCase(attribute)) {
+ generateWordAndClassFeature = false;
+ }
}
-
+
return new TokenClassFeatureGenerator(generateWordAndClassFeature);
}
@@ -512,7 +512,7 @@ public class GeneratorFactory {
if (nestedGeneratorElement == null) {
throw new InvalidFormatException("window feature generator must contain" +
- " an aggregator element");
+ " an aggregator element");
}
AdaptiveFeatureGenerator nestedGenerator = GeneratorFactory.createGenerator(nestedGeneratorElement, resourceManager);
@@ -703,10 +703,10 @@ public class GeneratorFactory {
* components.
*
* @param xmlDescriptorIn the {@link InputStream} from which the descriptor
- * is read, the stream remains open and must be closed by the caller.
+ * is read, the stream remains open and must be closed by the caller.
*
* @param resourceManager the resource manager which is used to resolve resources
- * referenced by a key in the descriptor
+ * referenced by a key in the descriptor
*
* @return created feature generators
*
@@ -724,8 +724,7 @@ public class GeneratorFactory {
}
public static Map<String, ArtifactSerializer<?>> extractCustomArtifactSerializerMappings(
- InputStream xmlDescriptorIn)
- throws IOException, InvalidFormatException {
+ InputStream xmlDescriptorIn) throws IOException, InvalidFormatException {
Map<String, ArtifactSerializer<?>> mapping = new HashMap<>();
@@ -767,8 +766,7 @@ public class GeneratorFactory {
* @throws IOException if inputstream cannot be open
* @throws InvalidFormatException if xml is not well-formed
*/
- public static List<Element> getDescriptorElements(
- InputStream xmlDescriptorIn)
+ public static List<Element> getDescriptorElements(InputStream xmlDescriptorIn)
throws IOException, InvalidFormatException {
List<Element> elements = new ArrayList<Element>();
@@ -786,8 +784,8 @@ public class GeneratorFactory {
if (allElements.item(i) instanceof Element) {
Element customElement = (Element) allElements.item(i);
elements.add(customElement);
- }
}
+ }
return elements;
}
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/InSpanGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/InSpanGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/InSpanGenerator.java
index bcffc7e..b557a4c 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/InSpanGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/InSpanGenerator.java
@@ -41,24 +41,24 @@ public class InSpanGenerator implements AdaptiveFeatureGenerator {
* Initializes the current instance.
*
* @param prefix the prefix is used to distinguish the generated features
- * from features generated by other instances of {@link InSpanGenerator}s.
+ * from features generated by other instances of {@link InSpanGenerator}s.
* @param finder the {@link TokenNameFinder} used to detect the names.
*/
public InSpanGenerator(String prefix, TokenNameFinder finder) {
if (prefix == null)
- throw new IllegalArgumentException("prefix must not be null!");
+ throw new IllegalArgumentException("prefix must not be null!");
this.prefix = prefix;
if (finder == null)
- throw new IllegalArgumentException("finder must not be null!");
+ throw new IllegalArgumentException("finder must not be null!");
this.finder = finder;
}
public void createFeatures(List<String> features, String[] tokens, int index,
- String[] preds) {
+ String[] preds) {
// cache results for sentence
if (currentSentence != tokens) {
currentSentence = tokens;
http://git-wip-us.apache.org/repos/asf/opennlp/blob/1bccbabb/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/StringPattern.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/StringPattern.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/StringPattern.java
index 8d93c68..571e26f 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/StringPattern.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/StringPattern.java
@@ -160,24 +160,24 @@ public class StringPattern {
}
switch (ch) {
- case ',':
- pattern |= CONTAINS_COMMA;
- break;
+ case ',':
+ pattern |= CONTAINS_COMMA;
+ break;
- case '.':
- pattern |= CONTAINS_PERIOD;
- break;
+ case '.':
+ pattern |= CONTAINS_PERIOD;
+ break;
- case '/':
- pattern |= CONTAINS_SLASH;
- break;
+ case '/':
+ pattern |= CONTAINS_SLASH;
+ break;
- case '-':
- pattern |= CONTAINS_HYPHEN;
- break;
+ case '-':
+ pattern |= CONTAINS_HYPHEN;
+ break;
- default:
- break;
+ default:
+ break;
}
}
}