本文整理汇总了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;
}
示例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());
}
}
示例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"));
}