Exemple #1
0
 /// <summary>
 /// Connects this node to the specified parent node.
 /// </summary>
 /// <param name="parent">The node to connect to this node.</param>
 /// <returns>True if the other node was connected to this node.</returns>
 public bool AddParent(Node parent)
 {
     if (parent == null) throw new ArgumentNullException("parent");
     return parent.AddChild(this);
 }
Exemple #2
0
		protected void AddKeywordsToGraphNode(Node node, List<SentenceInfo> keywords, int depth)
		{
			if (depth < FDG_DEPTH_LIMIT)
			{
				int idx = 0;

				foreach(SentenceInfo si in keywords)
				{
					// Limit # of keywords we display.
					if (idx++ < FDG_NODE_KEYWORD_LIMIT)
					{
						Node child = new TextNode(surface, si.Keyword);
						node.AddChild(child);

						// Get all sentences indices containing this keyword:
						List<int> containingSentences = keywordSentenceMap[si.Keyword];

						// Now get the related keywords for each of those sentences.  
						List<SentenceInfo> relatedKeywords = new List<SentenceInfo>();

						containingSentences.ForEach(cs =>
							{
								// Get the unique and previously not processed keywords in the sentence.
								List<SentenceInfo> si3 = GetKeywordsInSentence(cs).Where(sik => !parsedKeywords.Contains(sik.Keyword.ToLower())).ToList();
								// TODO: sort by relevance
								si3 = si3.RemoveDuplicates((si1, si2) => si1.Keyword.ToLower() == si2.Keyword.ToLower()).ToList();
								relatedKeywords.AddRange(si3);
								parsedKeywords.AddRange(si3.Select(sik=>sik.Keyword.ToLower()));
							});

						if (relatedKeywords.Count > 0)
						{
							AddKeywordsToGraphNode(child, relatedKeywords, depth + 1);
						}
					}
					else
					{
						break;
					}
				}
			}
		}