public void AddDocumentToClue(string clue, Document doc) { string[] clueFragments = SeperateClueFragments(clue); if (Clues.ContainsKey(clueFragments[0]) == false) { Clues[clueFragments[0]] = new ClueNode(); } Clues[clueFragments[0]].AddDocument(clueFragments, 0, doc); }
public void AddDocument(string[] clueFragments, int currentIndex, Document doc) { // If we are the last cluefragment, then just add the doc if (clueFragments.Length - 1 == currentIndex) { References.Add(doc); // Notice not checking existence, assumed not existing } else { if (Children.ContainsKey(clueFragments[currentIndex + 1]) == false) { Children[clueFragments[currentIndex + 1]] = new ClueNode(); } Children[clueFragments[currentIndex + 1]].AddDocument(clueFragments, currentIndex + 1, doc); } }
/// <summary> /// From existing clues find corresponding documents, and also provide a hint about next available clue; Do not return non-existing clues /// </summary> /// /// <param name="cursorLocation">Which keyPhrase is current cursor on, this is used for more intelligent auto-complete</param> /// <param name="keyPhrases"></param> /// <param name="nextClues"></param> /// <param name="foundDocuments"></param> public void SearchExistingClues(int cursorLocation, string[] keyPhrases, out List <ClueFragment> nextClues, out List <Document> foundDocuments) { // <Dev> Pending implementation cursorLocation // Genereate exact clues return ClueNode clueNode = GetClueNodeFromPhrases(keyPhrases); string currentClueString = string.Join("-", keyPhrases); if (clueNode != null) { // Get next clues Dictionary <string, ClueNode> clueNodeChildren = clueNode.Children; nextClues = new List <ClueFragment>(); foreach (KeyValuePair <string, ClueNode> entry in clueNodeChildren) { List <Document> clueDocuments = entry.Value.References; nextClues.Add(new ClueFragment(entry.Key, clueDocuments.Count, currentClueString + '-' + entry.Key, clueDocuments)); } // Get found documents foundDocuments = clueNode.References; } else { nextClues = null; foundDocuments = null; } // Try again by generating partial clues match return if (nextClues == null && foundDocuments == null && keyPhrases.Length > 1) { List <ClueNode> partialMatches = GetClueNodeFromPartialPhrase(keyPhrases); currentClueString = currentClueString.Substring(0, currentClueString.LastIndexOf('-')); // Next clues will be a combination of all nextClues = new List <ClueFragment>(); foreach (ClueNode node in partialMatches) { foreach (KeyValuePair <string, ClueNode> entry in node.Children) { List <Document> clueDocuments = entry.Value.References; nextClues.Add(new ClueFragment(entry.Key, clueDocuments.Count, currentClueString + '-' + entry.Key, clueDocuments)); } } // There shall be no found documents so far } }
public List <ClueNode> GetClueNodeFromPartialPhrase(string[] cluePhrases) // Compared with GetClueNodeFromPhrases(), this function doesn't assume the last keyword phrase to be exact { // Make a partial copy string[] partialPhrases = null; Array.Copy(cluePhrases, partialPhrases, cluePhrases.Length - 1); // Get node up till that partial copy ClueNode node = null; if (Clues.ContainsKey(partialPhrases[0]) != false) { node = Clues[partialPhrases[0]].GetNode(partialPhrases, 0); } else { return(null); } // Check result if (node != null) { // Find partial matches List <ClueNode> partialMatches = new List <ClueNode>(); string partialPhrase = cluePhrases[cluePhrases.Length - 1]; foreach (KeyValuePair <string, ClueNode> entry in node.Children) { if (entry.Key.IndexOf(partialPhrase) == 0) { partialMatches.Add(entry.Value); } } if (partialMatches.Count != 0) { return(partialMatches); } else { return(null); } } else { return(null); } }
// Search Shorthand clue form public void SearchBySimpleClue(int cursorLocation, string[] keyPhrases, out List <ClueFragment> nextClues, out List <Document> foundDocuments, bool bDeep = false) { // <Dev> Pending implementation cursorLocation // Parameters string lastKeyPhrase = keyPhrases[keyPhrases.Length - 1]; // Can be a clue or a metaname or a metavalue, can be partial nextClues = new List <ClueFragment>(); foundDocuments = new List <Document>(); // Heuristic: Mostly like the last phrase will be a meta because there's little point just entering a clue // Use former clues to confine range string[] partialPhrases; if (keyPhrases.Length > 1) { partialPhrases = new string[keyPhrases.Length - 1]; Array.Copy(keyPhrases, partialPhrases, keyPhrases.Length - 1); } else { partialPhrases = keyPhrases; } // Get node up till that partial copy ClueNode node = null; if (Clues.ContainsKey(partialPhrases[0]) != false) { node = Clues[partialPhrases[0]].GetNode(partialPhrases, 0); // Try as meta foreach (Document doc in node.References) { if (doc.IsPartialCLue(lastKeyPhrase) || doc.IsPartialMetaNameOrValue(lastKeyPhrase)) { foundDocuments.Add(doc); } } string currentClueString = string.Join("-", partialPhrases); if (foundDocuments.Count != 0) { // Add further clues at current level foreach (KeyValuePair <string, ClueNode> entry in node.Children) { List <Document> clueDocuments = entry.Value.References; nextClues.Add(new ClueFragment(entry.Key, clueDocuments.Count, currentClueString + '-' + entry.Key, clueDocuments)); } } else { // Try as clue foreach (KeyValuePair <string, ClueNode> entry in node.Children) { List <Document> clueDocuments = entry.Value.References; nextClues.Add(new ClueFragment(entry.Key, clueDocuments.Count, currentClueString + '-' + entry.Key, clueDocuments)); // foundDocuments.AddRange(clueDocuments); // Add all as possible found } foundDocuments = null; // or we shouldn't have any found } } else { nextClues = null; foundDocuments = null; } }