You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by jk...@apache.org on 2011/12/21 05:45:18 UTC
svn commit: r1221611 -
/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/namefind/DictionaryNameFinder.java
Author: jkosin
Date: Wed Dec 21 04:45:17 2011
New Revision: 1221611
URL: http://svn.apache.org/viewvc?rev=1221611&view=rev
Log:
OPENNLP-415: Refactored the DictionaryNameFinder to not use the mMetaDictionary, I also simplified the arraycopy() to use original arrays in the copy... more fun. Thanks to Loic Descotte for finding the bug.
Modified:
incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/namefind/DictionaryNameFinder.java
Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/namefind/DictionaryNameFinder.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/namefind/DictionaryNameFinder.java?rev=1221611&r1=1221610&r2=1221611&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/namefind/DictionaryNameFinder.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/namefind/DictionaryNameFinder.java Wed Dec 21 04:45:17 2011
@@ -22,7 +22,6 @@ import java.util.LinkedList;
import java.util.List;
import opennlp.tools.dictionary.Dictionary;
-import opennlp.tools.dictionary.Index;
import opennlp.tools.util.Span;
import opennlp.tools.util.StringList;
@@ -34,8 +33,6 @@ public class DictionaryNameFinder implem
private Dictionary mDictionary;
- private Index mMetaDictionary;
-
/**
* Initializes the current instance.
*
@@ -43,35 +40,25 @@ public class DictionaryNameFinder implem
*/
public DictionaryNameFinder(Dictionary dictionary) {
mDictionary = dictionary;
- mMetaDictionary = new Index(dictionary.iterator());
}
public Span[] find(String[] tokenStrings) {
- List<Span> foundNames = new LinkedList<Span>();
+ List<Span> foundNames = new LinkedList<>();
for (int startToken = 0; startToken < tokenStrings.length; startToken++) {
Span foundName = null;
-
String tokens[] = new String[]{};
for (int endToken = startToken; endToken < tokenStrings.length; endToken++) {
- String token = tokenStrings[endToken];
-
- // TODO: improve performance here
- String newTokens[] = new String[tokens.length + 1];
- System.arraycopy(tokens, 0, newTokens, 0, tokens.length);
- newTokens[newTokens.length - 1] = token;
- tokens = newTokens;
+ tokens = new String[(endToken - startToken + 1)];
+ System.arraycopy(tokenStrings, startToken, tokens, 0, (endToken - startToken + 1));
- if (mMetaDictionary.contains(token)) {
+ StringList tokenList = new StringList(tokens);
- StringList tokenList = new StringList(tokens);
-
- if (mDictionary.contains(tokenList)) {
- foundName = new Span(startToken, endToken + 1);
- }
+ if (mDictionary.contains(tokenList)) {
+ foundName = new Span(startToken, endToken + 1);
}
else {
break;
@@ -85,7 +72,7 @@ public class DictionaryNameFinder implem
return foundNames.toArray(new Span[foundNames.size()]);
}
-
+
public void clearAdaptiveData() {
// nothing to clear
}