Revision: 6273
          
http://languagetool.svn.sourceforge.net/languagetool/?rev=6273&view=rev
Author:   archeus
Date:     2012-01-17 11:22:04 +0000 (Tue, 17 Jan 2012)
Log Message:
-----------
MatchTest: bugfix + adding some tests for using Match.CaseConversion with 
static lemma

Modified Paths:
--------------
    trunk/JLanguageTool/src/java/org/languagetool/rules/patterns/Match.java
    trunk/JLanguageTool/src/test/org/languagetool/rules/patterns/MatchTest.java

Modified: 
trunk/JLanguageTool/src/java/org/languagetool/rules/patterns/Match.java
===================================================================
--- trunk/JLanguageTool/src/java/org/languagetool/rules/patterns/Match.java     
2012-01-17 02:21:15 UTC (rev 6272)
+++ trunk/JLanguageTool/src/java/org/languagetool/rules/patterns/Match.java     
2012-01-17 11:22:04 UTC (rev 6273)
@@ -89,7 +89,7 @@
 
   /**
    * True if this match element formats a statically defined lemma which is
-   * enclosed by the element, e.g., <tt>&lt;match...&gt;word&lt;/word&gt;</tt>.
+   * enclosed by the element, e.g., 
<tt>&lt;match...&gt;word&lt;/match&gt;</tt>.
    */
   private boolean staticLemma;
 
@@ -305,7 +305,12 @@
         }
       }
     }    
-    final String original = formattedToken != null ?  
formattedToken.getToken() : "";
+    final String original;
+    if (staticLemma) {
+       original = matchedToken != null ? matchedToken.getToken() : "";
+    } else {
+       original = formattedToken != null ?  formattedToken.getToken() : "";
+    }
     for (int i = 0; i < formattedString.length; i++) {
        formattedString[i] = convertCase(formattedString[i], original);
     }
@@ -433,7 +438,7 @@
        break;
     case PRESERVE:
       if (StringTools.startsWithUppercase(sample)) {
-        if (StringTools.isAllUppercase(formattedToken.getToken())) {
+        if (StringTools.isAllUppercase(sample)) {
           token =  token.toUpperCase();
         } else {
           token = StringTools.uppercaseFirstChar(token);

Modified: 
trunk/JLanguageTool/src/test/org/languagetool/rules/patterns/MatchTest.java
===================================================================
--- trunk/JLanguageTool/src/test/org/languagetool/rules/patterns/MatchTest.java 
2012-01-17 02:21:15 UTC (rev 6272)
+++ trunk/JLanguageTool/src/test/org/languagetool/rules/patterns/MatchTest.java 
2012-01-17 11:22:04 UTC (rev 6273)
@@ -137,6 +137,31 @@
                assertEquals("[Inflectedform121, Inflectedform122]", 
Arrays.toString(match.toFinalString()));
        }
        
+       public void testStaticLemmaPreserveStartLower() throws Exception {
+               Match match = getMatch("POS2", "POS1", 
Match.CaseConversion.PRESERVE);
+               match.setLemmaString("lemma2");
+               match.setToken(getAnalyzedTokenReadings("inflectedform121", 
"POS2", "Lemma1"));
+               assertEquals("[inflectedform2]", 
Arrays.toString(match.toFinalString()));
+       }
+       public void testStaticLemmaPreserveStartUpper() throws Exception {
+               Match match = getMatch("POS2", "POS1", 
Match.CaseConversion.PRESERVE);
+               match.setLemmaString("lemma2");
+               match.setToken(getAnalyzedTokenReadings("InflectedForm121", 
"POS2", "Lemma1"));
+               assertEquals("[Inflectedform2]", 
Arrays.toString(match.toFinalString()));
+       }
+       public void testStaticLemmaPreserveAllUpper() throws Exception {
+               Match match = getMatch("POS2", "POS1", 
Match.CaseConversion.PRESERVE);
+               match.setLemmaString("lemma2");
+               match.setToken(getAnalyzedTokenReadings("INFLECTEDFORM121", 
"POS2", "Lemma1"));
+               assertEquals("[INFLECTEDFORM2]", 
Arrays.toString(match.toFinalString()));
+       }
+       public void testStaticLemmaPreserveMixed() throws Exception {
+               Match match = getMatch("POS2", "POS1", 
Match.CaseConversion.PRESERVE);
+               match.setLemmaString("lemma2");
+               match.setToken(getAnalyzedTokenReadings("infleCtedForm121", 
"POS2", "Lemma1"));
+               assertEquals("[inflectedform2]", 
Arrays.toString(match.toFinalString()));
+       }
+       
        public void testPreserveStartLower() throws Exception {
                Match match = getMatch("POS1", "POS2", 
Match.CaseConversion.PRESERVE);
                match.setToken(getAnalyzedTokenReadings("inflectedForm11", 
"POS1", "Lemma1"));
@@ -204,4 +229,6 @@
                // the first two tokens come together, it a known issue. 
        }
        
+       // TODO ad tests for using Match.IncludeRange with {@link 
Match#staticLemma}
+       
 }

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


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Languagetool-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/languagetool-cvs

Reply via email to