Esempio n. 1
0
        /// <summary>
        /// tries to initialize a factory with no arguments </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private org.apache.lucene.analysis.util.AbstractAnalysisFactory initialize(Class<? extends org.apache.lucene.analysis.util.AbstractAnalysisFactory> factoryClazz) throws java.io.IOException
        private AbstractAnalysisFactory initialize <T1>(Type <T1> factoryClazz) where T1 : org.apache.lucene.analysis.util.AbstractAnalysisFactory
        {
            IDictionary <string, string> args = new Dictionary <string, string>();

            args["luceneMatchVersion"] = TEST_VERSION_CURRENT.ToString();
//JAVA TO C# CONVERTER TODO TASK: Java wildcard generics are not converted to .NET:
//ORIGINAL LINE: Constructor<? extends org.apache.lucene.analysis.util.AbstractAnalysisFactory> ctor;
            Constructor <?> ctor;

            try
            {
                ctor = factoryClazz.GetConstructor(typeof(IDictionary));
            }
            catch (Exception)
            {
                throw new Exception("factory '" + factoryClazz + "' does not have a proper ctor!");
            }

            AbstractAnalysisFactory factory = null;

            try
            {
                factory = ctor.newInstance(args);
            }
            catch (InstantiationException e)
            {
                throw new Exception(e);
            }
            catch (IllegalAccessException e)
            {
                throw new Exception(e);
            }
            catch (InvocationTargetException e)
            {
                if (e.InnerException is System.ArgumentException)
                {
                    // its ok if we dont provide the right parameters to throw this
                    return(null);
                }
            }

            if (factory is ResourceLoaderAware)
            {
                try
                {
                    ((ResourceLoaderAware)factory).inform(new StringMockResourceLoader(""));
                }
                catch (IOException)
                {
                    // its ok if the right files arent available or whatever to throw this
                }
                catch (System.ArgumentException)
                {
                    // is this ok? I guess so
                }
            }
            return(factory);
        }
Esempio n. 2
0
        /// <summary>
        /// tries to initialize a factory with no arguments </summary>
        private AbstractAnalysisFactory Initialize(Type factoryClazz)
        {
            IDictionary <string, string> args = new Dictionary <string, string>();

            args["luceneMatchVersion"] = TEST_VERSION_CURRENT.ToString();

            ConstructorInfo ctor;

            try
            {
                ctor = factoryClazz.GetConstructor(new Type[] { typeof(IDictionary <string, string>) });
            }
            catch (Exception)
            {
                throw new Exception("factory '" + factoryClazz + "' does not have a proper ctor!");
            }

            AbstractAnalysisFactory factory = null;

            try
            {
                factory = (AbstractAnalysisFactory)ctor.Invoke(new object[] { args });
            }
            catch (TypeInitializationException e)
            {
                throw new Exception(e.Message, e);
            }
            catch (MethodAccessException e)
            {
                throw new Exception(e.Message, e);
            }
            catch (TargetInvocationException e)
            {
                if (e.InnerException is System.ArgumentException)
                {
                    // its ok if we dont provide the right parameters to throw this
                    return(null);
                }
            }

            if (factory is IResourceLoaderAware)
            {
                try
                {
                    ((IResourceLoaderAware)factory).Inform(new StringMockResourceLoader(""));
                }
                catch (IOException)
                {
                    // its ok if the right files arent available or whatever to throw this
                }
                catch (System.ArgumentException)
                {
                    // is this ok? I guess so
                }
            }
            return(factory);
        }
Esempio n. 3
0
        private PerfRunData createPerfRunData()
        {
            Dictionary <string, string> props = new Dictionary <string, string>();

            props["writer.version"] = TEST_VERSION_CURRENT.ToString();
            props["print.props"]    = "false"; // don't print anything
            props["directory"]      = "RAMDirectory";
            Config config = new Config(props);

            return(new PerfRunData(config));
        }
Esempio n. 4
0
        private PerfRunData createPerfRunData()
        {
            IDictionary <string, string> props = new Dictionary <string, string>();

            props["writer.version"] = TEST_VERSION_CURRENT.ToString();
            props["print.props"]    = "false"; // don't print anything
            props["directory"]      = "RAMDirectory";
            props[AddIndexesTask.ADDINDEXES_INPUT_DIR] = inputDir.FullName;
            Config config = new Config(props);

            return(new PerfRunData(config));
        }
