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


C# TextNode.Add方法代码示例

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


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

示例1: WriteWordLookUp

        public static void WriteWordLookUp(EpsgData data, BinaryWriter textWriter, BinaryWriter indexWriter)
        {
            var roots = new List<TextNode>();
            foreach(var text in data.WordLookUpList) {
                var containerRoot = TextNode.FindContainingRoot(roots, text);
                if(null == containerRoot) {
                    containerRoot = new TextNode(text);
                    var containedRoots = roots.Where(r => containerRoot.Contains(r.Text)).ToList();
                    foreach(var containedRoot in containedRoots) {
                        roots.Remove(containedRoot);
                        if(!containerRoot.Add(containedRoot)) {
                            throw new InvalidOperationException();
                        }
                    }
                    roots.Add(containerRoot);
                }else {
                    if(!containerRoot.Add(text)) {
                        throw new InvalidOperationException();
                    }
                }
            }

            for (int quality = Math.Min(6,roots.Select(x => x.Text.Length).Max()/2); quality >= 0; quality--) {
                for (int i = 0; i < roots.Count; i++) {
                    for (int j = i + 1; j < roots.Count; j++) {
                        int overlapAt = StringUtils.OverlapIndex(roots[i].Text, roots[j].Text);
                        if (overlapAt >= 0 && (roots[i].Text.Length - overlapAt) >= quality) {
                            var newText = roots[i].Text.Substring(0, overlapAt) + roots[j].Text;
                            var newNode = new TextNode(newText, new[]{roots[i], roots[j]});
                            roots.RemoveAt(j);
                            roots[i] = newNode;
                            i--;
                            break;
                        }
                        overlapAt = StringUtils.OverlapIndex(roots[j].Text, roots[i].Text);
                        if (overlapAt >= 0 && (roots[j].Text.Length - overlapAt) >= quality) {
                            var newText = roots[j].Text.Substring(0, overlapAt) + roots[i].Text;
                            var newNode = new TextNode(newText, new[]{roots[j], roots[i]});
                            roots.RemoveAt(j);
                            roots[i] = newNode;
                            i--;
                            break;
                        }
                    }
                }
            }

            var offsetLookUp = new Dictionary<string, int>();
            int rootOffset = 0;
            foreach(var root in roots) {
                var rootText = root.Text;
                var rootBytes = Encoding.UTF8.GetBytes(rootText);
                textWriter.Write(rootBytes);
                foreach(var text in root.GetAllString()) {
                    int startIndex = rootText.IndexOf(text, StringComparison.Ordinal);
                    var localOffset = Encoding.UTF8.GetByteCount(rootText.Substring(0, startIndex));
                    offsetLookUp.Add(text, rootOffset + localOffset);
                }
                rootOffset += rootBytes.Length;
            }

            foreach(var word in data.WordLookUpList) {
                indexWriter.Write((ushort)offsetLookUp[word]);
                indexWriter.Write((byte)(Encoding.UTF8.GetByteCount(word)));
            }
        }
开发者ID:aarondandy,项目名称:pigeoid,代码行数:66,代码来源:WriterUtils.cs


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