You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ro...@apache.org on 2019/11/13 15:53:35 UTC
[lucene-solr] branch branch_8x updated: LUCENE-9030: Fix different
Solr- and WordnetSynonymParser behaviour (#981)
This is an automated email from the ASF dual-hosted git repository.
romseygeek pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/branch_8x by this push:
new eeea9fe LUCENE-9030: Fix different Solr- and WordnetSynonymParser behaviour (#981)
eeea9fe is described below
commit eeea9fe2c7447a9f748d0881712c19328b21621c
Author: Christoph Büscher <cb...@posteo.de>
AuthorDate: Wed Nov 13 16:40:46 2019 +0100
LUCENE-9030: Fix different Solr- and WordnetSynonymParser behaviour (#981)
This fixes an issue where sets of equivalent synonyms in the Wordnet format are
parsed and added to the SynonymMap in a way that leads to the original input
token not being typed as "word" but as SYNONYM instead. Also the original token
doesn't appear first in the token stream output, which is the case for
equivalent solr formatted synonym files.
Currently the WordnetSynonymParser adds all combinations of input/output pairs
of a synset entry into the synonym map, while the SolrSynonymParser excludes
those where input and output term are the same. This change adds the same
behaviour to WordnetSynonymParser and adds tests that show the two formats are
outputting the same token order and types now.
---
lucene/CHANGES.txt | 3 +++
.../analysis/synonym/WordnetSynonymParser.java | 4 +++-
.../analysis/synonym/TestSolrSynonymParser.java | 23 ++++++++++++++++++++++
.../analysis/synonym/TestWordnetSynonymParser.java | 5 +++++
4 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 29c4907..6a777a7 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -48,6 +48,9 @@ Bug Fixes
* LUCENE-9001: Fix race condition in SetOnce. (Przemko Robakowski)
+* LUCENE-9030: Fix WordnetSynonymParser behaviour so it behaves similar to
+ SolrSynonymParser. (Christoph Buescher via Alan Woodward)
+
Other
* LUCENE-8979: Code Cleanup: Use entryset for map iteration wherever possible. - Part 2 (Koen De Groote)
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/WordnetSynonymParser.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/WordnetSynonymParser.java
index 13e488c..aa83ac4 100644
--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/WordnetSynonymParser.java
+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/WordnetSynonymParser.java
@@ -96,7 +96,9 @@ public class WordnetSynonymParser extends SynonymMap.Parser {
if (expand) {
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
- add(synset[i], synset[j], false);
+ if (i != j) {
+ add(synset[i], synset[j], true);
+ }
}
}
} else {
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/synonym/TestSolrSynonymParser.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/synonym/TestSolrSynonymParser.java
index 9467137..748b177 100644
--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/synonym/TestSolrSynonymParser.java
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/synonym/TestSolrSynonymParser.java
@@ -185,6 +185,29 @@ public class TestSolrSynonymParser extends BaseSynonymParserTestCase {
new int[]{1, 2, 1});
}
+ /** Verify type of original token is "word", others are Synonym. */
+ public void testTypes() throws Exception {
+ String testFile = "woods, wood, forest";
+
+ Analyzer analyzer = new MockAnalyzer(random());
+ SolrSynonymParser parser = new SolrSynonymParser(true, true, analyzer);
+ parser.parse(new StringReader(testFile));
+ final SynonymMap map = parser.build();
+ analyzer.close();
+
+ analyzer = new Analyzer() {
+ @Override
+ protected TokenStreamComponents createComponents(String fieldName) {
+ Tokenizer tokenizer = new MockTokenizer(MockTokenizer.WHITESPACE, true);
+ return new TokenStreamComponents(tokenizer, new SynonymFilter(tokenizer, map, true));
+ }
+ };
+
+ assertAnalyzesTo(analyzer, "lost in the forest",
+ new String[]{"lost", "in", "the", "forest", "woods", "wood"},
+ new String[]{"word", "word", "word", "word", "SYNONYM", "SYNONYM"});
+ }
+
/** Test parsing of simple examples. */
public void testParseSimple() throws Exception {
String testFile =
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/synonym/TestWordnetSynonymParser.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/synonym/TestWordnetSynonymParser.java
index 675c829..2449f8f 100644
--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/synonym/TestWordnetSynonymParser.java
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/synonym/TestWordnetSynonymParser.java
@@ -66,6 +66,11 @@ public class TestWordnetSynonymParser extends BaseTokenStreamTestCase {
/* multi words */
assertAnalyzesTo(analyzer, "king's evil",
new String[] { "king's", "king's", "evil", "meany" });
+
+ /* all expansions, test types */
+ assertAnalyzesTo(analyzer, "Lost in the forest",
+ new String[] { "Lost", "in", "the", "forest", "woods", "wood"},
+ new String[] { "word", "word", "word", "word", "SYNONYM", "SYNONYM" });
analyzer.close();
}
}