本文整理汇总了C#中TokenStream.AddAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# TokenStream.AddAttribute方法的具体用法?C# TokenStream.AddAttribute怎么用?C# TokenStream.AddAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TokenStream
的用法示例。
在下文中一共展示了TokenStream.AddAttribute方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssertTokenStreamContents
public static void AssertTokenStreamContents(TokenStream ts, String[] output, Int32[] startOffsets, Int32[] endOffsets, String[] types, Int32[] posIncrements, Int32? finalOffset) {
Assert.IsNotNull(output);
var checkClearAtt = (CheckClearAttributesAttribute) ts.AddAttribute(typeof (CheckClearAttributesAttribute));
Assert.IsTrue(ts.HasAttribute(typeof (TermAttribute)), "has no TermAttribute");
var termAtt = (TermAttribute) ts.GetAttribute(typeof (TermAttribute));
OffsetAttribute offsetAtt = null;
if (startOffsets != null || endOffsets != null || finalOffset != null) {
Assert.IsTrue(ts.HasAttribute(typeof (OffsetAttribute)), "has no OffsetAttribute");
offsetAtt = (OffsetAttribute) ts.GetAttribute(typeof (OffsetAttribute));
}
TypeAttribute typeAtt = null;
if (types != null) {
Assert.IsTrue(ts.HasAttribute(typeof (TypeAttribute)), "has no TypeAttribute");
typeAtt = (TypeAttribute) ts.GetAttribute(typeof (TypeAttribute));
}
PositionIncrementAttribute posIncrAtt = null;
if (posIncrements != null) {
Assert.IsTrue(ts.HasAttribute(typeof (PositionIncrementAttribute)), "has no PositionIncrementAttribute");
posIncrAtt = (PositionIncrementAttribute) ts.GetAttribute(typeof (PositionIncrementAttribute));
}
ts.Reset();
for (Int32 i = 0; i < output.Length; i++) {
// extra safety to enforce, that the state is not preserved and also assign bogus values
ts.ClearAttributes();
termAtt.SetTermBuffer("bogusTerm");
if (offsetAtt != null) offsetAtt.SetOffset(14584724, 24683243);
if (typeAtt != null) typeAtt.SetType("bogusType");
if (posIncrAtt != null) posIncrAtt.SetPositionIncrement(45987657);
checkClearAtt.GetAndResetClearCalled(); // reset it, because we called clearAttribute() before
Assert.IsTrue(ts.IncrementToken(), "token " + i + " does not exist");
Assert.IsTrue(checkClearAtt.GetAndResetClearCalled(), "clearAttributes() was not called correctly in TokenStream chain");
Assert.AreEqual(output[i], termAtt.Term(), "term " + i);
if (startOffsets != null)
Assert.AreEqual(startOffsets[i], offsetAtt.StartOffset(), "startOffset " + i);
if (endOffsets != null)
Assert.AreEqual(endOffsets[i], offsetAtt.EndOffset(), "endOffset " + i);
if (types != null)
Assert.AreEqual(types[i], typeAtt.Type(), "type " + i);
if (posIncrements != null)
Assert.AreEqual(posIncrements[i], posIncrAtt.GetPositionIncrement(), "posIncrement " + i);
}
Assert.IsFalse(ts.IncrementToken(), "end of stream");
ts.End();
if (finalOffset.HasValue)
Assert.AreEqual(finalOffset.Value, offsetAtt.EndOffset(), "finalOffset ");
ts.Close();
}
示例2: PrefixAwareTokenFilter
public PrefixAwareTokenFilter(TokenStream prefix, TokenStream suffix)
: base(suffix)
{
this.suffix = suffix;
this.prefix = prefix;
prefixExhausted = false;
termAtt = AddAttribute<ICharTermAttribute>();
posIncrAtt = AddAttribute<IPositionIncrementAttribute>();
payloadAtt = AddAttribute<IPayloadAttribute>();
offsetAtt = AddAttribute<IOffsetAttribute>();
typeAtt = AddAttribute<ITypeAttribute>();
flagsAtt = AddAttribute<IFlagsAttribute>();
p_termAtt = prefix.AddAttribute<ICharTermAttribute>();
p_posIncrAtt = prefix.AddAttribute<IPositionIncrementAttribute>();
p_payloadAtt = prefix.AddAttribute<IPayloadAttribute>();
p_offsetAtt = prefix.AddAttribute<IOffsetAttribute>();
p_typeAtt = prefix.AddAttribute<ITypeAttribute>();
p_flagsAtt = prefix.AddAttribute<IFlagsAttribute>();
}
示例3: PrefixAwareTokenFilter
public PrefixAwareTokenFilter(TokenStream prefix, TokenStream suffix) : base(suffix)
{
Suffix = suffix;
Prefix = prefix;
_prefixExhausted = false;
// ReSharper disable DoNotCallOverridableMethodsInConstructor
_termAtt = AddAttribute<ITermAttribute>();
_posIncrAtt = AddAttribute<IPositionIncrementAttribute>();
_payloadAtt = AddAttribute<IPayloadAttribute>();
_offsetAtt = AddAttribute<IOffsetAttribute>();
_typeAtt = AddAttribute<ITypeAttribute>();
_flagsAtt = AddAttribute<IFlagsAttribute>();
// ReSharper restore DoNotCallOverridableMethodsInConstructor
_pTermAtt = prefix.AddAttribute<ITermAttribute>();
_pPosIncrAtt = prefix.AddAttribute<IPositionIncrementAttribute>();
_pPayloadAtt = prefix.AddAttribute<IPayloadAttribute>();
_pOffsetAtt = prefix.AddAttribute<IOffsetAttribute>();
_pTypeAtt = prefix.AddAttribute<ITypeAttribute>();
_pFlagsAtt = prefix.AddAttribute<IFlagsAttribute>();
}
示例4: assertEquals
// we only check a few core attributes here.
// TODO: test other things
public virtual void assertEquals(string s, TokenStream left, TokenStream right)
{
left.Reset();
right.Reset();
ICharTermAttribute leftTerm = left.AddAttribute<ICharTermAttribute>();
ICharTermAttribute rightTerm = right.AddAttribute<ICharTermAttribute>();
IOffsetAttribute leftOffset = left.AddAttribute<IOffsetAttribute>();
IOffsetAttribute rightOffset = right.AddAttribute<IOffsetAttribute>();
IPositionIncrementAttribute leftPos = left.AddAttribute<IPositionIncrementAttribute>();
IPositionIncrementAttribute rightPos = right.AddAttribute<IPositionIncrementAttribute>();
while (left.IncrementToken())
{
assertTrue("wrong number of tokens for input: " + s, right.IncrementToken());
assertEquals("wrong term text for input: " + s, leftTerm.ToString(), rightTerm.ToString());
assertEquals("wrong position for input: " + s, leftPos.PositionIncrement, rightPos.PositionIncrement);
assertEquals("wrong start offset for input: " + s, leftOffset.StartOffset(), rightOffset.StartOffset());
assertEquals("wrong end offset for input: " + s, leftOffset.EndOffset(), rightOffset.EndOffset());
};
assertFalse("wrong number of tokens for input: " + s, right.IncrementToken());
left.End();
right.End();
assertEquals("wrong final offset for input: " + s, leftOffset.EndOffset(), rightOffset.EndOffset());
left.Dispose();
right.Dispose();
}
示例5: ShingleMatrixFilter
/// <summary>
/// Creates a shingle filter with ad hoc parameter settings.
/// </summary>
/// <param name="input">stream from which to construct the matrix</param>
/// <param name="minimumShingleSize">minimum number of tokens in any shingle.</param>
/// <param name="maximumShingleSize">maximum number of tokens in any shingle.</param>
/// <param name="spacerCharacter">character to use between texts of the token parts in a shingle. null for none.</param>
/// <param name="ignoringSinglePrefixOrSuffixShingle">if true, shingles that only contains permutation of the first of the last column will not be produced as shingles. Useful when adding boundary marker tokens such as '^' and '$'.</param>
/// <param name="settingsCodec">codec used to read input token weight and matrix positioning.</param>
public ShingleMatrixFilter(TokenStream input, int minimumShingleSize, int maximumShingleSize, Char? spacerCharacter, bool ignoringSinglePrefixOrSuffixShingle, TokenSettingsCodec settingsCodec)
{
_input = input;
MinimumShingleSize = minimumShingleSize;
MaximumShingleSize = maximumShingleSize;
SpacerCharacter = spacerCharacter;
IsIgnoringSinglePrefixOrSuffixShingle = ignoringSinglePrefixOrSuffixShingle;
_settingsCodec = settingsCodec;
// ReSharper disable DoNotCallOverridableMethodsInConstructor
_termAtt = AddAttribute<ITermAttribute>();
_posIncrAtt = AddAttribute<IPositionIncrementAttribute>();
_payloadAtt = AddAttribute<IPayloadAttribute>();
_offsetAtt = AddAttribute<IOffsetAttribute>();
_typeAtt = AddAttribute<ITypeAttribute>();
_flagsAtt = AddAttribute<IFlagsAttribute>();
// ReSharper restore DoNotCallOverridableMethodsInConstructor
_inTermAtt = input.AddAttribute<ITermAttribute>();
_inPosIncrAtt = input.AddAttribute<IPositionIncrementAttribute>();
_inPayloadAtt = input.AddAttribute<IPayloadAttribute>();
_inOffsetAtt = input.AddAttribute<IOffsetAttribute>();
_inTypeAtt = input.AddAttribute<ITypeAttribute>();
_inFlagsAtt = input.AddAttribute<IFlagsAttribute>();
}
示例6: tsToString
/// <summary>
/// TODO: rewrite tests not to use string comparison.
/// </summary>
private static string tsToString(TokenStream @in)
{
StringBuilder @out = new StringBuilder();
ICharTermAttribute termAtt = @in.AddAttribute<ICharTermAttribute>();
// extra safety to enforce, that the state is not preserved and also
// assign bogus values
@in.ClearAttributes();
termAtt.SetEmpty().Append("bogusTerm");
@in.Reset();
while (@in.IncrementToken())
{
if (@out.Length > 0)
{
@out.Append(' ');
}
@out.Append(termAtt.ToString());
@in.ClearAttributes();
termAtt.SetEmpty().Append("bogusTerm");
}
@in.Dispose();
return @out.ToString();
}