opennlp-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark G <giaconiam...@gmail.com>
Subject Re: svn commit: r1564395 - in /opennlp/trunk/opennlp-tools/src: main/java/opennlp/tools/namefind/RegexNameFinder.java main/java/opennlp/tools/namefind/RegexNameFinderFactory.java test/java/opennlp/tools/namefind/RegexNameFinderTest.java
Date Thu, 06 Feb 2014 11:18:14 GMT
ok, sounds good


On Thu, Feb 6, 2014 at 5:16 AM, Jörn Kottmann <kottmann@gmail.com> wrote:

> Hi Mark,
>
> we should not remove the constructors, because that will break backward
> compatibility,
>
> This one: public RegexNameFinder(Pattern patterns[]) should be marked as
> deprecated,
> and the other one we should probably keep, because it makes it easy to
> just run it with one
> type.
>
> When you deprecate it, please add a comment to point the user to the other
> constructor, otherwise
> they don't know where to look.
>
> Jörn
>
>
> On 02/04/2014 06:33 PM, markg@apache.org wrote:
>
>> Author: markg
>> Date: Tue Feb  4 17:33:59 2014
>> New Revision: 1564395
>>
>> URL: http://svn.apache.org/r1564395
>> Log:
>> OPENNLP-643
>> Removed old constructors in lieu of Map<String,Pattern[]> constructor and
>> changed find methods appropriately. Updated unit tests for RegexNameFinder.
>>
>> Modified:
>>      opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/
>> namefind/RegexNameFinder.java
>>      opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/namefind/
>> RegexNameFinderFactory.java
>>      opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/
>> namefind/RegexNameFinderTest.java
>>
>> Modified: opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/
>> namefind/RegexNameFinder.java
>> URL: http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/
>> src/main/java/opennlp/tools/namefind/RegexNameFinder.java?
>> rev=1564395&r1=1564394&r2=1564395&view=diff
>> ============================================================
>> ==================
>> --- opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/namefind/RegexNameFinder.java
>> (original)
>> +++ opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/namefind/RegexNameFinder.java
>> Tue Feb  4 17:33:59 2014
>> @@ -30,8 +30,6 @@ import opennlp.tools.util.Span;
>>    */
>>   public final class RegexNameFinder implements TokenNameFinder {
>>   -  private Pattern mPatterns[];
>> -  private String sType;
>>     private Map<String, Pattern[]> regexMap;
>>       public RegexNameFinder(Map<String, Pattern[]> regexMap) {
>> @@ -42,24 +40,6 @@ public final class RegexNameFinder imple
>>       }
>>   -  public RegexNameFinder(Pattern patterns[], String type) {
>> -    if (patterns == null || patterns.length == 0) {
>> -      throw new IllegalArgumentException("patterns must not be null or
>> empty!");
>> -    }
>> -
>> -    mPatterns = patterns;
>> -    sType = type;
>> -  }
>> -
>> -  public RegexNameFinder(Pattern patterns[]) {
>> -    if (patterns == null || patterns.length == 0) {
>> -      throw new IllegalArgumentException("patterns must not be null or
>> empty!");
>> -    }
>> -
>> -    mPatterns = patterns;
>> -    sType = null;
>> -  }
>> -
>>     @Override
>>     public Span[] find(String tokens[]) {
>>       Map<Integer, Integer> sentencePosTokenMap = new HashMap<>();
>> @@ -83,7 +63,7 @@ public final class RegexNameFinder imple
>>         Collection<Span> annotations = new LinkedList<>();
>>   -    if (mPatterns == null && regexMap != null) {
>> +    if (regexMap != null) {
>>         for (Map.Entry<String, Pattern[]> entry : regexMap.entrySet()) {
>>           for (Pattern mPattern : entry.getValue()) {
>>             Matcher matcher = mPattern.matcher(sentenceString);
>> @@ -101,25 +81,10 @@ public final class RegexNameFinder imple
>>             }
>>           }
>>         }
>> -    } else {
>> -      for (Pattern mPattern : mPatterns) {
>> -        Matcher matcher = mPattern.matcher(sentenceString);
>> -
>> -        while (matcher.find()) {
>> -          Integer tokenStartIndex =
>> -                  sentencePosTokenMap.get(matcher.start());
>> -          Integer tokenEndIndex =
>> -                  sentencePosTokenMap.get(matcher.end());
>> -
>> -          if (tokenStartIndex != null && tokenEndIndex != null) {
>> -            Span annotation = new Span(tokenStartIndex, tokenEndIndex,
>> sType);
>> -            annotations.add(annotation);
>> -          }
>> -        }
>> -      }
>>       }
>>     +
>>       return annotations.toArray(
>>               new Span[annotations.size()]);
>>     }
>> @@ -138,7 +103,7 @@ public final class RegexNameFinder imple
>>       private Span[] getAnnotations(String text) {
>>       Collection<Span> annotations = new LinkedList<>();
>> -    if (mPatterns == null && regexMap != null) {
>> +    if (regexMap != null) {
>>         for (Map.Entry<String, Pattern[]> entry : regexMap.entrySet()) {
>>           for (Pattern mPattern : entry.getValue()) {
>>             Matcher matcher = mPattern.matcher(text);
>> @@ -152,20 +117,7 @@ public final class RegexNameFinder imple
>>             }
>>           }
>>         }
>> -    } else {
>> -      for (Pattern mPattern : mPatterns) {
>> -        Matcher matcher = mPattern.matcher(text);
>> -
>> -        while (matcher.find()) {
>> -          Integer tokenStartIndex = matcher.start();
>> -          Integer tokenEndIndex = matcher.end();
>> -          Span annotation = new Span(tokenStartIndex, tokenEndIndex,
>> sType);
>> -          annotations.add(annotation);
>> -
>> -        }
>> -      }
>>       }
>> -
>>       return annotations.toArray(
>>               new Span[annotations.size()]);
>>     }
>> @@ -175,19 +127,5 @@ public final class RegexNameFinder imple
>>       // nothing to clear
>>     }
>>   -  public Pattern[] getmPatterns() {
>> -    return mPatterns;
>> -  }
>> -
>> -  public void setmPatterns(Pattern[] mPatterns) {
>> -    this.mPatterns = mPatterns;
>> -  }
>> -
>> -  public String getsType() {
>> -    return sType;
>> -  }
>> -
>> -  public void setsType(String sType) {
>> -    this.sType = sType;
>> -  }
>> +
>>   }
>>
>> Modified: opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/
>> namefind/RegexNameFinderFactory.java
>> URL: http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/
>> src/main/java/opennlp/tools/namefind/RegexNameFinderFactory.java?
>> rev=1564395&r1=1564394&r2=1564395&view=diff
>> ============================================================
>> ==================
>> --- opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/namefind/RegexNameFinderFactory.java
>> (original)
>> +++ opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/namefind/RegexNameFinderFactory.java
>> Tue Feb  4 17:33:59 2014
>> @@ -22,8 +22,8 @@ import opennlp.tools.util.Span;
>>     /**
>>    *
>> - * Returns RegexNameFinders based on multiple methods: 1. A selection of
>> - * defaults 2. A configuration and a selection of defaults
>> + * Returns a RegexNameFinder based on A selection of
>> + * defaults or a configuration and a selection of defaults
>>    */
>>   public class RegexNameFinderFactory {
>>   @@ -50,7 +50,7 @@ public class RegexNameFinderFactory {
>>     }
>>       /**
>> -   * Allows for use of selecte
>> +   * Reterned a RegexNamefinder that will utilize specified default
>> regexes.
>>      *
>>      * @param defaults the OpenNLP default regexes
>>      * @return
>>
>> Modified: opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/
>> namefind/RegexNameFinderTest.java
>> URL: http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/
>> src/test/java/opennlp/tools/namefind/RegexNameFinderTest.
>> java?rev=1564395&r1=1564394&r2=1564395&view=diff
>> ============================================================
>> ==================
>> --- opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/
>> namefind/RegexNameFinderTest.java (original)
>> +++ opennlp/trunk/opennlp-tools/src/test/java/opennlp/tools/
>> namefind/RegexNameFinderTest.java Tue Feb  4 17:33:59 2014
>> @@ -14,15 +14,16 @@
>>    * See the License for the specific language governing permissions and
>>    * limitations under the License.
>>    */
>> -
>> -
>>   package opennlp.tools.namefind;
>>   +import java.util.HashMap;
>> +import java.util.Map;
>>   import static org.junit.Assert.assertTrue;
>>     import java.util.regex.Pattern;
>>     import opennlp.tools.util.Span;
>> +import org.junit.Before;
>>     import org.junit.Test;
>>   @@ -33,12 +34,19 @@ public class RegexNameFinderTest {
>>       @Test
>>     public void testFindSingleTokenPattern() {
>> -    Pattern testPattern = Pattern.compile("test");
>>   +    Pattern testPattern = Pattern.compile("test");
>>       String sentence[] = new String[]{"a", "test", "b", "c"};
>>   +
>> +    Pattern[] patterns = new Pattern[]{testPattern};
>> +    Map<String, Pattern[]> regexMap = new HashMap<>();
>> +    String type = "testtype";
>> +
>> +    regexMap.put(type, patterns);
>> +
>>       RegexNameFinder finder =
>> -      new RegexNameFinder(new Pattern[]{testPattern});
>> +            new RegexNameFinder(regexMap);
>>         Span[] result = finder.find(sentence);
>>   @@ -54,8 +62,14 @@ public class RegexNameFinderTest {
>>         String sentence[] = new String[]{"a", "80", "year", "b", "c"};
>>   +    Pattern[] patterns = new Pattern[]{testPattern};
>> +    Map<String, Pattern[]> regexMap = new HashMap<>();
>> +    String type = "match";
>> +
>> +    regexMap.put(type, patterns);
>> +
>>       RegexNameFinder finder =
>> -      new RegexNameFinder(new Pattern[]{testPattern}, "match");
>> +            new RegexNameFinder(regexMap);
>>         Span[] result = finder.find(sentence);
>>   @@ -71,9 +85,14 @@ public class RegexNameFinderTest {
>>       Pattern testPattern = Pattern.compile("[0-8] year"); // does match
>> "0 year"
>>         String sentence[] = new String[]{"a", "80", "year", "c"};
>> +Pattern[] patterns = new Pattern[]{testPattern};
>> +    Map<String, Pattern[]> regexMap = new HashMap<>();
>> +    String type = "testtype";
>> +
>> +    regexMap.put(type, patterns);
>>         RegexNameFinder finder =
>> -      new RegexNameFinder(new Pattern[]{testPattern});
>> +            new RegexNameFinder(regexMap);
>>         Span[] result = finder.find(sentence);
>>
>>
>>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message