//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public void testMapMerge() throws java.io.IOException
        public virtual void testMapMerge()
        {
            SlowSynonymMap map = new SlowSynonymMap();

            bool orig = false;
            bool merge = true;
            map.add(strings("a"), tokens("a5,5"), orig, merge);
            map.add(strings("a"), tokens("a3,3"), orig, merge);

            assertTokenizesTo(map, "a", new string[] {"a3", "a5"}, new int[] {1, 2});

            map.add(strings("b"), tokens("b3,3"), orig, merge);
            map.add(strings("b"), tokens("b5,5"), orig, merge);

            assertTokenizesTo(map, "b", new string[] {"b3", "b5"}, new int[] {1, 2});

            map.add(strings("a"), tokens("A3,3"), orig, merge);
            map.add(strings("a"), tokens("A5,5"), orig, merge);

            assertTokenizesTo(map, "a", new string[] {"a3", "A3", "a5", "A5"}, new int[] {1, 0, 2, 0});

            map.add(strings("a"), tokens("a1"), orig, merge);
            assertTokenizesTo(map, "a", new string[] {"a1", "a3", "A3", "a5", "A5"}, new int[] {1, 2, 0, 2, 0});

            map.add(strings("a"), tokens("a2,2"), orig, merge);
            map.add(strings("a"), tokens("a4,4 a6,2"), orig, merge);
            assertTokenizesTo(map, "a", new string[] {"a1", "a2", "a3", "A3", "a4", "a5", "A5", "a6"}, new int[] {1, 1, 1, 0, 1, 1, 0, 1});
        }
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public void testIncludeOrig() throws java.io.IOException
        public virtual void testIncludeOrig()
        {
            SlowSynonymMap map = new SlowSynonymMap();

            bool orig = true;
            bool merge = true;
            map.add(strings("a b"), tokens("ab"), orig, merge);
            map.add(strings("a c"), tokens("ac"), orig, merge);
            map.add(strings("a"), tokens("aa"), orig, merge);
            map.add(strings("b"), tokens("bb"), orig, merge);
            map.add(strings("z x c v"), tokens("zxcv"), orig, merge);
            map.add(strings("x c"), tokens("xc"), orig, merge);

            assertTokenizesTo(map, "$", new string[] {"$"}, new int[] {1});
            assertTokenizesTo(map, "a", new string[] {"a", "aa"}, new int[] {1, 0});
            assertTokenizesTo(map, "a", new string[] {"a", "aa"}, new int[] {1, 0});
            assertTokenizesTo(map, "$ a", new string[] {"$", "a", "aa"}, new int[] {1, 1, 0});
            assertTokenizesTo(map, "a $", new string[] {"a", "aa", "$"}, new int[] {1, 0, 1});
            assertTokenizesTo(map, "$ a !", new string[] {"$", "a", "aa", "!"}, new int[] {1, 1, 0, 1});
            assertTokenizesTo(map, "a a", new string[] {"a", "aa", "a", "aa"}, new int[] {1, 0, 1, 0});
            assertTokenizesTo(map, "b", new string[] {"b", "bb"}, new int[] {1, 0});
            assertTokenizesTo(map, "z x c v", new string[] {"z", "zxcv", "x", "c", "v"}, new int[] {1, 0, 1, 1, 1});
            assertTokenizesTo(map, "z x c $", new string[] {"z", "x", "xc", "c", "$"}, new int[] {1, 1, 0, 1, 1});

            // check for lack of recursion
            map.add(strings("zoo zoo"), tokens("zoo"), orig, merge);
            // CHECKME: I think the previous test (with 4 zoo's), was just a typo.
            assertTokenizesTo(map, "zoo zoo $ zoo", new string[] {"zoo", "zoo", "zoo", "$", "zoo"}, new int[] {1, 0, 1, 1, 1});

            map.add(strings("zoo"), tokens("zoo zoo"), orig, merge);
            assertTokenizesTo(map, "zoo zoo $ zoo", new string[] {"zoo", "zoo", "zoo", "$", "zoo", "zoo", "zoo"}, new int[] {1, 0, 1, 1, 1, 0, 1});
        }
