Ejemplo n.º 1
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 });
        }
Ejemplo n.º 2
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 });
        }
        //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});
        }
Ejemplo n.º 4
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 });
        }
        //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});
        }
Ejemplo n.º 6
0
//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);
                    }
                }
            }
        }
Ejemplo n.º 7
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 });
        }
Ejemplo n.º 8
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" });
        }
Ejemplo n.º 9
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 });
        }
Ejemplo n.º 10
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"});
        }
Ejemplo n.º 11
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});
        }
Ejemplo n.º 12
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});
        }
Ejemplo n.º 13
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});
        }