Parser for the Solr synonyms format.
  1. Blank lines and lines starting with '#' are comments.
  2. Explicit mappings match any token sequence on the LHS of "=>" and replace with all alternatives on the RHS. These types of mappings ignore the expand parameter in the constructor. Example:
    i-pod, i pod => ipod
  3. Equivalent synonyms may be separated with commas and give no explicit mapping. In this case the mapping behavior will be taken from the expand parameter in the constructor. This allows the same synonym file to be used in different synonym handling strategies. Example:
    ipod, i-pod, i pod
  4. Multiple synonym mapping entries are merged. Example:
    foo => foo bar
    foo => baz

    is equivalent to

    foo => foo bar, baz
@lucene.experimental
Inheritance: SynonymMap.Parser
Exemplo n.º 1
0
        /// <summary>
        /// parse a syn file with bad syntax </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected=java.text.ParseException.class) public void testInvalidAnalyzesToNothingOutput() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        public virtual void testInvalidAnalyzesToNothingOutput()
        {
            string            testFile = "a => 1";
            SolrSynonymParser parser   = new SolrSynonymParser(true, true, new MockAnalyzer(random(), MockTokenizer.SIMPLE, false));

            parser.parse(new StringReader(testFile));
        }
Exemplo n.º 2
0
        /// <summary>
        /// parse a syn file with bad syntax </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected=java.text.ParseException.class) public void testInvalidPositionsOutput() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        public virtual void testInvalidPositionsOutput()
        {
            string            testFile = "the test => testola";
            SolrSynonymParser parser   = new SolrSynonymParser(true, true, new EnglishAnalyzer(TEST_VERSION_CURRENT));

            parser.parse(new StringReader(testFile));
        }
Exemplo n.º 3
0
        /// <summary>
        /// parse a syn file with bad syntax </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected=java.text.ParseException.class) public void testInvalidDoubleMap() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        public virtual void testInvalidDoubleMap()
        {
            string            testFile = "a => b => c";
            SolrSynonymParser parser   = new SolrSynonymParser(true, true, new MockAnalyzer(random()));

            parser.parse(new StringReader(testFile));
        }
        /// <summary>
        /// parse a syn file with some escaped syntax chars </summary>
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public void testEscapedStuff() throws Exception
        public virtual void testEscapedStuff()
        {
            string testFile = "a\\=>a => b\\=>b\n" + "a\\,a => b\\,b";
            SolrSynonymParser parser = new SolrSynonymParser(true, true, new MockAnalyzer(random(), MockTokenizer.KEYWORD, false));
            parser.parse(new StringReader(testFile));
            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final SynonymMap map = parser.build();
            SynonymMap map = parser.build();
            Analyzer analyzer = new AnalyzerAnonymousInnerClassHelper2(this, map);

            assertAnalyzesTo(analyzer, "ball", new string[] {"ball"}, new int[] {1});

            assertAnalyzesTo(analyzer, "a=>a", new string[] {"b=>b"}, new int[] {1});

            assertAnalyzesTo(analyzer, "a,a", new string[] {"b,b"}, new int[] {1});
        }
Exemplo n.º 5
0
        /// <summary>
        /// parse a syn file with some escaped syntax chars </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testEscapedStuff() throws Exception
        public virtual void testEscapedStuff()
        {
            string            testFile = "a\\=>a => b\\=>b\n" + "a\\,a => b\\,b";
            SolrSynonymParser parser   = new SolrSynonymParser(true, true, new MockAnalyzer(random(), MockTokenizer.KEYWORD, false));

            parser.parse(new StringReader(testFile));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final SynonymMap map = parser.build();
            SynonymMap map      = parser.build();
            Analyzer   analyzer = new AnalyzerAnonymousInnerClassHelper2(this, map);

            assertAnalyzesTo(analyzer, "ball", new string[] { "ball" }, new int[] { 1 });

            assertAnalyzesTo(analyzer, "a=>a", new string[] { "b=>b" }, new int[] { 1 });

            assertAnalyzesTo(analyzer, "a,a", new string[] { "b,b" }, new int[] { 1 });
        }
