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 ClueNode GetClueNodeFromPhrases(string[] cluePhrases) { if (Clues.ContainsKey(cluePhrases[0]) != false) { return(Clues[cluePhrases[0]].GetNode(cluePhrases, 0)); } else { return(null); } }
public List <Document> GetDocumentsFromPhrases(string[] cluePhrases) { if (Clues.ContainsKey(cluePhrases[0]) != false) { return(Clues[cluePhrases[0]].GetDocuments(cluePhrases, 0)); } else { return(null); } }
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; } }