当前位置: 首页>>代码示例>>C#>>正文


C# IResourceLoader.OpenResource方法代码示例

本文整理汇总了C#中IResourceLoader.OpenResource方法的典型用法代码示例。如果您正苦于以下问题:C# IResourceLoader.OpenResource方法的具体用法?C# IResourceLoader.OpenResource怎么用?C# IResourceLoader.OpenResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IResourceLoader的用法示例。


在下文中一共展示了IResourceLoader.OpenResource方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: assertClasspathDelegation

 private void assertClasspathDelegation(IResourceLoader rl)
 {
     // try a stopwords file from classpath
     CharArraySet set = WordlistLoader.GetSnowballWordSet(new System.IO.StreamReader(rl.OpenResource(System.IO.Path.GetFullPath(@"..\..\..\Lucene.Net.Analysis.Common\Analysis\Snowball\english_stop.txt")), Encoding.UTF8), TEST_VERSION_CURRENT);
     assertTrue(set.contains("you"));
     // try to load a class; we use string comparison because classloader may be different...
     assertEquals("Lucene.Net.Analysis.Util.RollingCharBuffer", rl.NewInstance<object>("Lucene.Net.Analysis.Util.RollingCharBuffer").ToString());
     // theoretically classes should also be loadable:
     //IOUtils.CloseWhileHandlingException(rl.OpenResource("java/lang/String.class")); // LUCENENET TODO: Not sure what the equivalent to this is (or if there is one).
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:10,代码来源:TestFilesystemResourceLoader.cs

示例2: assertNotFound

 private void assertNotFound(IResourceLoader rl)
 {
     try
     {
         IOUtils.CloseWhileHandlingException(rl.OpenResource("/this-directory-really-really-really-should-not-exist/foo/bar.txt"));
         fail("The resource does not exist, should fail!");
     }
     catch (IOException)
     {
         // pass
     }
     try
     {
         rl.NewInstance<TokenFilterFactory>("org.apache.lucene.analysis.FooBarFilterFactory");
         fail("The class does not exist, should fail!");
     }
     catch (Exception)
     {
         // pass
     }
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:21,代码来源:TestFilesystemResourceLoader.cs

示例3: GetSnowballWordSet

 /// <summary>
 /// same as <seealso cref="#getWordSet(ResourceLoader, String, boolean)"/>,
 /// except the input is in snowball format. 
 /// </summary>
 protected internal CharArraySet GetSnowballWordSet(IResourceLoader loader, string wordFiles, bool ignoreCase)
 {
     AssureMatchVersion();
     IEnumerable<string> files = SplitFileNames(wordFiles);
     CharArraySet words = null;
     if (files.Count() > 0)
     {
         // default stopwords list has 35 or so words, but maybe don't make it that
         // big to start
         words = new CharArraySet(luceneMatchVersion, files.Count() * 10, ignoreCase);
         foreach (string file in files)
         {
             using (Stream stream = loader.OpenResource(file.Trim()))
             {
                 using (TextReader reader = new StreamReader(stream, Encoding.UTF8))
                 {
                     WordlistLoader.GetSnowballWordSet(reader, words);
                 }
             }
         }
     }
     return words;
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:27,代码来源:AbstractAnalysisFactory.cs

示例4: GetLines

 /// <summary>
 /// Returns the resource's lines (with content treated as UTF-8)
 /// </summary>
 protected internal IEnumerable<string> GetLines(IResourceLoader loader, string resource)
 {
     return WordlistLoader.GetLines(loader.OpenResource(resource), Encoding.UTF8);
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:7,代码来源:AbstractAnalysisFactory.cs

示例5: LoadSynonyms

        /// <summary>
        /// Load synonyms with the given <seealso cref="SynonymMap.Parser"/> class.
        /// </summary>
        private SynonymMap LoadSynonyms(IResourceLoader loader, string cname, bool dedup, Analyzer analyzer)
        {
            Encoding decoder = Encoding.UTF8;

            SynonymMap.Parser parser;
            Type clazz = loader.FindClass(cname /*, typeof(SynonymMap.Parser) */);
            try
            {
                parser = (SynonymMap.Parser)Activator.CreateInstance(clazz,
                    BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
                    null, new object[] { dedup, expand, analyzer }, CultureInfo.InvariantCulture);
            }
            catch (Exception e)
            {
                throw e;
            }

            if (File.Exists(synonyms))
            {
                parser.Parse(new StreamReader(loader.OpenResource(synonyms), decoder));
            }
            else
            {
                IEnumerable<string> files = SplitFileNames(synonyms);
                foreach (string file in files)
                {
                    parser.Parse(new StreamReader(loader.OpenResource(synonyms), decoder));
                }
            }
            return parser.Build();
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:34,代码来源:FSTSynonymFilterFactory.cs

示例6: Inform

        public virtual void Inform(IResourceLoader loader)
        {
            string[] dicts = dictionaryFiles.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            Stream affix = null;
            IList<Stream> dictionaries = new List<Stream>();

            try
            {
                dictionaries = new List<Stream>();
                foreach (string file in dicts)
                {
                    dictionaries.Add(loader.OpenResource(file));
                }
                affix = loader.OpenResource(affixFile);

                this.dictionary = new Dictionary(affix, dictionaries, ignoreCase);
            }
            catch (Exception e)
            {
                throw new IOException("Unable to load hunspell data! [dictionary=" + dictionaries + ",affix=" + affixFile + "]", e);
            }
            finally
            {
                IOUtils.CloseWhileHandlingException(affix);
                IOUtils.CloseWhileHandlingException(dictionaries);
            }
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:28,代码来源:HunspellStemFilterFactory.cs

示例7: Inform

        public virtual void Inform(IResourceLoader loader)
        {
            Stream stream = null;
            try
            {
                if (dictFile != null) // the dictionary can be empty.
                {
                    dictionary = GetWordSet(loader, dictFile, false);
                }
                // TODO: Broken, because we cannot resolve real system id
                // ResourceLoader should also supply method like ClassLoader to get resource URL
                stream = loader.OpenResource(hypFile);
                //InputSource @is = new InputSource(stream);
                //@is.Encoding = encoding; // if it's null let xml parser decide
                //@is.SystemId = hypFile;

                var xmlEncoding = string.IsNullOrEmpty(encoding) ? Encoding.UTF8 : Encoding.GetEncoding(encoding);

                hyphenator = HyphenationCompoundWordTokenFilter.GetHyphenationTree(stream, xmlEncoding);

            }
            finally
            {
                IOUtils.CloseWhileHandlingException(stream);
            }
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:26,代码来源:HyphenationCompoundWordTokenFilterFactory.cs


注:本文中的IResourceLoader.OpenResource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。