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


C# Sentence.GetAttributeByName方法代码示例

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


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

示例1: GetGraph

        public static Graph GetGraph(Sentence sentence, Definition definition, IEventAggregator eventAggregator)
        {
            var wordToVertexMapping = new Dictionary<string, int>();

            var vertexId = 0;

            foreach (var word in sentence.Words)
            {
                var wordId = word.GetAttributeByName(definition.Edge.TargetVertexAttributeName);

                if (wordToVertexMapping.ContainsKey(wordId))
                {
                    eventAggregator.GetEvent<ValidationExceptionEvent>().Publish(string.Format("Duplicate word id {0} in sentence {1}", sentence.GetAttributeByName("id"), wordId));
                    continue;
                }
                wordToVertexMapping.Add(word.GetAttributeByName(definition.Edge.TargetVertexAttributeName), vertexId++);
            }

            var result = new Graph(sentence.Words.Count, wordToVertexMapping);

            foreach (var word in sentence.Words)
            {
                var from = word.GetAttributeByName(definition.Edge.SourceVertexAttributeName);

                if ((from == null) || (from == "0"))
                {
                    continue;
                }

                var to = word.GetAttributeByName(definition.Edge.TargetVertexAttributeName);

                if (to == null)
                {
                    continue;
                }

                if (wordToVertexMapping.ContainsKey(to) && wordToVertexMapping.ContainsKey(from))
                {
                    var toVertexId = wordToVertexMapping[to];
                    var fromVertexId = wordToVertexMapping[from];

                    result.AddEdge(fromVertexId, toVertexId);
                }
            }

            return result;
        }
开发者ID:hflorin,项目名称:annotator,代码行数:47,代码来源:GraphOperations.cs

示例2: AddWordsToSentence

        private void AddWordsToSentence(Sentence sentence, string line)
        {
            if (sentence == null)
            {
                return;
            }

            var tokens = line.Split(new[] {' ', '\t'}, StringSplitOptions.RemoveEmptyEntries);

            var newWord = ObjectCopier.Clone(wordPrototype);

            for (var i = 0; i < tokens.Length; i++)
            {
                var attribute = newWord.Attributes.FirstOrDefault(a => a.Position == i);
                if (attribute != null)
                {
                    attribute.Value = tokens[i];
                }
            }

            sentence.Words.Add(newWord);

            if (string.IsNullOrWhiteSpace(sentence.GetAttributeByName("id")))
            {
                sentence.SetAttributeByName("id", sentenceIdProvider++.ToString());
            }
        }
开发者ID:hflorin,项目名称:annotator,代码行数:27,代码来源:LightConllxDocumentMapper.cs

示例3: ProcessPreviousSentence

        private void ProcessPreviousSentence(Sentence sentence)
        {
            if ((sentence == null) || (sentence.Words.Count <= 1))
            {
                return;
            }

            AddSentenceInternalAttributes(sentence);

            EventAggregator.GetEvent<StatusNotificationEvent>()
                .Publish(string.Format("Loaded sentence: {0} {1}", sentence.GetAttributeByName("id"),
                    sentence.GetAttributeByName("content")));

            var validationResult = new CheckGraphResult();

            sentence.IsTree =
                GraphOperations.GetGraph(sentence, definition, EventAggregator).IsTree(validationResult);

            ProcessGraphValidationResult(validationResult, sentence.GetAttributeByName("id"));
        }
开发者ID:hflorin,项目名称:annotator,代码行数:20,代码来源:LightConllxDocumentMapper.cs


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