Ejemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void doTestTokenFilter(String tokenfilter) throws java.io.IOException
        private void doTestTokenFilter(string tokenfilter)
        {
//JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET:
//ORIGINAL LINE: Class<? extends org.apache.lucene.analysis.util.TokenFilterFactory> factoryClazz = org.apache.lucene.analysis.util.TokenFilterFactory.lookupClass(tokenfilter);
            Type <?>           factoryClazz = TokenFilterFactory.lookupClass(tokenfilter);
            TokenFilterFactory factory      = (TokenFilterFactory)initialize(factoryClazz);

            if (factory != null)
            {
                // we managed to fully create an instance. check a few more things:

                // if it implements MultiTermAware, sanity check its impl
                if (factory is MultiTermAwareComponent)
                {
                    AbstractAnalysisFactory mtc = ((MultiTermAwareComponent)factory).MultiTermComponent;
                    assertNotNull(mtc);
                    // its not ok to return a charfilter or tokenizer here, this makes no sense
                    assertTrue(mtc is TokenFilterFactory);
                }

                // beast it just a little, it shouldnt throw exceptions:
                // (it should have thrown them in initialize)
                checkRandomData(random(), new FactoryAnalyzer(assertingTokenizer, factory, null), 100, 20, false, false);
            }
        }
Ejemplo n.º 2
0
        public virtual void testLookupTokenFilterClass()
        {
            assertSame(typeof(LowerCaseFilterFactory), TokenFilterFactory.lookupClass("Lowercase"));
            assertSame(typeof(LowerCaseFilterFactory), TokenFilterFactory.lookupClass("LOWERCASE"));
            assertSame(typeof(LowerCaseFilterFactory), TokenFilterFactory.lookupClass("lowercase"));

            assertSame(typeof(RemoveDuplicatesTokenFilterFactory), TokenFilterFactory.lookupClass("RemoveDuplicates"));
            assertSame(typeof(RemoveDuplicatesTokenFilterFactory), TokenFilterFactory.lookupClass("REMOVEDUPLICATES"));
            assertSame(typeof(RemoveDuplicatesTokenFilterFactory), TokenFilterFactory.lookupClass("removeduplicates"));
        }
