本文整理汇总了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).
}
示例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
}
}
示例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;
}
示例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);
}
示例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();
}
示例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);
}
}
示例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);
}
}