Revision: 6169
          
http://languagetool.svn.sourceforge.net/languagetool/?rev=6169&view=rev
Author:   archeus
Date:     2012-01-06 11:08:28 +0000 (Fri, 06 Jan 2012)
Log Message:
-----------
refactor BaseSynthesizer to allow extension . No functional change.

Modified Paths:
--------------
    trunk/JLanguageTool/src/java/org/languagetool/synthesis/BaseSynthesizer.java

Modified: 
trunk/JLanguageTool/src/java/org/languagetool/synthesis/BaseSynthesizer.java
===================================================================
--- 
trunk/JLanguageTool/src/java/org/languagetool/synthesis/BaseSynthesizer.java    
    2012-01-05 23:23:02 UTC (rev 6168)
+++ 
trunk/JLanguageTool/src/java/org/languagetool/synthesis/BaseSynthesizer.java    
    2012-01-06 11:08:28 UTC (rev 6169)
@@ -27,6 +27,19 @@
     this.resourceFileName = resourceFileName;  
     this.tagFileName = tagFileName;
   }
+
+  /**
+   * Lookup the inflected forms of a lemma defined by a part-of-speech tag.
+   * @param lemma the lemma to be inflected.
+   * @param posTag the desired part-of-speech tag.
+   * @param results the list to collect the inflected forms.
+   */
+  protected void lookup(String lemma, String posTag, List<String> results) {
+    final List<WordData> wordForms = synthesizer.lookup(lemma + "|" + posTag);
+    for (WordData wd : wordForms) {
+      results.add(wd.getStem().toString());
+    }
+  }
   
   /**
    * Get a form of a given AnalyzedToken, where the form is defined by a
@@ -41,11 +54,8 @@
   @Override
   public String[] synthesize(final AnalyzedToken token, final String posTag) 
throws IOException {
     initSynthesizer();
-    final List<WordData> wordData = synthesizer.lookup(token.getLemma() + "|" 
+ posTag);
     final List<String> wordForms = new ArrayList<String>();
-    for (WordData wd : wordData) {
-      wordForms.add(wd.getStem().toString());
-    }
+    lookup(token.getLemma(), posTag, wordForms);
     return wordForms.toArray(new String[wordForms.size()]);
   }
       
@@ -62,10 +72,7 @@
       for (final String tag : possibleTags) {
         final Matcher m = p.matcher(tag);
         if (m.matches()) {
-          final List<WordData> wordForms = synthesizer.lookup(token.getLemma() 
+ "|" + tag);
-          for (WordData wd : wordForms) {
-            results.add(wd.getStem().toString());
-          }
+          lookup(token.getLemma(), tag, results);
         }
       }
       return results.toArray(new String[results.size()]);
@@ -73,7 +80,7 @@
     return synthesize(token, posTag);
   }
 
-  private void initSynthesizer() throws IOException {
+  protected void initSynthesizer() throws IOException {
     if (synthesizer == null) {
       final URL url = this.getClass().getResource(resourceFileName);
       synthesizer = new DictionaryLookup(Dictionary.read(url));

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Languagetool-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/languagetool-cvs

Reply via email to