Revision: 7304
          
http://languagetool.svn.sourceforge.net/languagetool/?rev=7304&view=rev
Author:   milek_pl
Date:     2012-06-09 15:33:52 +0000 (Sat, 09 Jun 2012)
Log Message:
-----------
display what happened to tokens during disambiguation (now only in the case of 
error in disambugation rules themselves)

Modified Paths:
--------------
    trunk/JLanguageTool/src/java/org/languagetool/AnalyzedTokenReadings.java
    trunk/JLanguageTool/src/test/org/languagetool/AnalyzedTokenReadingsTest.java
    
trunk/JLanguageTool/src/test/org/languagetool/rules/patterns/UnifierTest.java
    
trunk/JLanguageTool/src/test/org/languagetool/tagging/disambiguation/rules/DisambiguationRuleTest.java

Modified: 
trunk/JLanguageTool/src/java/org/languagetool/AnalyzedTokenReadings.java
===================================================================
--- trunk/JLanguageTool/src/java/org/languagetool/AnalyzedTokenReadings.java    
2012-06-09 09:20:31 UTC (rev 7303)
+++ trunk/JLanguageTool/src/java/org/languagetool/AnalyzedTokenReadings.java    
2012-06-09 15:33:52 UTC (rev 7304)
@@ -53,6 +53,11 @@
    */
   private boolean isImmunized;
   
+  /**
+   * Used to hold the string representation of the disambiguator actions on a 
token.
+   */
+  private String historicalAnnotations = "";
+   
   
   public AnalyzedTokenReadings(final AnalyzedToken[] token, final int 
startPos) {
     anTokReadings = token.clone();
@@ -321,9 +326,14 @@
   @Override
   public String toString() {
     final StringBuilder sb = new StringBuilder();
+    sb.append(token);
+    sb.append("[");
     for (final AnalyzedToken element : anTokReadings) {
       sb.append(element);
+      sb.append(",");
     }
+    sb.delete(sb.length() - 1, sb.length());
+    sb.append("]");
     return sb.toString();
   }
 
@@ -377,5 +387,21 @@
       return false;
     return true;
   }
+
+/**
+ * Used to track disambiguator actions.
+ * @return the historicalAnnotations
+ */
+public String getHistoricalAnnotations() {
+    return historicalAnnotations;
+}
+
+/**
+ * Used to track disambiguator actions.
+ * @param historicalAnnotations the historicalAnnotations to set
+ */
+public void setHistoricalAnnotations(String historicalAnnotations) {
+    this.historicalAnnotations = this.historicalAnnotations + "\n" + 
historicalAnnotations;
+}
   
 }

Modified: 
trunk/JLanguageTool/src/test/org/languagetool/AnalyzedTokenReadingsTest.java
===================================================================
--- 
trunk/JLanguageTool/src/test/org/languagetool/AnalyzedTokenReadingsTest.java    
    2012-06-09 09:20:31 UTC (rev 7303)
+++ 
trunk/JLanguageTool/src/test/org/languagetool/AnalyzedTokenReadingsTest.java    
    2012-06-09 15:33:52 UTC (rev 7304)
@@ -69,6 +69,14 @@
     assertTrue(!testReadings.hasPosTag("POS"));
     
   }
+  
+  public void testToString() {
+      AnalyzedTokenReadings tokenReadings = new AnalyzedTokenReadings(new 
AnalyzedToken("word", "POS", "lemma"));
+      assertEquals(tokenReadings.toString(), "word[lemma/POS]");
+      AnalyzedToken aTok2 = new AnalyzedToken("word", "POS2", "lemma2");
+      tokenReadings.addReading(aTok2);
+      assertEquals(tokenReadings.toString(), "word[lemma/POS,lemma2/POS2]");
+  }
 
   public void testHasPosTag() {
     AnalyzedTokenReadings tokenReadings = new AnalyzedTokenReadings(new 
AnalyzedToken("word", "POS:FOO:BAR", "lemma"));

Modified: 
trunk/JLanguageTool/src/test/org/languagetool/rules/patterns/UnifierTest.java
===================================================================
--- 
trunk/JLanguageTool/src/test/org/languagetool/rules/patterns/UnifierTest.java   
    2012-06-09 09:20:31 UTC (rev 7303)
+++ 
trunk/JLanguageTool/src/test/org/languagetool/rules/patterns/UnifierTest.java   
    2012-06-09 15:33:52 UTC (rev 7304)
@@ -200,7 +200,7 @@
     satisfied &= uni.isSatisfied(sing2, equiv);
     uni.startNextToken();
     assertEquals(true, satisfied);
-    assertEquals("[mały/adj:sg:blahblah:m, człowiek/subst:sg:blahblah:m]", 
Arrays.toString(uni.getUnifiedTokens()));
+    assertEquals("[mały[mały/adj:sg:blahblah:m], 
człowiek[człowiek/subst:sg:blahblah:m]]", 
Arrays.toString(uni.getUnifiedTokens()));
     uni.reset();
   }
 
