Revision: 6222
          
http://languagetool.svn.sourceforge.net/languagetool/?rev=6222&view=rev
Author:   archeus
Date:     2012-01-11 13:40:56 +0000 (Wed, 11 Jan 2012)
Log Message:
-----------
- refactoring: use case conversion after calling Synthesizer instead of before
- temorary fix for case preservation (commented out)

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

Modified: 
trunk/JLanguageTool/src/java/org/languagetool/rules/patterns/Match.java
===================================================================
--- trunk/JLanguageTool/src/java/org/languagetool/rules/patterns/Match.java     
2012-01-11 09:30:28 UTC (rev 6221)
+++ trunk/JLanguageTool/src/java/org/languagetool/rules/patterns/Match.java     
2012-01-11 13:40:56 UTC (rev 6222)
@@ -250,7 +250,6 @@
         formattedString[0] = pRegexMatch.matcher(formattedString[0])
             .replaceAll(regexReplace);
       }
-      formattedString[0] = convertCase(formattedString[0]);
       if (posTag != null) {
         if (synthesizer == null) {
           formattedString[0] = formattedToken.getToken();
@@ -306,6 +305,11 @@
         }
       }
     }    
+    final String original = formattedToken != null ?  
formattedToken.getToken() : "";
+    for (int i = 0; i < formattedString.length; i++) {
+       formattedString[i] = convertCase(formattedString[i], original);
+    }
+    // TODO should case conversion happen before or after including skipped 
tokens?
     if (includeSkipped != IncludeRange.NONE 
         && skippedTokens != null && !"".equals(skippedTokens)) {      
       final String[] helper = new String[formattedString.length];
@@ -416,15 +420,28 @@
    * Converts case of the string token according to match element attributes.
    * 
    * @param s Token to be converted.
+   * @param sample the sample string used to determine how the original string 
looks like (used on case preservation) 
    * @return Converted string.
    */
-  private String convertCase(final String s) {
+  private String convertCase(final String s, String sample) {
     if (StringTools.isEmpty(s)) {
       return s;
     }
     String token = s;
     switch (caseConversionType) {
-    case NONE:
+    case NONE: // preserve case
+      /* 
+        
+        temporary commented out until we agree if this is correct
+        
+      if (StringTools.startsWithUppercase(sample)) {
+        if (StringTools.isAllUppercase(formattedToken.getToken())) {
+          token =  token.toUpperCase();
+        } else {
+          token = StringTools.uppercaseFirstChar(token);
+        }
+      }
+      */ 
       break;
     case STARTLOWER:
       token = token.substring(0, 1).toLowerCase() + token.substring(1);
@@ -472,7 +489,7 @@
        /* only replace if it is something to replace*/
         token = pRegexMatch.matcher(token).replaceAll(regexReplace);
       }
-      token = convertCase(token);
+      token = convertCase(token, token);
       if (posTag != null) {
         final int numRead = formattedToken.getReadingsLength();
         if (postagRegexp) {

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