当前位置: 首页>>代码示例>>C#>>正文


C# Token.CopyBuffer方法代码示例

本文整理汇总了C#中Token.CopyBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# Token.CopyBuffer方法的具体用法?C# Token.CopyBuffer怎么用?C# Token.CopyBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Token的用法示例。


在下文中一共展示了Token.CopyBuffer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MergeTokens

        /// <summary>
        /// Merge two lists of tokens, producing a single list with manipulated positionIncrements so that
        /// the tokens end up at the same position.
        /// 
        /// Example:  [a b] merged with [c d] produces [a/b c/d]  ('/' denotes tokens in the same position)
        /// Example:  [a,5 b,2] merged with [c d,4 e,4] produces [c a,5/d b,2 e,2]  (a,n means a has posInc=n)
        /// 
        /// </summary>
        public static IList<Token> MergeTokens(IList<Token> lst1, IList<Token> lst2)
        {
            var result = new List<Token>();
            if (lst1 == null || lst2 == null)
            {
                if (lst2 != null)
                {
                    result.AddRange(lst2);
                }
                if (lst1 != null)
                {
                    result.AddRange(lst1);
                }
                return result;
            }

            int pos = 0;
            var iter1 = lst1.GetEnumerator();
            var iter2 = lst2.GetEnumerator();
            var tok1 = iter1.MoveNext() ? iter1.Current : null;
            var tok2 = iter2.MoveNext() ? iter2.Current : null;
            int pos1 = tok1 != null ? tok1.PositionIncrement : 0;
            int pos2 = tok2 != null ? tok2.PositionIncrement : 0;
            while (tok1 != null || tok2 != null)
            {
                while (tok1 != null && (pos1 <= pos2 || tok2 == null))
                {
                    var tok = new Token(tok1.StartOffset(), tok1.EndOffset(), tok1.Type);
                    tok.CopyBuffer(tok1.Buffer(), 0, tok1.Length);
                    tok.PositionIncrement = pos1 - pos;
                    result.Add(tok);
                    pos = pos1;
                    tok1 = iter1.MoveNext() ? iter1.Current : null;
                    pos1 += tok1 != null ? tok1.PositionIncrement : 0;
                }
                while (tok2 != null && (pos2 <= pos1 || tok1 == null))
                {
                    var tok = new Token(tok2.StartOffset(), tok2.EndOffset(), tok2.Type);
                    tok.CopyBuffer(tok2.Buffer(), 0, tok2.Length);
                    tok.PositionIncrement = pos2 - pos;
                    result.Add(tok);
                    pos = pos2;
                    tok2 = iter2.MoveNext() ? iter2.Current : null;
                    pos2 += tok2 != null ? tok2.PositionIncrement : 0;
                }
            }
            return result;
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:56,代码来源:SlowSynonymMap.cs

示例2: GetNextPrefixInputToken

 private Token GetNextPrefixInputToken(Token token)
 {
     if (!prefix.IncrementToken())
     {
         return null;
     }
     token.CopyBuffer(p_termAtt.Buffer(), 0, p_termAtt.Length);
     token.PositionIncrement = p_posIncrAtt.PositionIncrement;
     token.Flags = p_flagsAtt.Flags;
     token.SetOffset(p_offsetAtt.StartOffset(), p_offsetAtt.EndOffset());
     token.Type = p_typeAtt.Type;
     token.Payload = p_payloadAtt.Payload;
     return token;
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:14,代码来源:PrefixAwareTokenFilter.cs

示例3: GetNextSuffixInputToken

 private Token GetNextSuffixInputToken(Token token)
 {
     if (!suffix.IncrementToken())
     {
         return null;
     }
     token.CopyBuffer(termAtt.Buffer(), 0, termAtt.Length);
     token.PositionIncrement = posIncrAtt.PositionIncrement;
     token.Flags = flagsAtt.Flags;
     token.SetOffset(offsetAtt.StartOffset(), offsetAtt.EndOffset());
     token.Type = typeAtt.Type;
     token.Payload = payloadAtt.Payload;
     return token;
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:14,代码来源:PrefixAwareTokenFilter.cs

示例4: CreateToken

 private static Token CreateToken(string term, int start, int offset, int positionIncrement)
 {
     Token token = new Token(start, offset);
     token.CopyBuffer(term.ToCharArray(), 0, term.Length);
     token.PositionIncrement = positionIncrement;
     return token;
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:7,代码来源:ShingleFilterTest.cs


注:本文中的Token.CopyBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。