// Return affected documents: only immediate documents, i.e. those who are actually specified under that exact clue is affected public List <Document> ChangeClue(Clue oldClue, Clue newClue) { // <Development> Multithread it and I believe the speech will be moderate; Consider parallel LInq // Remove documents from old node ClueTreeNode node = GetTreeNode(oldClue); List <Document> temp = node.Documents; node.Documents = new List <Document>(); // Remove old node from parent if it's empty if (node.Branches.Count == 0) { if (node.Parent == null) { ClueTree.Remove(node.Name); } else { node.Parent.Branches.Remove(node.Name); } } // Move those documents to a new node ClueTreeNode newNode = CreateTreeNode(newClue); newNode.Documents = temp; return(temp); }
public void AddDocument(string[] fragments, int currentIndex, List <Document> pendings) { if (currentIndex == fragments.Length - 1) { foreach (Document pending in pendings) { bool bAlreadyExist = false; foreach (Document doc in Documents) { if (doc == pending) { bAlreadyExist = true; break; } } if (!bAlreadyExist) { Documents.Add(pending); } } } else { if (Branches.ContainsKey(fragments[currentIndex + 1]) == false) { Branches[fragments[currentIndex + 1]] = new ClueTreeNode(fragments[currentIndex + 1], this); } Branches[fragments[currentIndex + 1]].AddDocument(fragments, currentIndex + 1, pendings); } }
public ClueTreeNode CreateTreeNode(Clue clue) { string[] fragments = clue.Fragments; if (ClueTree.ContainsKey(fragments[0]) == false) { ClueTree[fragments[0]] = new ClueTreeNode(fragments[0], null); } return(ClueTree[fragments[0]].CreateTreeNode(fragments, 0)); }
public void AddClue(Clue clue, List <Document> docs) { string[] fragments = clue.Fragments; if (ClueTree.ContainsKey(fragments[0]) == false) { ClueTree[fragments[0]] = new ClueTreeNode(fragments[0], null); } ClueTree[fragments[0]].AddDocument(fragments, 0, docs); }
internal List <ClueFragment> GetBranches(Clue clue) { string[] fragments = clue.Fragments; if (ClueTree.ContainsKey(fragments[0]) == false) { throw new IndexOutOfRangeException("The partial clue doesn't exit."); } // Retrieve ClueTreeNode note = GetTreeNode(clue); return(note.GetClueFraments()); }
internal void GetBranches(Clue clue, out List <ClueFragment> nextFragments, out List <Document> foundDocuments) { string[] fragments = clue.Fragments; if (ClueTree.ContainsKey(fragments[0]) == false) { throw new IndexOutOfRangeException("The partial clue doesn't exit."); } // Retrieve foundDocuments = ClueTree[fragments[0]].GetDocuments(fragments, 0); ClueTreeNode note = GetTreeNode(clue); nextFragments = note.GetClueFraments(); }
public ClueTreeNode CreateTreeNode(string[] fragments, int currentIndex) { if (currentIndex == fragments.Length - 1) { return(this); } else { if (Branches.ContainsKey(fragments[currentIndex + 1]) == false) { Branches[fragments[currentIndex + 1]] = new ClueTreeNode(fragments[currentIndex + 1], this); } return(Branches[fragments[currentIndex + 1]].CreateTreeNode(fragments, currentIndex + 1)); } }
/// <summary> /// Given a bunch of keyphrases, suggest found documents and next steps /// </summary> /// <param name="keyPhrases"></param> /// <param name="nextFragments"></param> /// <param name="foundDocuments"></param> public void SearchForClueFragments(Clue clue, out List <ClueFragment> nextFragments, out List <Document> foundDocuments) { // If we have an exact match, then foundDocuments are results of that match, and nextFragments are sibglings of that match ClueTreeNode node = GetTreeNode(clue); if (node != null) { foundDocuments = node.Documents; nextFragments = node.GetClueFraments(); } // If we don't have an exact match, then foundDocuments are none, and nextFragmetns are possible fragments to use else { foundDocuments = null; // Or empty nextFragments = GetPossibleClueFragments(clue); } }
public void AddDocument(string[] fragments, int currentIndex, Document pending) { if (currentIndex == fragments.Length - 1) { foreach (Document doc in Documents) { if (doc == pending) { return; } } Documents.Add(pending); } else { if (Branches.ContainsKey(fragments[currentIndex + 1]) == false) { Branches[fragments[currentIndex + 1]] = new ClueTreeNode(fragments[currentIndex + 1], this); } Branches[fragments[currentIndex + 1]].AddDocument(fragments, currentIndex + 1, pending); } }
} // If null it's primary tree node public ClueTreeNode(string name, ClueTreeNode parent) { Name = name; Branches = new Dictionary <string, ClueTreeNode>(); Documents = new List <Document>(); }