Revision: 7235
          
http://languagetool.svn.sourceforge.net/languagetool/?rev=7235&view=rev
Author:   dnaber
Date:     2012-06-04 22:03:46 +0000 (Mon, 04 Jun 2012)
Log Message:
-----------
some improvements and fixes for expert mode

Modified Paths:
--------------
    trunk/JLanguageTool/src/dev/org/languagetool/dev/index/Searcher.java
    
trunk/JLanguageTool/src/test/org/languagetool/dev/index/IndexerSearcherTest.java
    
trunk/ltcommunity/grails-app/controllers/org/languagetool/RuleEditorController.groovy
    trunk/ltcommunity/grails-app/views/ruleEditor/_checkRuleProblem.gsp
    trunk/ltcommunity/grails-app/views/ruleEditor/_corpusResult.gsp

Modified: trunk/JLanguageTool/src/dev/org/languagetool/dev/index/Searcher.java
===================================================================
--- trunk/JLanguageTool/src/dev/org/languagetool/dev/index/Searcher.java        
2012-06-04 21:37:56 UTC (rev 7234)
+++ trunk/JLanguageTool/src/dev/org/languagetool/dev/index/Searcher.java        
2012-06-04 22:03:46 UTC (rev 7235)
@@ -97,8 +97,8 @@
     final int sentencesChecked;
     final int indexSize = indexSearcher.getIndexReader().numDocs();
     if (query.isRelaxed) {
-      // unsupported rules: the number of documents we really ran LT on:
-      sentencesChecked = Math.min(maxHits, topDocs.totalHits);
+      // unsupported rules: we actually check up to maxHits sentences:
+      sentencesChecked = Math.min(maxHits, indexSize);
     } else {
       // supported rules: no need to run LT (other than getting the exact 
match position), so we can claim
       // that we really have checked all the sentences in the index:
@@ -109,6 +109,7 @@
 
   private List<MatchingSentence> findMatchingSentences(IndexSearcher 
indexSearcher, TopDocs topDocs, JLanguageTool languageTool) throws IOException {
     final List<MatchingSentence> matchingSentences = new 
ArrayList<MatchingSentence>();
+    //long t = System.currentTimeMillis();
     for (ScoreDoc match : topDocs.scoreDocs) {
       final Document doc = indexSearcher.doc(match.doc);
       final String sentence = doc.get(PatternRuleQueryBuilder.FIELD_NAME);
@@ -118,6 +119,7 @@
         matchingSentences.add(matchingSentence);
       }
     }
+    //System.out.println(">>>" + (System.currentTimeMillis() - t) + "ms for " 
+ topDocs.scoreDocs.length + " docs");
     return matchingSentences;
   }
 

Modified: 
trunk/JLanguageTool/src/test/org/languagetool/dev/index/IndexerSearcherTest.java
===================================================================
--- 
trunk/JLanguageTool/src/test/org/languagetool/dev/index/IndexerSearcherTest.java
    2012-06-04 21:37:56 UTC (rev 7234)
+++ 
trunk/JLanguageTool/src/test/org/languagetool/dev/index/IndexerSearcherTest.java
    2012-06-04 22:03:46 UTC (rev 7235)
@@ -64,7 +64,7 @@
     assertEquals(false, searcherResult.isRelaxedQuery());
 
     searcherResult = errorSearcher.findRuleMatchesOnIndex(getRule("EYE_BROW"), 
Language.ENGLISH, searcher);
-    assertEquals(1, searcherResult.getCheckedSentences());
+    assertEquals(2, searcherResult.getCheckedSentences());
     assertEquals(1, searcherResult.getMatchingSentences().size());
     assertEquals(true, searcherResult.isRelaxedQuery());
 
@@ -218,4 +218,12 @@
     searcher = new IndexSearcher(directory);
   }
 
+  /*public void testForManualDebug() throws Exception {
+    createIndex("How to move back and fourth from linux to xmb?");
+    final Searcher errorSearcher = new Searcher();
+    SearcherResult searcherResult = 
errorSearcher.findRuleMatchesOnIndex(getRule("IS_EVEN_WORST"), 
Language.ENGLISH, searcher);
+    System.out.println(searcherResult.getCheckedSentences());
+    System.out.println(searcherResult.isRelaxedQuery());
+  }*/
+
 }

Modified: 
trunk/ltcommunity/grails-app/controllers/org/languagetool/RuleEditorController.groovy
===================================================================
--- 
trunk/ltcommunity/grails-app/controllers/org/languagetool/RuleEditorController.groovy
       2012-06-04 21:37:56 UTC (rev 7234)
+++ 
trunk/ltcommunity/grails-app/controllers/org/languagetool/RuleEditorController.groovy
       2012-06-04 22:03:46 UTC (rev 7235)
@@ -34,6 +34,7 @@
     def patternStringConverterService
 
     int CORPUS_MATCH_LIMIT = 20
