Revision: 7439
          
http://languagetool.svn.sourceforge.net/languagetool/?rev=7439&view=rev
Author:   dnaber
Date:     2012-06-20 22:04:37 +0000 (Wed, 20 Jun 2012)
Log Message:
-----------
rule indexing: fix another known problem

Modified Paths:
--------------
    
trunk/JLanguageTool/src/dev/org/languagetool/dev/index/PatternRuleQueryBuilder.java
    
trunk/JLanguageTool/src/test/org/languagetool/dev/index/IndexerSearcherTest.java

Modified: 
trunk/JLanguageTool/src/dev/org/languagetool/dev/index/PatternRuleQueryBuilder.java
===================================================================
--- 
trunk/JLanguageTool/src/dev/org/languagetool/dev/index/PatternRuleQueryBuilder.java
 2012-06-20 21:50:32 UTC (rev 7438)
+++ 
trunk/JLanguageTool/src/dev/org/languagetool/dev/index/PatternRuleQueryBuilder.java
 2012-06-20 22:04:37 UTC (rev 7439)
@@ -54,8 +54,13 @@
     }
   }
 
+  private SpanQuery next(Iterator<Element> it, boolean 
throwExceptionOnUnsupportedRule)
+          throws UnsupportedPatternRuleException {
+    return next(it, throwExceptionOnUnsupportedRule, 0);
+  }
+
   // create the next SpanQuery from the top Element in the Iterator.
-  private SpanQuery next(Iterator<Element> it, boolean 
throwExceptionOnUnsupportedRule)
+  private SpanQuery next(Iterator<Element> it, boolean 
throwExceptionOnUnsupportedRule, int position)
       throws UnsupportedPatternRuleException {
 
     // no more Element
@@ -68,7 +73,7 @@
     SpanQuery tokenQuery;
     SpanQuery posQuery = null;
     try {
-      checkUnsupportedRule(patternElement);
+      checkUnsupportedRule(patternElement, position);
       final boolean caseSensitive = patternElement.getCaseSensitive();
 
       tokenQuery = createTokenQuery(patternElement.getString(), 
patternElement.getNegation(),
@@ -89,7 +94,11 @@
           tokenQuery = createTokenQuery(patternElement.getString(), 
patternElement.getNegation(),
                   patternElement.isRegularExpression(), 
patternElement.getCaseSensitive());
         } else {
-          tokenQuery = new POSAwaredSpanRegexQuery(new Term(FIELD_NAME, ".*"), 
false);
+          if (position == 0 && patternElement.getNegation()) {
+            tokenQuery = null;
+          } else {
+            tokenQuery = new POSAwaredSpanRegexQuery(new Term(FIELD_NAME, 
".*"), false);
+          }
         }
       }
 
@@ -116,7 +125,7 @@
     }
 
     // recursion invoke
-    final SpanQuery next = next(it, throwExceptionOnUnsupportedRule);
+    final SpanQuery next = next(it, throwExceptionOnUnsupportedRule, position 
+ 1);
 
     if (next != null) {
       list.add(next);
@@ -129,31 +138,28 @@
 
   }
 
-  private void checkUnsupportedRule(Element patternElement)
+  private void checkUnsupportedRule(Element patternElement, int position)
       throws UnsupportedPatternRuleException {
-    // we need Element to expose its features of exception and whitespace 
testing support.
+    if (position == 0 && patternElement.getNegation()) {
+      throw new UnsupportedPatternRuleException("Pattern rules with negation 
in first element are not supported.");
+    }
     if (patternElement.hasExceptionList()) {
-      throw new UnsupportedPatternRuleException(
-          "Pattern rules with token exceptions are not supported.");
+      throw new UnsupportedPatternRuleException("Pattern rules with token 
exceptions are not supported.");
     }
     if (patternElement.testWhitespace()) {
-      throw new UnsupportedPatternRuleException(
-          "Pattern rules with tokens testing \"Whitespace before\" are not 
supported.");
+      throw new UnsupportedPatternRuleException("Pattern rules with tokens 
testing \"Whitespace before\" are not supported.");
     }
     if (patternElement.hasAndGroup()) {
-      throw new UnsupportedPatternRuleException(
-          "Pattern rules with tokens in \"And Group\" are not supported.");
+      throw new UnsupportedPatternRuleException("Pattern rules with tokens in 
\"And Group\" are not supported.");
     }
     if (patternElement.isPartOfPhrase()) {
       throw new UnsupportedPatternRuleException("Pattern rules with phrases 
are not supported.");
     }
     if (patternElement.isUnified()) {
-      throw new UnsupportedPatternRuleException(
-          "Pattern rules with unified tokens are not supported.");
+      throw new UnsupportedPatternRuleException("Pattern rules with unified 
tokens are not supported.");
     }
     if (patternElement.isInflected()) {
-      throw new UnsupportedPatternRuleException(
-          "Pattern rules with inflected tokens are not supported.");
+      throw new UnsupportedPatternRuleException("Pattern rules with inflected 
tokens are not supported.");
     }
     // TODO: exception for <match no="0"/> etc. (patternElement.getMatch()?)
   }

Modified: 
trunk/JLanguageTool/src/test/org/languagetool/dev/index/IndexerSearcherTest.java
===================================================================
--- 
trunk/JLanguageTool/src/test/org/languagetool/dev/index/IndexerSearcherTest.java
    2012-06-20 21:50:32 UTC (rev 7438)
+++ 
trunk/JLanguageTool/src/test/org/languagetool/dev/index/IndexerSearcherTest.java
    2012-06-20 22:04:37 UTC (rev 7439)
@@ -157,8 +157,8 @@
   /** for manual debugging only */
   public void IGNOREtestForDebugging() throws Exception {
     // Note that the second sentence ends with "lid" instead of "lids" (the 
inflated one)
-    createIndex("Das machen Sinn");
-    final PatternRule rule = getRule("SINN_MACHEN", new 
File("src/rules/de/grammar.xml"));
+    createIndex("I thin so");
+    final PatternRule rule = getRule("I_THIN", new 
File("src/rules/en/grammar.xml"));
     final SearcherResult searcherResult = 
errorSearcher.findRuleMatchesOnIndex(rule, Language.GERMAN, searcher);
     System.out.println("Matches: " + searcherResult.getMatchingSentences());
     assertEquals(1, searcherResult.getMatchingSentences().size());
@@ -304,8 +304,7 @@
     }
   }
 
-  // TODO: known to fail, see TODO in LanguageToolFilter
-  public void IGNOREtestNegatedMatchAtSentenceStart() throws Exception {
+  public void testNegatedMatchAtSentenceStart() throws Exception {
     createIndex("How to move?");
     final Searcher errorSearcher = new Searcher();
     final Element negatedElement = new Element("Negated", false, false, false);
@@ -320,7 +319,7 @@
       final SearcherResult searcherResult = 
errorSearcher.findRuleMatchesOnIndex(rule1, Language.ENGLISH, indexSearcher);
       assertEquals(1, searcherResult.getCheckedSentences());
       assertEquals(1, searcherResult.getMatchingSentences().size());
-      assertEquals(false, searcherResult.isRelaxedQuery());
+      assertEquals(true, searcherResult.isRelaxedQuery());
       final List<RuleMatch> ruleMatches = 
searcherResult.getMatchingSentences().get(0).getRuleMatches();
       assertEquals(1, ruleMatches.size());
       final Rule rule = ruleMatches.get(0).getRule();

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