本文整理汇总了C#中Lucene.Net.Analysis.Token.SetTermBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# Token.SetTermBuffer方法的具体用法?C# Token.SetTermBuffer怎么用?C# Token.SetTermBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Analysis.Token
的用法示例。
在下文中一共展示了Token.SetTermBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCtor
public virtual void TestCtor()
{
Token t = new Token();
char[] content = "hello".ToCharArray();
t.SetTermBuffer(content, 0, content.Length);
char[] buf = t.TermBuffer();
Assert.AreNotEqual(t.TermBuffer(), content);
Assert.AreEqual("hello", t.Term);
Assert.AreEqual("word", t.Type);
Assert.AreEqual(0, t.Flags);
t = new Token(6, 22);
t.SetTermBuffer(content, 0, content.Length);
Assert.AreEqual("hello", t.Term);
Assert.AreEqual("(hello,6,22)", t.ToString());
Assert.AreEqual("word", t.Type);
Assert.AreEqual(0, t.Flags);
t = new Token(6, 22, 7);
t.SetTermBuffer(content, 0, content.Length);
Assert.AreEqual("hello", t.Term);
Assert.AreEqual("(hello,6,22)", t.ToString());
Assert.AreEqual(7, t.Flags);
t = new Token(6, 22, "junk");
t.SetTermBuffer(content, 0, content.Length);
Assert.AreEqual("hello", t.Term);
Assert.AreEqual("(hello,6,22,type=junk)", t.ToString());
Assert.AreEqual(0, t.Flags);
}
示例2: TestToString
public virtual void TestToString()
{
char[] b = new char[]{'a', 'l', 'o', 'h', 'a'};
Token t = new Token("", 0, 5);
t.SetTermBuffer(b, 0, 5);
Assert.AreEqual("(aloha,0,5)", t.ToString());
t.SetTermText("hi there");
Assert.AreEqual("(hi there,0,5)", t.ToString());
}
示例3: Next
public override Token Next(Token result)
{
result = input.Next(result);
if (result != null)
{
if (stemmer.Stem(result.TermBuffer(), 0, result.termLength))
result.SetTermBuffer(stemmer.GetResultBuffer(), 0, stemmer.GetResultLength());
return result;
}
else
return null;
}
示例4: TestResize
public virtual void TestResize()
{
Token t = new Token();
char[] content = "hello".ToCharArray();
t.SetTermBuffer(content, 0, content.Length);
for (int i = 0; i < 2000; i++)
{
t.ResizeTermBuffer(i);
Assert.IsTrue(i <= t.TermBuffer().Length);
Assert.AreEqual("hello", t.Term);
}
}
示例5: TestMixedStringArray
public virtual void TestMixedStringArray()
{
Token t = new Token("hello", 0, 5);
Assert.AreEqual(t.TermText(), "hello");
Assert.AreEqual(t.TermLength(), 5);
Assert.AreEqual(new System.String(t.TermBuffer(), 0, 5), "hello");
t.SetTermText("hello2");
Assert.AreEqual(t.TermLength(), 6);
Assert.AreEqual(new System.String(t.TermBuffer(), 0, 6), "hello2");
t.SetTermBuffer("hello3".ToCharArray(), 0, 6);
Assert.AreEqual(t.TermText(), "hello3");
// Make sure if we get the buffer and change a character
// that termText() reflects the change
char[] buffer = t.TermBuffer();
buffer[1] = 'o';
Assert.AreEqual(t.TermText(), "hollo3");
}
示例6: Next
public override Token Next(Token token)
{
token.Clear();
if (start == 0)
{
length = input.Read((System.Char[])ioBuffer, 0, ioBuffer.Length);
if (length <= 0)
return null;
}
if (start == length)
return null;
token.SetTermBuffer(ioBuffer, start, 1);
start++;
token.termBuffer[0] = System.Char.ToLower(token.termBuffer[0]);
return token;
}
示例7: Next
public override Token Next(Token result)
{
result = input.Next(result);
if (result != null)
{
char[] buffer = result.TermBuffer();
int length = result.TermLength();
// If no characters actually require rewriting then we
// just return token as-is:
for (int i = 0; i < length; i++)
{
char c = buffer[i];
if (c >= '\u00c0' && c <= '\u0178')
{
RemoveAccents(buffer, length);
result.SetTermBuffer(output, 0, outputPos);
break;
}
}
return result;
}
else
return null;
}
示例8: TokenFactory
private static Token TokenFactory(String text, int posIncr, float weight, int startOffset, int endOffset,
TokenPositioner positioner)
{
var token = new Token(startOffset, endOffset);
token.SetTermBuffer(text);
token.SetPositionIncrement(posIncr);
ShingleMatrixFilter.DefaultSettingsCodec.SetWeight(token, weight);
ShingleMatrixFilter.DefaultSettingsCodec.SetTokenPositioner(token, positioner);
return token;
}
示例9: TokenFactory
private Token TokenFactory(String text, int posIncr, int startOffset, int endOffset)
{
Token token = new Token(startOffset, endOffset);
token.SetTermBuffer(text);
token.PositionIncrement = posIncr;
return token;
}
示例10: CreateToken
private static Token CreateToken(String term, int start, int offset)
{
var token = new Token(start, offset);
token.SetTermBuffer(term);
return token;
}
示例11: TestGrow
public virtual void TestGrow()
{
Token t = new Token();
System.Text.StringBuilder buf = new System.Text.StringBuilder("ab");
for (int i = 0; i < 20; i++)
{
char[] content = buf.ToString().ToCharArray();
t.SetTermBuffer(content, 0, content.Length);
Assert.AreEqual(buf.Length, t.TermLength());
Assert.AreEqual(buf.ToString(), t.Term);
buf.Append(buf.ToString());
}
Assert.AreEqual(1048576, t.TermLength());
Assert.AreEqual(1179654, t.TermBuffer().Length);
// now as a string, first variant
t = new Token();
buf = new System.Text.StringBuilder("ab");
for (int i = 0; i < 20; i++)
{
System.String content = buf.ToString();
t.SetTermBuffer(content, 0, content.Length);
Assert.AreEqual(content.Length, t.TermLength());
Assert.AreEqual(content, t.Term);
buf.Append(content);
}
Assert.AreEqual(1048576, t.TermLength());
Assert.AreEqual(1179654, t.TermBuffer().Length);
// now as a string, second variant
t = new Token();
buf = new System.Text.StringBuilder("ab");
for (int i = 0; i < 20; i++)
{
System.String content = buf.ToString();
t.SetTermBuffer(content);
Assert.AreEqual(content.Length, t.TermLength());
Assert.AreEqual(content, t.Term);
buf.Append(content);
}
Assert.AreEqual(1048576, t.TermLength());
Assert.AreEqual(1179654, t.TermBuffer().Length);
// Test for slow growth to a long term
t = new Token();
buf = new System.Text.StringBuilder("a");
for (int i = 0; i < 20000; i++)
{
System.String content = buf.ToString();
t.SetTermBuffer(content);
Assert.AreEqual(content.Length, t.TermLength());
Assert.AreEqual(content, t.Term);
buf.Append("a");
}
Assert.AreEqual(20000, t.TermLength());
Assert.AreEqual(20167, t.TermBuffer().Length);
// Test for slow growth to a long term
t = new Token();
buf = new System.Text.StringBuilder("a");
for (int i = 0; i < 20000; i++)
{
System.String content = buf.ToString();
t.SetTermBuffer(content);
Assert.AreEqual(content.Length, t.TermLength());
Assert.AreEqual(content, t.Term);
buf.Append("a");
}
Assert.AreEqual(20000, t.TermLength());
Assert.AreEqual(20167, t.TermBuffer().Length);
}
示例12: IncrementToken
public override bool IncrementToken()
{
if (currentRealToken == null)
{
bool next = realStream.IncrementToken();
if (!next)
{
return false;
}
//Token nextRealToken = new Token(, offsetAtt.startOffset(), offsetAtt.endOffset());
ClearAttributes();
termAtt.SetTermBuffer(realTermAtt.Term);
offsetAtt.SetOffset(realOffsetAtt.StartOffset, realOffsetAtt.EndOffset);
posIncrAtt.PositionIncrement = realPosIncrAtt.PositionIncrement;
String expansions = synonyms[realTermAtt.Term];
if (expansions == null)
{
return true;
}
st = new Tokenizer(expansions, ",");
if (st.HasMoreTokens())
{
currentRealToken = new Token(realOffsetAtt.StartOffset, realOffsetAtt.EndOffset);
currentRealToken.SetTermBuffer(realTermAtt.Term);
}
return true;
}
else
{
String tok = st.NextToken();
ClearAttributes();
termAtt.SetTermBuffer(tok);
offsetAtt.SetOffset(currentRealToken.StartOffset, currentRealToken.EndOffset);
posIncrAtt.PositionIncrement = 0;
if (!st.HasMoreTokens())
{
currentRealToken = null;
st = null;
}
return true;
}
}
示例13: TestCopyTo
public virtual void TestCopyTo()
{
Token t = new Token();
Token copy = (Token) TestSimpleAttributeImpls.AssertCopyIsEqual(t);
Assert.AreEqual("", t.Term);
Assert.AreEqual("", copy.Term);
t = new Token(0, 5);
char[] content = "hello".ToCharArray();
t.SetTermBuffer(content, 0, 5);
char[] buf = t.TermBuffer();
copy = (Token) TestSimpleAttributeImpls.AssertCopyIsEqual(t);
Assert.AreEqual(t.Term, copy.Term);
Assert.AreNotSame(buf, copy.TermBuffer());
Payload pl = new Payload(new byte[]{1, 2, 3, 4});
t.Payload = pl;
copy = (Token) TestSimpleAttributeImpls.AssertCopyIsEqual(t);
Assert.AreEqual(pl, copy.Payload);
Assert.AreNotSame(pl, copy.Payload);
}
示例14: GetNextSuffixInputToken
private Token GetNextSuffixInputToken(Token token)
{
if (!Suffix.IncrementToken()) return null;
token.SetTermBuffer(_termAtt.TermBuffer(), 0, _termAtt.TermLength());
token.SetPositionIncrement(_posIncrAtt.GetPositionIncrement());
token.SetFlags(_flagsAtt.GetFlags());
token.SetOffset(_offsetAtt.StartOffset(), _offsetAtt.EndOffset());
token.SetType(_typeAtt.Type());
token.SetPayload(_payloadAtt.GetPayload());
return token;
}
示例15: GetNextInputToken
private Token GetNextInputToken(Token token)
{
if (!_input.IncrementToken()) return null;
token.SetTermBuffer(_inTermAtt.TermBuffer(), 0, _inTermAtt.TermLength());
token.SetPositionIncrement(_inPosIncrAtt.GetPositionIncrement());
token.SetFlags(_inFlagsAtt.GetFlags());
token.SetOffset(_inOffsetAtt.StartOffset(), _inOffsetAtt.EndOffset());
token.SetType(_inTypeAtt.Type());
token.SetPayload(_inPayloadAtt.GetPayload());
return token;
}