+    int EXPERT_MODE_CORPUS_MATCH_LIMIT = 100
 
     def index = {
         List languageNames = getLanguageNames()
@@ -59,13 +60,13 @@
         List shortProblems = []
         checkExampleSentences(patternRule, language, problems, shortProblems)
         if (problems.size() == 0) {
-            SearcherResult searcherResult = 
checkRuleAgainstCorpus(patternRule, language)
+            SearcherResult searcherResult = 
checkRuleAgainstCorpus(patternRule, language, CORPUS_MATCH_LIMIT)
             log.info("Checked rule: valid - LANG: ${language.getShortName()} - 
PATTERN: ${params.pattern} - BAD: ${params.incorrectExample1} - GOOD: 
${params.correctExample1}")
             [messagePreset: params.messageBackup, namePreset: 
params.nameBackup,
                     searcherResult: searcherResult, limit: CORPUS_MATCH_LIMIT]
         } else {
             log.info("Checked rule: invalid - LANG: ${language.getShortName()} 
- PATTERN: ${params.pattern} - BAD: ${params.incorrectExample1} - GOOD: 
${params.correctExample1} - ${shortProblems}")
-            render(template: 'checkRuleProblem', model: [problems: problems, 
hasRegex: hasRegex(patternRule)])
+            render(template: 'checkRuleProblem', model: [problems: problems, 
hasRegex: hasRegex(patternRule), expertMode: false])
         }
     }
 
@@ -91,16 +92,16 @@
         List shortProblems = []
         checkExampleSentences(patternRule, language, problems, shortProblems)
         if (problems.size() > 0) {
-            render(template: 'checkRuleProblem', model: [problems: problems, 
hasRegex: hasRegex(patternRule)])
+            render(template: 'checkRuleProblem', model: [problems: problems, 
hasRegex: hasRegex(patternRule), expertMode: true])
             return
         }
-        SearcherResult searcherResult = checkRuleAgainstCorpus(patternRule, 
language)
-        render(view: '_corpusResult', model: [searcherResult: searcherResult, 
expertMode: true, limit: CORPUS_MATCH_LIMIT])
+        SearcherResult searcherResult = checkRuleAgainstCorpus(patternRule, 
language, EXPERT_MODE_CORPUS_MATCH_LIMIT)
+        render(view: '_corpusResult', model: [searcherResult: searcherResult, 
expertMode: true, limit: EXPERT_MODE_CORPUS_MATCH_LIMIT])
     }
 
-    SearcherResult checkRuleAgainstCorpus(PatternRule patternRule, Language 
language) {
+    SearcherResult checkRuleAgainstCorpus(PatternRule patternRule, Language 
language, int maxHits) {
         Searcher searcher = new Searcher()  // TODO: move to service?
-        searcher.setMaxHits(CORPUS_MATCH_LIMIT)
+        searcher.setMaxHits(maxHits)
         String indexDirTemplate = grailsApplication.config.fastSearchIndex
         File indexDir = new File(indexDirTemplate.replace("LANG", 
language.getShortName()))
         if (indexDir.isDirectory()) {

Modified: trunk/ltcommunity/grails-app/views/ruleEditor/_checkRuleProblem.gsp
===================================================================
--- trunk/ltcommunity/grails-app/views/ruleEditor/_checkRuleProblem.gsp 
2012-06-04 21:37:56 UTC (rev 7234)
+++ trunk/ltcommunity/grails-app/views/ruleEditor/_checkRuleProblem.gsp 
2012-06-04 22:03:46 UTC (rev 7235)
@@ -18,7 +18,7 @@
         The second example sentence should not contain the error.
         If you need help, <a href="http://www.languagetool.org/forum/";>please 
ask in our forum</a>.</p>
 
-        <g:if test="${hasRegex}">
+        <g:if test="${hasRegex && !expertMode}">
             <p style="width:450px;margin-top: 5px">Note that you have used 
special characters like the dot (<tt>.</tt>),
             a question mark (<tt>?</tt>), or similar. This means that the word 
with that character is interpreted
             as a <a 
href="http://en.wikipedia.org/wiki/Regular_expression";>regular expression</a>. 
If you

Modified: trunk/ltcommunity/grails-app/views/ruleEditor/_corpusResult.gsp
===================================================================
--- trunk/ltcommunity/grails-app/views/ruleEditor/_corpusResult.gsp     
2012-06-04 21:37:56 UTC (rev 7234)
+++ trunk/ltcommunity/grails-app/views/ruleEditor/_corpusResult.gsp     
2012-06-04 22:03:46 UTC (rev 7235)
@@ -10,8 +10,10 @@
     <g:else>
 
         <p style="width:700px;">We've checked your pattern against 
${sentencesChecked} sentences
-        from <a href="http://www.wikipedia.org";>Wikipedia</a> and found the 
following matches (showing only the
-        first ${limit} matches).
+        from <a href="http://www.wikipedia.org";>Wikipedia</a> and found the 
following matches
+        <g:if test="${searcherResult.getMatchingSentences().size() == limit}">
+            (showing only the first ${limit} matches).
+        </g:if>
         Please consider modifying your rule if these matches are false alarms.
         <g:if test="${!expertMode}">
             As this page does not support our full rule syntax you might want 
to learn

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