Esempio n. 5
0
 public void TestBogusArguments()
 {
     try
     {
         new JapanesePartOfSpeechStopFilterFactory(new Dictionary <String, String>()
         {
             { "luceneMatchVersion", TEST_VERSION_CURRENT.toString() },
             { "bogusArg", "bogusValue" }
         });
         fail();
     }
     catch (ArgumentException expected)
     {
         assertTrue(expected.Message.Contains("Unknown parameters"));
     }
 }
Esempio n. 6
0
        private TokenFilterFactory tokenFilterFactory(String name, params String[] keysAndValues)
        {
            Type clazz = TokenFilterFactory.LookupClass(name);

            if (keysAndValues.Length % 2 == 1)
            {
                throw new ArgumentException("invalid keysAndValues map");
            }
            IDictionary <String, String> args = new Dictionary <String, String>();

            for (int i = 0; i < keysAndValues.Length; i += 2)
            {
                String prev = args.Put(keysAndValues[i], keysAndValues[i + 1]);
                assertNull("duplicate values for key: " + keysAndValues[i], prev);
            }
            String previous = args.Put("luceneMatchVersion", TEST_VERSION_CURRENT.toString());

            assertNull("duplicate values for key: luceneMatchVersion", previous);
            TokenFilterFactory factory = null;

            try
            {
                //factory = clazz.getConstructor(Map.class).newInstance(args);
                factory = (TokenFilterFactory)Activator.CreateInstance(clazz, args);
            }
            catch (TargetInvocationException e)
            {
                // to simplify tests that check for illegal parameters
                if (e.InnerException is ArgumentException)
                {
                    throw (ArgumentException)e.InnerException;
                }
                else
                {
                    throw e;
                }
            }
            if (factory is IResourceLoaderAware)
            {
                ((IResourceLoaderAware)factory).Inform(new ClasspathResourceLoader(GetType()));
            }
            return(factory);
        }
Esempio n. 7
0
        public void TestBasics()
        {
            String tags =
                "#  verb-main:\n" +
                "動詞-自立\n";

            JapaneseTokenizerFactory tokenizerFactory = new JapaneseTokenizerFactory(new Dictionary <String, String>());

            tokenizerFactory.Inform(new StringMockResourceLoader(""));
            TokenStream ts = tokenizerFactory.Create(new StringReader("私は制限スピードを超える。"));
            IDictionary <String, String> args = new Dictionary <String, String>();

            args.Put("luceneMatchVersion", TEST_VERSION_CURRENT.toString());
            args.Put("tags", "stoptags.txt");
            JapanesePartOfSpeechStopFilterFactory factory = new JapanesePartOfSpeechStopFilterFactory(args);

            factory.Inform(new StringMockResourceLoader(tags));
            ts = factory.Create(ts);
            AssertTokenStreamContents(ts,
                                      new String[] { "私", "は", "制限", "スピード", "を" }
                                      );
        }
Esempio n. 8
0
 public HashMapAnonymousClass()
 {
     this["luceneMatchVersion"] = TEST_VERSION_CURRENT.ToString();
 }