@@ -259,7 +259,7 @@
     uni.isUnified(sing1a, equiv, false);
     uni.isUnified(sing1b, equiv, true);    
     assertEquals(true, uni.isUnified(sing2, equiv, true));
-    assertEquals("[osobisty/adj:sg:nom.acc.voc:n:pos:aff, 
godło/subst:sg:nom.acc.voc:n]", Arrays.toString(uni.getFinalUnified()));
+    assertEquals("[osobiste[osobisty/adj:sg:nom.acc.voc:n:pos:aff], 
godło[godło/subst:sg:nom.acc.voc:n]]", Arrays.toString(uni.getFinalUnified()));
     uni.reset();
 
     //now test a case when the last reading doesn't match at all
@@ -273,7 +273,7 @@
     uni.isUnified(sing1b, equiv, true);
     uni.isUnified(sing2a, equiv, false);
     assertEquals(true, uni.isUnified(sing2b, equiv, true));
-    assertEquals("[osobisty/adj:sg:nom.acc.voc:n:pos:aff, 
godło/subst:sg:nom.acc.voc:n]", Arrays.toString(uni.getFinalUnified()));
+    assertEquals("[osobiste[osobisty/adj:sg:nom.acc.voc:n:pos:aff], 
godło[godło/subst:sg:nom.acc.voc:n]]", Arrays.toString(uni.getFinalUnified()));
     uni.reset();
   }
 

Modified: 
trunk/JLanguageTool/src/test/org/languagetool/tagging/disambiguation/rules/DisambiguationRuleTest.java
===================================================================
--- 
trunk/JLanguageTool/src/test/org/languagetool/tagging/disambiguation/rules/DisambiguationRuleTest.java
      2012-06-09 09:20:31 UTC (rev 7303)
+++ 
trunk/JLanguageTool/src/test/org/languagetool/tagging/disambiguation/rules/DisambiguationRuleTest.java
      2012-06-09 15:33:52 UTC (rev 7304)
@@ -114,7 +114,7 @@
           assertTrue(goodSentence.trim().length() > 0);
           final AnalyzedSentence sent = disambiguateUntil(rules, id,
               languageTool.getRawAnalyzedSentence(goodSentence));
-          assertTrue("The untouched example for rule " + id + "was touched!",
+          assertTrue("The untouched example (" + goodSentence + ") for rule " 
+ id + "was touched!",
               sent.equals(rule.replace(sent)));
         }
       }
@@ -155,6 +155,7 @@
               "Disambiguated sentence is equal to the input sentence for rule 
:"
                   + id, !sent.equals(disambiguatedSent));
           String reading = "";
+          String annotations = "";
           for (final AnalyzedTokenReadings readings : sent.getTokens()) {
             if (readings.isSentStart() && inputForms.indexOf("<S>") == -1) {
               continue;
@@ -162,6 +163,7 @@
             if (readings.getStartPos() == expectedMatchStart) {
               final AnalyzedTokenReadings r[] = { readings };
               reading = new AnalyzedSentence(r).toString();
+              annotations = readings.getHistoricalAnnotations();
               assertTrue(
                   "Wrong marker position in the example for the rule " + id,
                   readings.getStartPos() == expectedMatchStart
@@ -171,8 +173,8 @@
           }
           assertTrue("The input form for the rule " + id + " in the example: "
               + example.toString() + " is different than expected (expected "
-              + inputForms + " but got " + sortForms(reading) + ").", 
sortForms(reading)
-              .equals(inputForms));
+              + inputForms + " but got " + sortForms(reading) + "). The token 
has been changed by the disambiguator: " + annotations, 
+              sortForms(reading).equals(inputForms));
           for (final AnalyzedTokenReadings readings : disambiguatedSent
               .getTokens()) {
             if (readings.isSentStart() && outputForms.indexOf("<S>") == -1) {
@@ -188,8 +190,8 @@
           }
           assertTrue("The output form for the rule " + id + " in the example: "
               + example.toString() + " is different than expected (expected "
-              + outputForms + " but got " + sortForms(reading) + ").", 
sortForms(reading)
-              .equals(outputForms));
+              + outputForms + " but got " + sortForms(reading) + "). The token 
has been changed by the disambiguator: " + annotations,
+              sortForms(reading).equals(outputForms));
         }
       }
     }

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


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Languagetool-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/languagetool-cvs

Reply via email to