예제 #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testMapMerge() throws java.io.IOException
        public virtual void testMapMerge()
        {
            SlowSynonymMap map = new SlowSynonymMap();

            bool orig  = false;
            bool merge = true;

            map.add(strings("a"), tokens("a5,5"), orig, merge);
            map.add(strings("a"), tokens("a3,3"), orig, merge);

            assertTokenizesTo(map, "a", new string[] { "a3", "a5" }, new int[] { 1, 2 });

            map.add(strings("b"), tokens("b3,3"), orig, merge);
            map.add(strings("b"), tokens("b5,5"), orig, merge);

            assertTokenizesTo(map, "b", new string[] { "b3", "b5" }, new int[] { 1, 2 });

            map.add(strings("a"), tokens("A3,3"), orig, merge);
            map.add(strings("a"), tokens("A5,5"), orig, merge);

            assertTokenizesTo(map, "a", new string[] { "a3", "A3", "a5", "A5" }, new int[] { 1, 0, 2, 0 });

            map.add(strings("a"), tokens("a1"), orig, merge);
            assertTokenizesTo(map, "a", new string[] { "a1", "a3", "A3", "a5", "A5" }, new int[] { 1, 2, 0, 2, 0 });

            map.add(strings("a"), tokens("a2,2"), orig, merge);
            map.add(strings("a"), tokens("a4,4 a6,2"), orig, merge);
            assertTokenizesTo(map, "a", new string[] { "a1", "a2", "a3", "A3", "a4", "a5", "A5", "a6" }, new int[] { 1, 1, 1, 0, 1, 1, 0, 1 });
        }
예제 #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testIncludeOrig() throws java.io.IOException
        public virtual void testIncludeOrig()
        {
            SlowSynonymMap map = new SlowSynonymMap();

            bool orig  = true;
            bool merge = true;

            map.add(strings("a b"), tokens("ab"), orig, merge);
            map.add(strings("a c"), tokens("ac"), orig, merge);
            map.add(strings("a"), tokens("aa"), orig, merge);
            map.add(strings("b"), tokens("bb"), orig, merge);
            map.add(strings("z x c v"), tokens("zxcv"), orig, merge);
            map.add(strings("x c"), tokens("xc"), orig, merge);

            assertTokenizesTo(map, "$", new string[] { "$" }, new int[] { 1 });
            assertTokenizesTo(map, "a", new string[] { "a", "aa" }, new int[] { 1, 0 });
            assertTokenizesTo(map, "a", new string[] { "a", "aa" }, new int[] { 1, 0 });
            assertTokenizesTo(map, "$ a", new string[] { "$", "a", "aa" }, new int[] { 1, 1, 0 });
            assertTokenizesTo(map, "a $", new string[] { "a", "aa", "$" }, new int[] { 1, 0, 1 });
            assertTokenizesTo(map, "$ a !", new string[] { "$", "a", "aa", "!" }, new int[] { 1, 1, 0, 1 });
            assertTokenizesTo(map, "a a", new string[] { "a", "aa", "a", "aa" }, new int[] { 1, 0, 1, 0 });
            assertTokenizesTo(map, "b", new string[] { "b", "bb" }, new int[] { 1, 0 });
            assertTokenizesTo(map, "z x c v", new string[] { "z", "zxcv", "x", "c", "v" }, new int[] { 1, 0, 1, 1, 1 });
            assertTokenizesTo(map, "z x c $", new string[] { "z", "x", "xc", "c", "$" }, new int[] { 1, 1, 0, 1, 1 });

            // check for lack of recursion
            map.add(strings("zoo zoo"), tokens("zoo"), orig, merge);
            // CHECKME: I think the previous test (with 4 zoo's), was just a typo.
            assertTokenizesTo(map, "zoo zoo $ zoo", new string[] { "zoo", "zoo", "zoo", "$", "zoo" }, new int[] { 1, 0, 1, 1, 1 });

            map.add(strings("zoo"), tokens("zoo zoo"), orig, merge);
            assertTokenizesTo(map, "zoo zoo $ zoo", new string[] { "zoo", "zoo", "zoo", "$", "zoo", "zoo", "zoo" }, new int[] { 1, 0, 1, 1, 1, 0, 1 });
        }