Exemplo n.º 6
0
        /// <summary>
        /// Tests some simple examples from the solr wiki </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testSimple() throws Exception
        public virtual void testSimple()
        {
            string testFile = "i-pod, ipod, ipoooood\n" + "foo => foo bar\n" + "foo => baz\n" + "this test, that testing";

            SolrSynonymParser parser = new SolrSynonymParser(true, true, new MockAnalyzer(random()));

            parser.parse(new StringReader(testFile));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final SynonymMap map = parser.build();
            SynonymMap map = parser.build();

            Analyzer analyzer = new AnalyzerAnonymousInnerClassHelper(this, map);

            assertAnalyzesTo(analyzer, "ball", new string[] { "ball" }, new int[] { 1 });

            assertAnalyzesTo(analyzer, "i-pod", new string[] { "i-pod", "ipod", "ipoooood" }, new int[] { 1, 0, 0 });

            assertAnalyzesTo(analyzer, "foo", new string[] { "foo", "baz", "bar" }, new int[] { 1, 0, 1 });

            assertAnalyzesTo(analyzer, "this test", new string[] { "this", "that", "test", "testing" }, new int[] { 1, 0, 1, 0 });
        }
Exemplo n.º 7
0
        // LUCENE-3375
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public void testVanishingTerms() throws Exception
        public virtual void testVanishingTerms()
        {
            string testFile = "aaa => aaaa1 aaaa2 aaaa3\n" + "bbb => bbbb1 bbbb2\n";

            SolrSynonymParser parser = new SolrSynonymParser(true, true, new MockAnalyzer(random()));
            parser.parse(new StringReader(testFile));
            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final SynonymMap map = parser.build();
            SynonymMap map = parser.build();

            Analyzer analyzer = new AnalyzerAnonymousInnerClassHelper5(this, map);

            // where did my pot go?!
            assertAnalyzesTo(analyzer, "xyzzy bbb pot of gold", new string[] {"xyzzy", "bbbb1", "pot", "bbbb2", "of", "gold"});

            // this one nukes 'pot' and 'of'
            // xyzzy aaa pot of gold -> xyzzy aaaa1 aaaa2 aaaa3 gold
            assertAnalyzesTo(analyzer, "xyzzy aaa pot of gold", new string[] {"xyzzy", "aaaa1", "pot", "aaaa2", "of", "aaaa3", "gold"});
        }
 /// <summary>
 /// parse a syn file with bad syntax </summary>
 //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
 //ORIGINAL LINE: @Test(expected=java.text.ParseException.class) public void testInvalidPositionsInput() throws Exception
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 public virtual void testInvalidPositionsInput()
 {
     string testFile = "testola => the test";
     SolrSynonymParser parser = new SolrSynonymParser(true, true, new EnglishAnalyzer(TEST_VERSION_CURRENT));
     parser.parse(new StringReader(testFile));
 }
 /// <summary>
 /// parse a syn file with bad syntax </summary>
 //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
 //ORIGINAL LINE: @Test(expected=java.text.ParseException.class) public void testInvalidDoubleMap() throws Exception
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 public virtual void testInvalidDoubleMap()
 {
     string testFile = "a => b => c";
     SolrSynonymParser parser = new SolrSynonymParser(true, true, new MockAnalyzer(random()));
     parser.parse(new StringReader(testFile));
 }
Exemplo n.º 10
0
 /// <summary>
 /// parse a syn file with bad syntax </summary>
 //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
 //ORIGINAL LINE: @Test(expected=java.text.ParseException.class) public void testInvalidAnalyzesToNothingOutput() throws Exception
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 public virtual void testInvalidAnalyzesToNothingOutput()
 {
     string testFile = "a => 1";
     SolrSynonymParser parser = new SolrSynonymParser(true, true, new MockAnalyzer(random(), MockTokenizer.SIMPLE, false));
     parser.parse(new StringReader(testFile));
 }
Exemplo n.º 11
0
        /// <summary>
        /// Tests some simple examples from the solr wiki </summary>
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public void testSimple() throws Exception
        public virtual void testSimple()
        {
            string testFile = "i-pod, ipod, ipoooood\n" + "foo => foo bar\n" + "foo => baz\n" + "this test, that testing";

            SolrSynonymParser parser = new SolrSynonymParser(true, true, new MockAnalyzer(random()));
            parser.parse(new StringReader(testFile));
            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final SynonymMap map = parser.build();
            SynonymMap map = parser.build();

            Analyzer analyzer = new AnalyzerAnonymousInnerClassHelper(this, map);

            assertAnalyzesTo(analyzer, "ball", new string[] {"ball"}, new int[] {1});

            assertAnalyzesTo(analyzer, "i-pod", new string[] {"i-pod", "ipod", "ipoooood"}, new int[] {1, 0, 0});

            assertAnalyzesTo(analyzer, "foo", new string[] {"foo", "baz", "bar"}, new int[] {1, 0, 1});

            assertAnalyzesTo(analyzer, "this test", new string[] {"this", "that", "test", "testing"}, new int[] {1, 0, 1, 0});
        }