Revision: 7228
http://languagetool.svn.sourceforge.net/languagetool/?rev=7228&view=rev
Author: dnaber
Date: 2012-06-03 22:08:18 +0000 (Sun, 03 Jun 2012)
Log Message:
-----------
corpus search: fix NullPointerException in pattern with only one token and
exception
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-03 21:09:07 UTC (rev 7227)
+++
trunk/JLanguageTool/src/dev/org/languagetool/dev/index/PatternRuleQueryBuilder.java
2012-06-03 22:08:18 UTC (rev 7228)
@@ -83,7 +83,14 @@
} else {
// create an empty token for the unsupported token, so that it can
match any term with any
// POS tag.
- tokenQuery = createTokenQuery("", false, false, false);
+ if (patternElement.hasExceptionList()) {
+ // having an exception causes the rule not to be supported but we
can ignore it
+ // and search for the token to get a super set of matches:
+ tokenQuery = createTokenQuery(patternElement.getString(),
patternElement.getNegation(),
+ patternElement.isRegularExpression(),
patternElement.getCaseSensitive());
+ } else {
+ tokenQuery = createTokenQuery("", false, false, false);
+ }
}
}
Modified:
trunk/JLanguageTool/src/test/org/languagetool/dev/index/IndexerSearcherTest.java
===================================================================
---
trunk/JLanguageTool/src/test/org/languagetool/dev/index/IndexerSearcherTest.java
2012-06-03 21:09:07 UTC (rev 7227)
+++
trunk/JLanguageTool/src/test/org/languagetool/dev/index/IndexerSearcherTest.java
2012-06-03 22:08:18 UTC (rev 7228)
@@ -83,7 +83,7 @@
return errorSearcher.getRuleById(ruleId, ruleFile);
}
- public void testIndexerSearcherWithNewRule() throws Exception {
+ public void testWithNewRule() throws Exception {
createIndex("How to move back and fourth from linux to xmb?");
final Searcher errorSearcher = new Searcher();
final List<Element> elements = Arrays.asList(
@@ -106,7 +106,7 @@
}
}
- public void testIndexerSearcherWithRegexRule() throws Exception {
+ public void testWithRegexRule() throws Exception {
createIndex("How to move back and fourth from linux to xmb?");
final Searcher errorSearcher = new Searcher();
final List<Element> elements = Arrays.asList(
@@ -162,7 +162,7 @@
}
}
- public void testIndexerSearcherWithException() throws Exception {
+ public void testWithException() throws Exception {
createIndex("How to move back and fourth from linux to xmb?");
final Searcher errorSearcher = new Searcher();
final Element exceptionElem = new Element("forth|back", false, true,
false);
@@ -187,6 +187,30 @@
}
}
+ public void testWithOneElementWithException() throws Exception {
+ createIndex("How to move back and fourth from linux to xmb?");
+ final Searcher errorSearcher = new Searcher();
+ final Element exceptionElem = new Element("forth|back", false, true,
false);
+ exceptionElem.setStringPosException("exception", false, false, false,
false, false, "POS", false, false);
+ final List<Element> elements = Arrays.asList(
+ exceptionElem
+ );
+ final PatternRule rule1 = new PatternRule("RULE1", Language.ENGLISH,
elements, "desc", "msg", "shortMsg");
+ final IndexSearcher indexSearcher = new IndexSearcher(directory);
+ try {
+ final SearcherResult searcherResult =
errorSearcher.findRuleMatchesOnIndex(rule1, Language.ENGLISH, indexSearcher);
+ assertEquals(1, searcherResult.getCheckedSentences());
+ assertEquals(1, searcherResult.getMatchingSentences().size());
+ assertEquals(true, searcherResult.isRelaxedQuery());
+ final List<RuleMatch> ruleMatches =
searcherResult.getMatchingSentences().get(0).getRuleMatches();
+ assertEquals(1, ruleMatches.size());
+ final Rule rule = ruleMatches.get(0).getRule();
+ assertEquals("RULE1", rule.getId());
+ } finally {
+ indexSearcher.close();
+ }
+ }
+
private void createIndex(String content) throws IOException {
directory = newDirectory();
//directory = FSDirectory.open(new File("/tmp/lucenetest"));
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