예제 #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: static void assertTokenizesTo(SlowSynonymMap dict, String input, String expected[], int posIncs[]) throws java.io.IOException
        internal static void assertTokenizesTo(SlowSynonymMap dict, string input, string[] expected, int[] posIncs)
        {
            Tokenizer         tokenizer = new MockTokenizer(new StringReader(input), MockTokenizer.WHITESPACE, false);
            SlowSynonymFilter stream    = new SlowSynonymFilter(tokenizer, dict);

            assertTokenStreamContents(stream, expected, posIncs);
        }
예제 #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: static void assertTokenizesTo(SlowSynonymMap dict, java.util.List<org.apache.lucene.analysis.Token> input, String expected[], int startOffsets[], int endOffsets[], int posIncs[]) throws java.io.IOException
        internal static void assertTokenizesTo(SlowSynonymMap dict, IList <Token> input, string[] expected, int[] startOffsets, int[] endOffsets, int[] posIncs)
        {
            TokenStream       tokenizer = new IterTokenStream(input);
            SlowSynonymFilter stream    = new SlowSynonymFilter(tokenizer, dict);

            assertTokenStreamContents(stream, expected, startOffsets, endOffsets, posIncs);
        }
예제 #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testBigramTokenizer() throws Exception
        public virtual void testBigramTokenizer()
        {
            SlowSynonymMap synMap;

            // prepare bi-gram tokenizer factory
            IDictionary <string, string> args = new Dictionary <string, string>();

            args[AbstractAnalysisFactory.LUCENE_MATCH_VERSION_PARAM] = "4.4";
            args["minGramSize"] = "2";
            args["maxGramSize"] = "2";
            TokenizerFactory tf = new NGramTokenizerFactory(args);

            // (ab)->(bc)->(cd)->[ef][fg][gh]
            IList <string> rules = new List <string>();

            rules.Add("abcd=>efgh");
            synMap = new SlowSynonymMap(true);
            SlowSynonymFilterFactory.parseRules(rules, synMap, "=>", ",", true, tf);
            assertEquals(1, synMap.submap.size());
            assertEquals(1, getSubSynonymMap(synMap, "ab").submap.size());
            assertEquals(1, getSubSynonymMap(getSubSynonymMap(synMap, "ab"), "bc").submap.size());
            assertTokIncludes(getSubSynonymMap(getSubSynonymMap(synMap, "ab"), "bc"), "cd", "ef");
            assertTokIncludes(getSubSynonymMap(getSubSynonymMap(synMap, "ab"), "bc"), "cd", "fg");
            assertTokIncludes(getSubSynonymMap(getSubSynonymMap(synMap, "ab"), "bc"), "cd", "gh");
        }