Ejemplo n.º 3
0
        public virtual void testBogusLookupTokenFilterClass()
        {
            try
            {
                TokenFilterFactory.lookupClass("sdfsdfsdfdsfsdfsdf");
                fail();
            }
            catch (System.ArgumentException)
            {
                //
            }

            try
            {
                TokenFilterFactory.lookupClass("!(**#$U*#$*");
                fail();
            }
            catch (System.ArgumentException)
            {
                //
            }
        }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void test() throws Exception
        public virtual void test()
        {
            IList <Type> analysisClasses = new List <Type>();

            ((List <Type>)analysisClasses).AddRange(TestRandomChains.getClassesForPackage("org.apache.lucene.analysis"));
            ((List <Type>)analysisClasses).AddRange(TestRandomChains.getClassesForPackage("org.apache.lucene.collation"));

            foreach (Class c in analysisClasses)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int modifiers = c.getModifiers();
                int modifiers = c.Modifiers;
                if (Modifier.isAbstract(modifiers) || !Modifier.isPublic(modifiers) || c.Synthetic || c.AnonymousClass || c.MemberClass || c.Interface || testComponents.Contains(c) || crazyComponents.Contains(c) || oddlyNamedComponents.Contains(c) || deprecatedDuplicatedComponents.Contains(c) || c.isAnnotationPresent(typeof(Deprecated)) || !(c.IsSubclassOf(typeof(Tokenizer)) || c.IsSubclassOf(typeof(TokenFilter)) || c.IsSubclassOf(typeof(CharFilter))))
                {   // deprecated ones are typically back compat hacks
                    // don't waste time with abstract classes
                    continue;
                }

                IDictionary <string, string> args = new Dictionary <string, string>();
                args["luceneMatchVersion"] = TEST_VERSION_CURRENT.ToString();

                if (c.IsSubclassOf(typeof(Tokenizer)))
                {
                    string clazzName = c.SimpleName;
                    assertTrue(clazzName.EndsWith("Tokenizer", StringComparison.Ordinal));
                    string simpleName = clazzName.Substring(0, clazzName.Length - 9);
                    assertNotNull(TokenizerFactory.lookupClass(simpleName));
                    TokenizerFactory instance = null;
                    try
                    {
                        instance = TokenizerFactory.forName(simpleName, args);
                        assertNotNull(instance);
                        if (instance is ResourceLoaderAware)
                        {
                            ((ResourceLoaderAware)instance).inform(loader);
                        }
                        assertSame(c, instance.create(new StringReader("")).GetType());
                    }
                    catch (System.ArgumentException e)
                    {
                        if (e.InnerException is NoSuchMethodException)
                        {
                            // there is no corresponding ctor available
                            throw e;
                        }
                        // TODO: For now pass because some factories have not yet a default config that always works
                    }
                }
                else if (c.IsSubclassOf(typeof(TokenFilter)))
                {
                    string clazzName = c.SimpleName;
                    assertTrue(clazzName.EndsWith("Filter", StringComparison.Ordinal));
                    string simpleName = clazzName.Substring(0, clazzName.Length - (clazzName.EndsWith("TokenFilter", StringComparison.Ordinal) ? 11 : 6));
                    assertNotNull(TokenFilterFactory.lookupClass(simpleName));
                    TokenFilterFactory instance = null;
                    try
                    {
                        instance = TokenFilterFactory.forName(simpleName, args);
                        assertNotNull(instance);
                        if (instance is ResourceLoaderAware)
                        {
                            ((ResourceLoaderAware)instance).inform(loader);
                        }
//JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET:
//ORIGINAL LINE: Class<? extends org.apache.lucene.analysis.TokenStream> createdClazz = instance.create(new KeywordTokenizer(new java.io.StringReader(""))).getClass();
                        Type <?> createdClazz = instance.create(new KeywordTokenizer(new StringReader(""))).GetType();
                        // only check instance if factory have wrapped at all!
                        if (typeof(KeywordTokenizer) != createdClazz)
                        {
                            assertSame(c, createdClazz);
                        }
                    }
                    catch (System.ArgumentException e)
                    {
                        if (e.InnerException is NoSuchMethodException)
                        {
                            // there is no corresponding ctor available
                            throw e;
                        }
                        // TODO: For now pass because some factories have not yet a default config that always works
                    }
                }
                else if (c.IsSubclassOf(typeof(CharFilter)))
                {
                    string clazzName = c.SimpleName;
                    assertTrue(clazzName.EndsWith("CharFilter", StringComparison.Ordinal));
                    string simpleName = clazzName.Substring(0, clazzName.Length - 10);
                    assertNotNull(CharFilterFactory.lookupClass(simpleName));
                    CharFilterFactory instance = null;
                    try
                    {
                        instance = CharFilterFactory.forName(simpleName, args);
                        assertNotNull(instance);
                        if (instance is ResourceLoaderAware)
                        {
                            ((ResourceLoaderAware)instance).inform(loader);
                        }
//JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET:
//ORIGINAL LINE: Class<? extends java.io.Reader> createdClazz = instance.create(new java.io.StringReader("")).getClass();
                        Type <?> createdClazz = instance.create(new StringReader("")).GetType();
                        // only check instance if factory have wrapped at all!
                        if (typeof(StringReader) != createdClazz)
                        {
                            assertSame(c, createdClazz);
                        }
                    }
                    catch (System.ArgumentException e)
                    {
                        if (e.InnerException is NoSuchMethodException)
                        {
                            // there is no corresponding ctor available
                            throw e;
                        }
                        // TODO: For now pass because some factories have not yet a default config that always works
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns a fully initialized TokenFilterFactory with the specified name, version, resource loader,
        /// and key-value arguments.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected TokenFilterFactory tokenFilterFactory(String name, org.apache.lucene.util.Version matchVersion, ResourceLoader loader, String... keysAndValues) throws Exception
        protected internal virtual TokenFilterFactory tokenFilterFactory(string name, Version matchVersion, ResourceLoader loader, params string[] keysAndValues)
        {
            return((TokenFilterFactory)analysisFactory(TokenFilterFactory.lookupClass(name), matchVersion, loader, keysAndValues));
        }