本文整理汇总了C#中Tokenizer.End方法的典型用法代码示例。如果您正苦于以下问题:C# Tokenizer.End方法的具体用法?C# Tokenizer.End怎么用?C# Tokenizer.End使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tokenizer
的用法示例。
在下文中一共展示了Tokenizer.End方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsMatchImpl
protected override Token IsMatchImpl(Tokenizer tokenizer)
{
var str = new StringBuilder();
if (tokenizer.Current == StringDelim)
{
tokenizer.Consume();
while (!tokenizer.End() && tokenizer.Current != StringDelim)
{
str.Append(tokenizer.Current);
tokenizer.Consume();
}
if (tokenizer.Current == StringDelim)
{
tokenizer.Consume();
}
}
if (str.Length > 0)
{
return new Token(TokenType.QuotedString, str.ToString());
}
return null;
}
示例2: IsMatchImpl
protected override Token IsMatchImpl(Tokenizer tokenizer)
{
bool foundWhiteSpace = false;
while (!tokenizer.End() && String.IsNullOrWhiteSpace(tokenizer.Current))
{
foundWhiteSpace = true;
tokenizer.Consume();
}
if (foundWhiteSpace)
{
return new Token(TokenType.WhiteSpace);
}
return null;
}
示例3: IsMatch
public Token IsMatch(Tokenizer tokenizer)
{
if (tokenizer.End())
{
return new Token(TokenType.EOF);
}
tokenizer.TakeSnapshot();
var match = IsMatchImpl(tokenizer);
if (match == null)
{
tokenizer.RollbackSnapshot();
}
else
{
tokenizer.CommitSnapshot();
}
return match;
}
示例4: 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
}
示例5: 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);
}
示例6: 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);
}
示例7: 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");
}
示例8: Tokenize
static void Tokenize(TextReader reader, Tokenizer tokenizer)
{
tokenizer.Start();
bool swallowBom = true;
try
{
char[] buffer = new char[2048];
UTF16Buffer bufr = new UTF16Buffer(buffer, 0, 0);
bool lastWasCR = false;
int len = -1;
if ((len = reader.Read(buffer, 0, buffer.Length)) != 0)
{
int streamOffset = 0;
int offset = 0;
int length = len;
if (swallowBom)
{
if (buffer[0] == '\uFEFF')
{
streamOffset = -1;
offset = 1;
length--;
}
}
if (length > 0)
{
bufr.Start = offset;
bufr.End = offset + length;
while (bufr.HasMore)
{
bufr.Adjust(lastWasCR);
lastWasCR = false;
if (bufr.HasMore)
{
lastWasCR = tokenizer.TokenizeBuffer(bufr);
}
}
}
streamOffset = length;
while ((len = reader.Read(buffer, 0, buffer.Length)) != 0)
{
bufr.Start = 0;
bufr.End = len;
while (bufr.HasMore)
{
bufr.Adjust(lastWasCR);
lastWasCR = false;
if (bufr.HasMore)
{
lastWasCR = tokenizer.TokenizeBuffer(bufr);
}
}
streamOffset += len;
}
}
tokenizer.Eof();
}
finally
{
tokenizer.End();
}
}