string Prefix() { string thePrefix = "" + Data; IFCEntityTrieNode currParent = Parent; while (currParent != null) { thePrefix = currParent.Data + thePrefix; currParent = currParent.Parent; } return(thePrefix.Trim()); }
/// <summary> /// Add the IFC entity string into the Trie /// </summary> /// <param name="word">the IFC entity name</param> public void AddEntry(string word) { for (int wordcharCnt = 0; wordcharCnt < word.Length; wordcharCnt++) { IFCEntityTrieNode currNode = m_Root; for (int cnt = wordcharCnt; cnt < word.Length; cnt++) { currNode = currNode.GetChild(word[cnt], FilteredIFCEntityDict, true); if (currNode == null) { break; } } } }
string dumpInvertedIndex(IFCEntityTrieNode node) { string dumpString = null; IFCEntityTrieNode currNode = node; dumpString += currNode.PrintIndexedItems(FilteredIFCEntityDict); if (currNode.Children.Count > 0) { foreach (IFCEntityTrieNode childNode in currNode.Children) { dumpString += dumpInvertedIndex(childNode); } } return(dumpString); }
/// <summary> /// Get the list of IFC entities given the partial name /// </summary> /// <param name="partialWord">partial word to search</param> /// <returns>the list of IFC entities that contain the partial word</returns> public IList <string> PartialWordSearch(string partialWord) { SortedList <string, string> foundItems = new SortedList <string, string>(); IFCEntityTrieNode currNode = m_Root; for (int cnt = 0; cnt < partialWord.Length; cnt++) { currNode = currNode.GetChild(partialWord[cnt], FilteredIFCEntityDict); if (currNode == null) { break; } } if (currNode != null) { foreach (short idx in currNode.IndexItemsWithSubstring) { foundItems.Add(FilteredIFCEntityDict[idx], null); } } return(foundItems.Keys.ToList()); }
/// <summary> /// Create a child node of the Trie /// </summary> /// <param name="inputChar">the input character</param> /// <param name="nonABSEntDict">the dict of all valid entities</param> /// <returns>the created Trie node</returns> public IFCEntityTrieNode CreateChild(char inputChar, IDictionary <short, string> entDict, IList <short> idxWithSubstring) { string thePrefix = Prefix(); thePrefix = thePrefix + inputChar; IList <short> idxEntries = new List <short>(); // At the first node, the list is empty: use the list from the original Dict if (this.Parent == null) { idxWithSubstring = entDict.Keys.ToList(); } // Collect the index with the intended prefix foreach (short idx in idxWithSubstring) { string ent = entDict[idx]; if (ent.IndexOf(thePrefix, StringComparison.OrdinalIgnoreCase) >= 0) { idxEntries.Add(idx); } } // Don't create any node if there is no corresponding entry in the dict if (idxEntries.Count == 0) { return(null); } IFCEntityTrieNode child = new IFCEntityTrieNode(inputChar, this); child.IndexItemsWithSubstring = idxEntries; Children.Add(child); return(child); }
public IFCEntityTrieNode(char inputChar = ' ', IFCEntityTrieNode parent = null) { Parent = parent; Data = inputChar; }