本文整理汇总了C#中Tokenizer.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Tokenizer.Dispose方法的具体用法?C# Tokenizer.Dispose怎么用?C# Tokenizer.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tokenizer
的用法示例。
在下文中一共展示了Tokenizer.Dispose方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestBasic2
public virtual void TestBasic2()
{
b = new SynonymMap.Builder(true);
const bool keepOrig = false;
Add("aaa", "aaaa1 aaaa2 aaaa3", keepOrig);
Add("bbb", "bbbb1 bbbb2", keepOrig);
tokensIn = new MockTokenizer(new StringReader("a"), MockTokenizer.WHITESPACE, true);
tokensIn.Reset();
assertTrue(tokensIn.IncrementToken());
assertFalse(tokensIn.IncrementToken());
tokensIn.End();
tokensIn.Dispose();
tokensOut = new SynonymFilter(tokensIn, b.Build(), true);
termAtt = tokensOut.AddAttribute<ICharTermAttribute>();
posIncrAtt = tokensOut.AddAttribute<IPositionIncrementAttribute>();
posLenAtt = tokensOut.AddAttribute<IPositionLengthAttribute>();
offsetAtt = tokensOut.AddAttribute<IOffsetAttribute>();
#pragma warning disable 162
if (keepOrig)
{
Verify("xyzzy bbb pot of gold", "xyzzy bbb/bbbb1 pot/bbbb2 of gold");
Verify("xyzzy aaa pot of gold", "xyzzy aaa/aaaa1 pot/aaaa2 of/aaaa3 gold");
}
else
{
Verify("xyzzy bbb pot of gold", "xyzzy bbbb1 pot/bbbb2 of gold");
Verify("xyzzy aaa pot of gold", "xyzzy aaaa1 pot/aaaa2 of/aaaa3 gold");
}
#pragma warning restore 612, 618
}
示例2: TestBasic
public virtual void TestBasic()
{
b = new SynonymMap.Builder(true);
Add("a", "foo", true);
Add("a b", "bar fee", true);
Add("b c", "dog collar", true);
Add("c d", "dog harness holder extras", true);
Add("m c e", "dog barks loudly", false);
Add("i j k", "feep", true);
Add("e f", "foo bar", false);
Add("e f", "baz bee", false);
Add("z", "boo", false);
Add("y", "bee", true);
tokensIn = new MockTokenizer(new StringReader("a"), MockTokenizer.WHITESPACE, true);
tokensIn.Reset();
assertTrue(tokensIn.IncrementToken());
assertFalse(tokensIn.IncrementToken());
tokensIn.End();
tokensIn.Dispose();
tokensOut = new SynonymFilter(tokensIn, b.Build(), true);
termAtt = tokensOut.AddAttribute<ICharTermAttribute>();
posIncrAtt = tokensOut.AddAttribute<IPositionIncrementAttribute>();
posLenAtt = tokensOut.AddAttribute<IPositionLengthAttribute>();
offsetAtt = tokensOut.AddAttribute<IOffsetAttribute>();
Verify("a b c", "a/bar b/fee c");
// syn output extends beyond input tokens
Verify("x a b c d", "x a/bar b/fee c/dog d/harness holder extras");
Verify("a b a", "a/bar b/fee a/foo");
// outputs that add to one another:
Verify("c d c d", "c/dog d/harness c/holder/dog d/extras/harness holder extras");
// two outputs for same input
Verify("e f", "foo/baz bar/bee");
// verify multi-word / single-output offsets:
Verify("g i j k g", "g i/feep:7_3 j k g");
// mixed keepOrig true/false:
Verify("a m c e x", "a/foo dog barks loudly x");
Verify("c d m c e x", "c/dog d/harness holder/dog extras/barks loudly x");
assertTrue(tokensOut.CaptureCount > 0);
// no captureStates when no syns matched
Verify("p q r s t", "p q r s t");
assertEquals(0, tokensOut.CaptureCount);
// no captureStates when only single-input syns, w/ no
// lookahead needed, matched
Verify("p q z y t", "p q boo y/bee t");
assertEquals(0, tokensOut.CaptureCount);
}
示例3: TestRandom
public virtual void TestRandom()
{
int alphabetSize = TestUtil.NextInt(Random(), 2, 7);
int docLen = AtLeast(3000);
//final int docLen = 50;
string document = GetRandomString('a', alphabetSize, docLen);
if (VERBOSE)
{
Console.WriteLine("TEST: doc=" + document);
}
int numSyn = AtLeast(5);
//final int numSyn = 2;
IDictionary<string, OneSyn> synMap = new Dictionary<string, OneSyn>();
IList<OneSyn> syns = new List<OneSyn>();
bool dedup = Random().nextBoolean();
if (VERBOSE)
{
Console.WriteLine(" dedup=" + dedup);
}
b = new SynonymMap.Builder(dedup);
for (int synIDX = 0; synIDX < numSyn; synIDX++)
{
string synIn = GetRandomString('a', alphabetSize, TestUtil.NextInt(Random(), 1, 5)).Trim();
OneSyn s = synMap.ContainsKey(synIn) ? synMap[synIn] : null;
if (s == null)
{
s = new OneSyn();
[email protected] = synIn;
syns.Add(s);
[email protected] = new List<string>();
synMap[synIn] = s;
s.keepOrig = Random().nextBoolean();
}
string synOut = GetRandomString('0', 10, TestUtil.NextInt(Random(), 1, 5)).Trim();
[email protected](synOut);
Add(synIn, synOut, s.keepOrig);
if (VERBOSE)
{
Console.WriteLine(" syns[" + synIDX + "] = " + [email protected] + " -> " + [email protected] + " keepOrig=" + s.keepOrig);
}
}
tokensIn = new MockTokenizer(new StringReader("a"), MockTokenizer.WHITESPACE, true);
tokensIn.Reset();
assertTrue(tokensIn.IncrementToken());
assertFalse(tokensIn.IncrementToken());
tokensIn.End();
tokensIn.Dispose();
tokensOut = new SynonymFilter(tokensIn, b.Build(), true);
termAtt = tokensOut.AddAttribute<ICharTermAttribute>();
posIncrAtt = tokensOut.AddAttribute<IPositionIncrementAttribute>();
posLenAtt = tokensOut.AddAttribute<IPositionLengthAttribute>();
offsetAtt = tokensOut.AddAttribute<IOffsetAttribute>();
if (dedup)
{
PruneDups(syns);
}
string expected = SlowSynMatcher(document, syns, 5);
if (VERBOSE)
{
Console.WriteLine("TEST: expected=" + expected);
}
Verify(document, expected);
}
示例4: TestOutputHangsOffEnd
public virtual void TestOutputHangsOffEnd()
{
b = new SynonymMap.Builder(true);
const bool keepOrig = false;
// b hangs off the end (no input token under it):
Add("a", "a b", keepOrig);
tokensIn = new MockTokenizer(new StringReader("a"), MockTokenizer.WHITESPACE, true);
tokensIn.Reset();
assertTrue(tokensIn.IncrementToken());
assertFalse(tokensIn.IncrementToken());
tokensIn.End();
tokensIn.Dispose();
tokensOut = new SynonymFilter(tokensIn, b.Build(), true);
termAtt = tokensOut.AddAttribute<ICharTermAttribute>();
posIncrAtt = tokensOut.AddAttribute<IPositionIncrementAttribute>();
offsetAtt = tokensOut.AddAttribute<IOffsetAttribute>();
posLenAtt = tokensOut.AddAttribute<IPositionLengthAttribute>();
// Make sure endOffset inherits from previous input token:
Verify("a", "a b:1");
}