예제 #8
0
        public virtual void testMultiWordSynonymsOld()
        {
            IList<string> rules = new List<string>();
            rules.Add("a b c,d");
            SlowSynonymMap synMap = new SlowSynonymMap(true);
            SlowSynonymFilterFactory.parseRules(rules, synMap, "=>", ",", true, null);

            SlowSynonymFilter ts = new SlowSynonymFilter(new MockTokenizer(new StringReader("a e"), MockTokenizer.WHITESPACE, false), synMap);
            // This fails because ["e","e"] is the value of the token stream
            assertTokenStreamContents(ts, new string[] {"a", "e"});
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: static void parseRules(Iterable<String> rules, SlowSynonymMap map, String mappingSep, String synSep, boolean expansion, TokenizerFactory tokFactory) throws java.io.IOException
        internal static void parseRules(IEnumerable <string> rules, SlowSynonymMap map, string mappingSep, string synSep, bool expansion, TokenizerFactory tokFactory)
        {
            int count = 0;

            foreach (string rule in rules)
            {
                // To use regexes, we need an expression that specifies an odd number of chars.
                // This can't really be done with string.split(), and since we need to
                // do unescaping at some point anyway, we wouldn't be saving any effort
                // by using regexes.

                IList <string> mapping = splitSmart(rule, mappingSep, false);

                IList <IList <string> > source;
                IList <IList <string> > target;

                if (mapping.Count > 2)
                {
                    throw new System.ArgumentException("Invalid Synonym Rule:" + rule);
                }
                else if (mapping.Count == 2)
                {
                    source = getSynList(mapping[0], synSep, tokFactory);
                    target = getSynList(mapping[1], synSep, tokFactory);
                }
                else
                {
                    source = getSynList(mapping[0], synSep, tokFactory);
                    if (expansion)
                    {
                        // expand to all arguments
                        target = source;
                    }
                    else
                    {
                        // reduce to first argument
                        target = new List <>(1);
                        target.Add(source[0]);
                    }
                }

                bool includeOrig = false;
                foreach (IList <string> fromToks in source)
                {
                    count++;
                    foreach (IList <string> toToks in target)
                    {
                        map.add(fromToks, SlowSynonymMap.makeTokens(toToks), includeOrig, true);
                    }
                }
            }
        }
예제 #10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testRead1waySynonymRules() throws Exception
        public virtual void testRead1waySynonymRules()
        {
            SlowSynonymMap synMap;

            // (a)->[a]
            // (b)->[a]
            IList <string> rules = new List <string>();

            rules.Add("a,b");
            synMap = new SlowSynonymMap(true);
            SlowSynonymFilterFactory.parseRules(rules, synMap, "=>", ",", false, null);
            assertEquals(2, synMap.submap.size());
            assertTokIncludes(synMap, "a", "a");
            assertTokIncludes(synMap, "b", "a");

            // (a)->[a]
            // (b)->[a]
            // (c)->[a]
            rules.Clear();
            rules.Add("a,b,c");
            synMap = new SlowSynonymMap(true);
            SlowSynonymFilterFactory.parseRules(rules, synMap, "=>", ",", false, null);
            assertEquals(3, synMap.submap.size());
            assertTokIncludes(synMap, "a", "a");
            assertTokIncludes(synMap, "b", "a");
            assertTokIncludes(synMap, "c", "a");

            // (a)->[a]
            // (b1)->(b2)->[a]
            rules.Clear();
            rules.Add("a,b1 b2");
            synMap = new SlowSynonymMap(true);
            SlowSynonymFilterFactory.parseRules(rules, synMap, "=>", ",", false, null);
            assertEquals(2, synMap.submap.size());
            assertTokIncludes(synMap, "a", "a");
            assertEquals(1, getSubSynonymMap(synMap, "b1").submap.size());
            assertTokIncludes(getSubSynonymMap(synMap, "b1"), "b2", "a");

            // (a1)->(a2)->[a1][a2]
            // (b)->[a1][a2]
            rules.Clear();
            rules.Add("a1 a2,b");
            synMap = new SlowSynonymMap(true);
            SlowSynonymFilterFactory.parseRules(rules, synMap, "=>", ",", false, null);
            assertEquals(2, synMap.submap.size());
            assertEquals(1, getSubSynonymMap(synMap, "a1").submap.size());
            assertTokIncludes(getSubSynonymMap(synMap, "a1"), "a2", "a1");
            assertTokIncludes(getSubSynonymMap(synMap, "a1"), "a2", "a2");
            assertTokIncludes(synMap, "b", "a1");
            assertTokIncludes(synMap, "b", "a2");
        }
예제 #11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void inform(ResourceLoader loader) throws java.io.IOException
        public void inform(ResourceLoader loader)
        {
            TokenizerFactory tokFactory = null;

            if (tf != null)
            {
                tokFactory = loadTokenizerFactory(loader, tf);
            }

            IEnumerable <string> wlist = loadRules(synonyms, loader);

            synMap = new SlowSynonymMap(ignoreCase);
            parseRules(wlist, synMap, "=>", ",", expand, tokFactory);
        }
예제 #12
0
        public virtual void testMultiWordSynonymsOld()
        {
            IList <string> rules = new List <string>();

            rules.Add("a b c,d");
            SlowSynonymMap synMap = new SlowSynonymMap(true);

            SlowSynonymFilterFactory.parseRules(rules, synMap, "=>", ",", true, null);

            SlowSynonymFilter ts = new SlowSynonymFilter(new MockTokenizer(new StringReader("a e"), MockTokenizer.WHITESPACE, false), synMap);

            // This fails because ["e","e"] is the value of the token stream
            assertTokenStreamContents(ts, new string[] { "a", "e" });
        }
예제 #13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testInvalidMappingRules() throws Exception
        public virtual void testInvalidMappingRules()
        {
            SlowSynonymMap synMap = new SlowSynonymMap(true);
            IList <string> rules  = new List <string>(1);

            rules.Add("a=>b=>c");
            try
            {
                SlowSynonymFilterFactory.parseRules(rules, synMap, "=>", ",", true, null);
                fail("IllegalArgumentException must be thrown.");
            }
            catch (System.ArgumentException)
            {
            }
        }
예제 #14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testLoadRules() throws Exception
        public virtual void testLoadRules()
        {
            IDictionary <string, string> args = new Dictionary <string, string>();

            args["synonyms"] = "something.txt";
            SlowSynonymFilterFactory ff = new SlowSynonymFilterFactory(args);

            ff.inform(new ResourceLoaderAnonymousInnerClassHelper(this));

            SlowSynonymMap synMap = ff.SynonymMap;

            assertEquals(2, synMap.submap.size());
            assertTokIncludes(synMap, "a", "a");
            assertTokIncludes(synMap, "a", "b");
            assertTokIncludes(synMap, "b", "a");
            assertTokIncludes(synMap, "b", "b");
        }
예제 #15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testOffsetBug() throws java.io.IOException
        public virtual void testOffsetBug()
        {
            // With the following rules:
            // a a=>b
            // x=>y
            // analysing "a x" causes "y" to have a bad offset (end less than start)
            // SOLR-167
            SlowSynonymMap map = new SlowSynonymMap();

            bool orig  = false;
            bool merge = true;

            map.add(strings("a a"), tokens("b"), orig, merge);
            map.add(strings("x"), tokens("y"), orig, merge);

            // "a a x" => "b y"
            assertTokenizesTo(map, tokens("a,1,0,1 a,1,2,3 x,1,4,5"), new string[] { "b", "y" }, new int[] { 0, 4 }, new int[] { 3, 5 }, new int[] { 1, 1 });
        }
예제 #16
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testOverlap() throws java.io.IOException
        public virtual void testOverlap()
        {
            SlowSynonymMap map = new SlowSynonymMap();

            bool orig  = false;
            bool merge = true;

            map.add(strings("qwe"), tokens("qq/ww/ee"), orig, merge);
            map.add(strings("qwe"), tokens("xx"), orig, merge);
            map.add(strings("qwe"), tokens("yy"), orig, merge);
            map.add(strings("qwe"), tokens("zz"), orig, merge);
            assertTokenizesTo(map, "$", new string[] { "$" });
            assertTokenizesTo(map, "qwe", new string[] { "qq", "ww", "ee", "xx", "yy", "zz" }, new int[] { 1, 0, 0, 0, 0, 0 });

            // test merging within the map

            map.add(strings("a"), tokens("a5,5 a8,3 a10,2"), orig, merge);
            map.add(strings("a"), tokens("a3,3 a7,4 a9,2 a11,2 a111,100"), orig, merge);
            assertTokenizesTo(map, "a", new string[] { "a3", "a5", "a7", "a8", "a9", "a10", "a11", "a111" }, new int[] { 1, 2, 2, 1, 1, 1, 1, 100 });
        }
예제 #17
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testPositionIncrementsWithOrig() throws java.io.IOException
        public virtual void testPositionIncrementsWithOrig()
        {
            SlowSynonymMap map = new SlowSynonymMap();

            bool orig  = true;
            bool merge = true;

            // test that generated tokens start at the same offset as the original
            map.add(strings("a"), tokens("aa"), orig, merge);
            assertTokenizesTo(map, tokens("a,5"), new string[] { "a", "aa" }, new int[] { 5, 0 });
            assertTokenizesTo(map, tokens("b,1 a,0"), new string[] { "b", "a", "aa" }, new int[] { 1, 0, 0 });

            // test that offset of first replacement is ignored (always takes the orig offset)
            map.add(strings("b"), tokens("bb,100"), orig, merge);
            assertTokenizesTo(map, tokens("b,5"), new string[] { "b", "bb" }, new int[] { 5, 0 });
            assertTokenizesTo(map, tokens("c,1 b,0"), new string[] { "c", "b", "bb" }, new int[] { 1, 0, 0 });

            // test that subsequent tokens are adjusted accordingly
            map.add(strings("c"), tokens("cc,100 c2,2"), orig, merge);
            assertTokenizesTo(map, tokens("c,5"), new string[] { "c", "cc", "c2" }, new int[] { 5, 0, 2 });
            assertTokenizesTo(map, tokens("d,1 c,0"), new string[] { "d", "c", "cc", "c2" }, new int[] { 1, 0, 0, 2 });
        }
예제 #18
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testMatching() throws java.io.IOException
        public virtual void testMatching()
        {
            SlowSynonymMap map = new SlowSynonymMap();

            bool orig  = false;
            bool merge = true;

            map.add(strings("a b"), tokens("ab"), orig, merge);
            map.add(strings("a c"), tokens("ac"), orig, merge);
            map.add(strings("a"), tokens("aa"), orig, merge);
            map.add(strings("b"), tokens("bb"), orig, merge);
            map.add(strings("z x c v"), tokens("zxcv"), orig, merge);
            map.add(strings("x c"), tokens("xc"), orig, merge);

            assertTokenizesTo(map, "$", new string[] { "$" });
            assertTokenizesTo(map, "a", new string[] { "aa" });
            assertTokenizesTo(map, "a $", new string[] { "aa", "$" });
            assertTokenizesTo(map, "$ a", new string[] { "$", "aa" });
            assertTokenizesTo(map, "a a", new string[] { "aa", "aa" });
            assertTokenizesTo(map, "b", new string[] { "bb" });
            assertTokenizesTo(map, "z x c v", new string[] { "zxcv" });
            assertTokenizesTo(map, "z x c $", new string[] { "z", "xc", "$" });

            // repeats
            map.add(strings("a b"), tokens("ab"), orig, merge);
            map.add(strings("a b"), tokens("ab"), orig, merge);

            // FIXME: the below test intended to be { "ab" }
            assertTokenizesTo(map, "a b", new string[] { "ab", "ab", "ab" });

            // check for lack of recursion
            map.add(strings("zoo"), tokens("zoo"), orig, merge);
            assertTokenizesTo(map, "zoo zoo $ zoo", new string[] { "zoo", "zoo", "$", "zoo" });
            map.add(strings("zoo"), tokens("zoo zoo"), orig, merge);
            // FIXME: the below test intended to be { "zoo", "zoo", "zoo", "zoo", "$", "zoo", "zoo" }
            // maybe this was just a typo in the old test????
            assertTokenizesTo(map, "zoo zoo $ zoo", new string[] { "zoo", "zoo", "zoo", "zoo", "zoo", "zoo", "$", "zoo", "zoo", "zoo" });
        }
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: static void assertTokenizesTo(SlowSynonymMap dict, java.util.List<org.apache.lucene.analysis.Token> input, String expected[], int startOffsets[], int endOffsets[], int posIncs[]) throws java.io.IOException
 internal static void assertTokenizesTo(SlowSynonymMap dict, IList<Token> input, string[] expected, int[] startOffsets, int[] endOffsets, int[] posIncs)
 {
     TokenStream tokenizer = new IterTokenStream(input);
     SlowSynonymFilter stream = new SlowSynonymFilter(tokenizer, dict);
     assertTokenStreamContents(stream, expected, startOffsets, endOffsets, posIncs);
 }
예제 #20
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testReadMappingRules() throws Exception
        public virtual void testReadMappingRules()
        {
            SlowSynonymMap synMap;

            // (a)->[b]
            IList <string> rules = new List <string>();

            rules.Add("a=>b");
            synMap = new SlowSynonymMap(true);
            SlowSynonymFilterFactory.parseRules(rules, synMap, "=>", ",", true, null);
            assertEquals(1, synMap.submap.size());
            assertTokIncludes(synMap, "a", "b");

            // (a)->[c]
            // (b)->[c]
            rules.Clear();
            rules.Add("a,b=>c");
            synMap = new SlowSynonymMap(true);
            SlowSynonymFilterFactory.parseRules(rules, synMap, "=>", ",", true, null);
            assertEquals(2, synMap.submap.size());
            assertTokIncludes(synMap, "a", "c");
            assertTokIncludes(synMap, "b", "c");

            // (a)->[b][c]
            rules.Clear();
            rules.Add("a=>b,c");
            synMap = new SlowSynonymMap(true);
            SlowSynonymFilterFactory.parseRules(rules, synMap, "=>", ",", true, null);
            assertEquals(1, synMap.submap.size());
            assertTokIncludes(synMap, "a", "b");
            assertTokIncludes(synMap, "a", "c");

            // (a)->(b)->[a2]
            //      [a1]
            rules.Clear();
            rules.Add("a=>a1");
            rules.Add("a b=>a2");
            synMap = new SlowSynonymMap(true);
            SlowSynonymFilterFactory.parseRules(rules, synMap, "=>", ",", true, null);
            assertEquals(1, synMap.submap.size());
            assertTokIncludes(synMap, "a", "a1");
            assertEquals(1, getSubSynonymMap(synMap, "a").submap.size());
            assertTokIncludes(getSubSynonymMap(synMap, "a"), "b", "a2");

            // (a)->(b)->[a2]
            //      (c)->[a3]
            //      [a1]
            rules.Clear();
            rules.Add("a=>a1");
            rules.Add("a b=>a2");
            rules.Add("a c=>a3");
            synMap = new SlowSynonymMap(true);
            SlowSynonymFilterFactory.parseRules(rules, synMap, "=>", ",", true, null);
            assertEquals(1, synMap.submap.size());
            assertTokIncludes(synMap, "a", "a1");
            assertEquals(2, getSubSynonymMap(synMap, "a").submap.size());
            assertTokIncludes(getSubSynonymMap(synMap, "a"), "b", "a2");
            assertTokIncludes(getSubSynonymMap(synMap, "a"), "c", "a3");

            // (a)->(b)->[a2]
            //      [a1]
            // (b)->(c)->[b2]
            //      [b1]
            rules.Clear();
            rules.Add("a=>a1");
            rules.Add("a b=>a2");
            rules.Add("b=>b1");
            rules.Add("b c=>b2");
            synMap = new SlowSynonymMap(true);
            SlowSynonymFilterFactory.parseRules(rules, synMap, "=>", ",", true, null);
            assertEquals(2, synMap.submap.size());
            assertTokIncludes(synMap, "a", "a1");
            assertEquals(1, getSubSynonymMap(synMap, "a").submap.size());
            assertTokIncludes(getSubSynonymMap(synMap, "a"), "b", "a2");
            assertTokIncludes(synMap, "b", "b1");
            assertEquals(1, getSubSynonymMap(synMap, "b").submap.size());
            assertTokIncludes(getSubSynonymMap(synMap, "b"), "c", "b2");
        }
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public void testOffsetBug() throws java.io.IOException
        public virtual void testOffsetBug()
        {
            // With the following rules:
            // a a=>b
            // x=>y
            // analysing "a x" causes "y" to have a bad offset (end less than start)
            // SOLR-167
            SlowSynonymMap map = new SlowSynonymMap();

            bool orig = false;
            bool merge = true;

            map.add(strings("a a"), tokens("b"), orig, merge);
            map.add(strings("x"), tokens("y"), orig, merge);

            // "a a x" => "b y"
            assertTokenizesTo(map, tokens("a,1,0,1 a,1,2,3 x,1,4,5"), new string[] {"b", "y"}, new int[] {0, 4}, new int[] {3, 5}, new int[] {1, 1});
        }
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public void testMatching() throws java.io.IOException
        public virtual void testMatching()
        {
            SlowSynonymMap map = new SlowSynonymMap();

            bool orig = false;
            bool merge = true;
            map.add(strings("a b"), tokens("ab"), orig, merge);
            map.add(strings("a c"), tokens("ac"), orig, merge);
            map.add(strings("a"), tokens("aa"), orig, merge);
            map.add(strings("b"), tokens("bb"), orig, merge);
            map.add(strings("z x c v"), tokens("zxcv"), orig, merge);
            map.add(strings("x c"), tokens("xc"), orig, merge);

            assertTokenizesTo(map, "$", new string[] {"$"});
            assertTokenizesTo(map, "a", new string[] {"aa"});
            assertTokenizesTo(map, "a $", new string[] {"aa", "$"});
            assertTokenizesTo(map, "$ a", new string[] {"$", "aa"});
            assertTokenizesTo(map, "a a", new string[] {"aa", "aa"});
            assertTokenizesTo(map, "b", new string[] {"bb"});
            assertTokenizesTo(map, "z x c v", new string[] {"zxcv"});
            assertTokenizesTo(map, "z x c $", new string[] {"z", "xc", "$"});

            // repeats
            map.add(strings("a b"), tokens("ab"), orig, merge);
            map.add(strings("a b"), tokens("ab"), orig, merge);

            // FIXME: the below test intended to be { "ab" }
            assertTokenizesTo(map, "a b", new string[] {"ab", "ab", "ab"});

            // check for lack of recursion
            map.add(strings("zoo"), tokens("zoo"), orig, merge);
            assertTokenizesTo(map, "zoo zoo $ zoo", new string[] {"zoo", "zoo", "$", "zoo"});
            map.add(strings("zoo"), tokens("zoo zoo"), orig, merge);
            // FIXME: the below test intended to be { "zoo", "zoo", "zoo", "zoo", "$", "zoo", "zoo" }
            // maybe this was just a typo in the old test????
            assertTokenizesTo(map, "zoo zoo $ zoo", new string[] {"zoo", "zoo", "zoo", "zoo", "zoo", "zoo", "$", "zoo", "zoo", "zoo"});
        }
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public void testOverlap() throws java.io.IOException
        public virtual void testOverlap()
        {
            SlowSynonymMap map = new SlowSynonymMap();

            bool orig = false;
            bool merge = true;
            map.add(strings("qwe"), tokens("qq/ww/ee"), orig, merge);
            map.add(strings("qwe"), tokens("xx"), orig, merge);
            map.add(strings("qwe"), tokens("yy"), orig, merge);
            map.add(strings("qwe"), tokens("zz"), orig, merge);
            assertTokenizesTo(map, "$", new string[] {"$"});
            assertTokenizesTo(map, "qwe", new string[] {"qq", "ww", "ee", "xx", "yy", "zz"}, new int[] {1, 0, 0, 0, 0, 0});

            // test merging within the map

            map.add(strings("a"), tokens("a5,5 a8,3 a10,2"), orig, merge);
            map.add(strings("a"), tokens("a3,3 a7,4 a9,2 a11,2 a111,100"), orig, merge);
            assertTokenizesTo(map, "a", new string[] {"a3", "a5", "a7", "a8", "a9", "a10", "a11", "a111"}, new int[] {1, 2, 2, 1, 1, 1, 1, 100});
        }
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public void testPositionIncrementsWithOrig() throws java.io.IOException
        public virtual void testPositionIncrementsWithOrig()
        {
            SlowSynonymMap map = new SlowSynonymMap();

            bool orig = true;
            bool merge = true;

            // test that generated tokens start at the same offset as the original
            map.add(strings("a"), tokens("aa"), orig, merge);
            assertTokenizesTo(map, tokens("a,5"), new string[] {"a", "aa"}, new int[] {5, 0});
            assertTokenizesTo(map, tokens("b,1 a,0"), new string[] {"b", "a", "aa"}, new int[] {1, 0, 0});

            // test that offset of first replacement is ignored (always takes the orig offset)
            map.add(strings("b"), tokens("bb,100"), orig, merge);
            assertTokenizesTo(map, tokens("b,5"), new string[] {"b", "bb"}, new int[] {5, 0});
            assertTokenizesTo(map, tokens("c,1 b,0"), new string[] {"c", "b", "bb"}, new int[] {1, 0, 0});

            // test that subsequent tokens are adjusted accordingly
            map.add(strings("c"), tokens("cc,100 c2,2"), orig, merge);
            assertTokenizesTo(map, tokens("c,5"), new string[] {"c", "cc", "c2"}, new int[] {5, 0, 2});
            assertTokenizesTo(map, tokens("d,1 c,0"), new string[] {"d", "c", "cc", "c2"}, new int[] {1, 0, 0, 2});
        }
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: static void assertTokenizesTo(SlowSynonymMap dict, String input, String expected[], int posIncs[]) throws java.io.IOException
 internal static void assertTokenizesTo(SlowSynonymMap dict, string input, string[] expected, int[] posIncs)
 {
     Tokenizer tokenizer = new MockTokenizer(new StringReader(input), MockTokenizer.WHITESPACE, false);
     SlowSynonymFilter stream = new SlowSynonymFilter(tokenizer, dict);
     assertTokenStreamContents(stream, expected, posIncs);
 }