Esempio n. 9
0
        public virtual void Test()
        {
            IList <Type> analysisClasses = typeof(StandardAnalyzer).Assembly.GetTypes()
                                           .Where(c =>
            {
                var typeInfo = c;

                return(!typeInfo.IsAbstract && typeInfo.IsPublic && !typeInfo.IsInterface && typeInfo.IsClass && (typeInfo.GetCustomAttribute <ObsoleteAttribute>() == null) &&
                       !testComponents.Contains(c) && !crazyComponents.Contains(c) && !oddlyNamedComponents.Contains(c) && !deprecatedDuplicatedComponents.Contains(c) &&
                       (typeInfo.IsSubclassOf(typeof(Tokenizer)) || typeInfo.IsSubclassOf(typeof(TokenFilter)) || typeInfo.IsSubclassOf(typeof(CharFilter))));
            })
                                           .ToList();


            foreach (Type c in analysisClasses)
            {
                IDictionary <string, string> args = new Dictionary <string, string>();
                args["luceneMatchVersion"] = TEST_VERSION_CURRENT.ToString();

                if (c.IsSubclassOf(typeof(Tokenizer)))
                {
                    string clazzName = c.Name;
                    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 IResourceLoaderAware resourceLoaderAware)
                        {
                            resourceLoaderAware.Inform(loader);
                        }
                        assertSame(c, instance.Create(new StringReader("")).GetType());
                    }
                    catch (Exception e) when(e.IsIllegalArgumentException())
                    {
                        if (e.InnerException.IsNoSuchMethodException())
                        {
                            // there is no corresponding ctor available
                            throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details)
                        }
                        // 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.Name;
                    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 IResourceLoaderAware resourceLoaderAware)
                        {
                            resourceLoaderAware.Inform(loader);
                        }
                        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 (Exception e) when(e.IsIllegalArgumentException())
                    {
                        if (e.InnerException.IsNoSuchMethodException())
                        {
                            // there is no corresponding ctor available
                            throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details)
                        }
                        // 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.Name;
                    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 IResourceLoaderAware resourceLoaderAware)
                        {
                            resourceLoaderAware.Inform(loader);
                        }
                        Type createdClazz = instance.Create(new StringReader("")).GetType();
                        // only check instance if factory have wrapped at all!
                        if (typeof(StringReader) != createdClazz)
                        {
                            assertSame(c, createdClazz);
                        }
                    }
                    catch (Exception e) when(e.IsIllegalArgumentException())
                    {
                        if (e.InnerException.IsNoSuchMethodException())
                        {
                            // there is no corresponding ctor available
                            throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details)
                        }
                        // TODO: For now pass because some factories have not yet a default config that always works
                    }
                }
            }
        }
Esempio n. 10
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
                    }
                }
            }
        }
        public virtual void Test()
        {
            IList <Type> analysisClasses = new List <Type>(
                typeof(StandardAnalyzer).Assembly.GetTypes()
                .Where(c => !c.IsAbstract && c.IsPublic && !c.IsInterface && c.IsClass && (c.GetCustomAttribute <ObsoleteAttribute>() == null) &&
                       !testComponents.Contains(c) && !crazyComponents.Contains(c) && !oddlyNamedComponents.Contains(c) && !deprecatedDuplicatedComponents.Contains(c) &&
                       (c.IsSubclassOf(typeof(Tokenizer)) || c.IsSubclassOf(typeof(TokenFilter)) || c.IsSubclassOf(typeof(CharFilter)))
                       ));


            foreach (Type c in analysisClasses)
            {
                IDictionary <string, string> args = new Dictionary <string, string>();
                args["luceneMatchVersion"] = TEST_VERSION_CURRENT.ToString();

                if (c.IsSubclassOf(typeof(Tokenizer)))
                {
                    string clazzName = c.Name;
                    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 IResourceLoaderAware)
                        {
                            ((IResourceLoaderAware)instance).Inform(loader);
                        }
                        assertSame(c, instance.Create(new StringReader("")).GetType());
                    }
                    catch (System.ArgumentException e)
                    {
                        if (e.InnerException is MissingMethodException)
                        {
                            // 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.Name;
                    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 IResourceLoaderAware)
                        {
                            ((IResourceLoaderAware)instance).Inform(loader);
                        }
                        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 MissingMethodException)
                        {
                            // 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.Name;
                    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 IResourceLoaderAware)
                        {
                            ((IResourceLoaderAware)instance).Inform(loader);
                        }
                        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 MissingMethodException)
                        {
                            // there is no corresponding ctor available
                            throw e;
                        }
                        // TODO: For now pass because some factories have not yet a default config that always works
                    }
                }
            }
        }
Esempio n. 12
0
            public HashMapAnonymousInnerClassHelper(TestAnalysisSPILoader outerInstance)
            {
                this.outerInstance = outerInstance;

                this["luceneMatchVersion"] = TEST_VERSION_CURRENT.ToString();
            }