Revision: 7841
          
http://languagetool.svn.sourceforge.net/languagetool/?rev=7841&view=rev
Author:   dnaber
Date:     2012-08-12 09:32:59 +0000 (Sun, 12 Aug 2012)
Log Message:
-----------
rule editor: move search to service class

Modified Paths:
--------------
    
trunk/ltcommunity/grails-app/controllers/org/languagetool/RuleEditorController.groovy

Added Paths:
-----------
    trunk/ltcommunity/grails-app/services/org/languagetool/SearchService.groovy

Modified: 
trunk/ltcommunity/grails-app/controllers/org/languagetool/RuleEditorController.groovy
===================================================================
--- 
trunk/ltcommunity/grails-app/controllers/org/languagetool/RuleEditorController.groovy
       2012-08-12 00:25:06 UTC (rev 7840)
+++ 
trunk/ltcommunity/grails-app/controllers/org/languagetool/RuleEditorController.groovy
       2012-08-12 09:32:59 UTC (rev 7841)
@@ -33,10 +33,10 @@
 class RuleEditorController extends BaseController {
 
     def patternStringConverterService
+    def searchService
 
     int CORPUS_MATCH_LIMIT = 20
     int EXPERT_MODE_CORPUS_MATCH_LIMIT = 100
-    int SEARCH_TIMEOUT_MILLIS = 5000
 
     def index = {
         List languageNames = getLanguageNames()
@@ -62,7 +62,7 @@
         List shortProblems = []
         checkExampleSentences(patternRule, language, problems, shortProblems)
         if (problems.size() == 0) {
-            SearcherResult searcherResult = 
checkRuleAgainstCorpus(patternRule, language, CORPUS_MATCH_LIMIT)
+            SearcherResult searcherResult = 
searchService.checkRuleAgainstCorpus(patternRule, language, CORPUS_MATCH_LIMIT)
             log.info("Checked rule: valid - LANG: 
${language.getShortNameWithVariant()} - PATTERN: ${params.pattern} - BAD: 
${params.incorrectExample1} - GOOD: ${params.correctExample1}")
             [messagePreset: params.messageBackup, namePreset: 
params.nameBackup,
                     searcherResult: searcherResult, limit: CORPUS_MATCH_LIMIT]
@@ -99,34 +99,12 @@
             return
         }
         long startTime = System.currentTimeMillis()
-        SearcherResult searcherResult = checkRuleAgainstCorpus(patternRule, 
language, EXPERT_MODE_CORPUS_MATCH_LIMIT)
+        SearcherResult searcherResult = 
searchService.checkRuleAgainstCorpus(patternRule, language, 
EXPERT_MODE_CORPUS_MATCH_LIMIT)
         long searchTime = System.currentTimeMillis() - startTime
-        log.info("Checked XML in ${language}, timeout 
(${SEARCH_TIMEOUT_MILLIS}ms) triggered: ${searcherResult.resultIsTimeLimited}, 
time: ${searchTime}ms")
+        log.info("Checked XML in ${language}, timeout 
(${SearchService.SEARCH_TIMEOUT_MILLIS}ms) triggered: 
${searcherResult.resultIsTimeLimited}, time: ${searchTime}ms")
         render(view: '_corpusResult', model: [searcherResult: searcherResult, 
expertMode: true, limit: EXPERT_MODE_CORPUS_MATCH_LIMIT])
     }
 
-    SearcherResult checkRuleAgainstCorpus(PatternRule patternRule, Language 
language, int maxHits) {
-        Searcher searcher = new Searcher()  // TODO: move to service?
-        searcher.setMaxHits(maxHits)
-        searcher.setMaxSearchTimeMillis(SEARCH_TIMEOUT_MILLIS)
-        String indexDirTemplate = grailsApplication.config.fastSearchIndex
-        File indexDir = new File(indexDirTemplate.replace("LANG", 
language.getShortName()))
-        if (indexDir.isDirectory()) {
-            def directory = FSDirectory.open(indexDir)
-            DirectoryReader indexReader = DirectoryReader.open(directory)
-            SearcherResult searcherResult = null
-            try {
-              IndexSearcher indexSearcher = new IndexSearcher(indexReader)
-              searcherResult = searcher.findRuleMatchesOnIndex(patternRule, 
language, indexSearcher)
-            } finally {
-              indexReader.close()
-            }
-            return searcherResult
-        } else {
-            throw new NoDataForLanguageException(language, indexDir)
-        }
-    }
-
     private void checkExampleSentences(PatternRule patternRule, Language 
language, List problems, List shortProblems) {
         JLanguageTool langTool = getLanguageToolWithOneRule(language, 
patternRule)
         List correctExamples = patternRule.getCorrectExamples()

Added: 
trunk/ltcommunity/grails-app/services/org/languagetool/SearchService.groovy
===================================================================
--- trunk/ltcommunity/grails-app/services/org/languagetool/SearchService.groovy 
                        (rev 0)
+++ trunk/ltcommunity/grails-app/services/org/languagetool/SearchService.groovy 
2012-08-12 09:32:59 UTC (rev 7841)
@@ -0,0 +1,55 @@
+/* LanguageTool Community
+ * Copyright (C) 2012 Daniel Naber (http://www.danielnaber.de)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+ * USA
+ */
+package org.languagetool
+
+import org.languagetool.dev.index.SearcherResult
+import org.languagetool.rules.patterns.PatternRule
+import org.languagetool.dev.index.Searcher
+import org.apache.lucene.store.FSDirectory
+import org.apache.lucene.index.DirectoryReader
+import org.apache.lucene.search.IndexSearcher
+
+class SearchService {
+
+    public static final int SEARCH_TIMEOUT_MILLIS = 5000
+
+    def grailsApplication
+
+    SearcherResult checkRuleAgainstCorpus(PatternRule patternRule, Language 
language, int maxHits) {
+        Searcher searcher = new Searcher()
+        searcher.setMaxHits(maxHits)
+        searcher.setMaxSearchTimeMillis(SEARCH_TIMEOUT_MILLIS)
+        String indexDirTemplate = grailsApplication.config.fastSearchIndex
+        File indexDir = new File(indexDirTemplate.replace("LANG", 
language.getShortName()))
+        if (indexDir.isDirectory()) {
+            def directory = FSDirectory.open(indexDir)
+            DirectoryReader indexReader = DirectoryReader.open(directory)
+            SearcherResult searcherResult = null
+            try {
+                IndexSearcher indexSearcher = new IndexSearcher(indexReader)
+                searcherResult = searcher.findRuleMatchesOnIndex(patternRule, 
language, indexSearcher)
+            } finally {
+                indexReader.close()
+            }
+            return searcherResult
+        } else {
+            throw new NoDataForLanguageException(language, indexDir)
+        }
+    }
+}

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
Languagetool-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/languagetool-cvs

Reply via email to