void Trie::insertWord(string word){
	incrementWordCount();
	TrieNode* node = root;
	for(unsigned int i = 0; i < word.length(); i++){
		if(node->findChild(word[i]) == NULL){
			node = node->insertChild(word[i]);
		}
		else{
			node = node->findChild(word[i]);
		}
	}
	node->setIsWord();
	node->instantiatePostingList(word); // implemented in trieNode
	node->setDocFreq();
}
TrieNode* Trie::findWord(string word){
	TrieNode* node = root;
	for(unsigned int i = 0; i < word.length(); i++){
		if(node->findChild(word[i]) == NULL){
			return NULL;
		}
		else{
			node = node->findChild(word[i]);
		}
		if(i == word.length()-1){
			if(node->getIsWord() == true){
				return node;
			}
			else{
				return NULL;
			}
		}
	}
}
Пример #3
0
bool Trie::searchWord(string s) {
  TrieNode* curr = root;

  while(curr != NULL) {
    for(int i = 0; i < s.length(); i++) {
      TrieNode* tmp = curr->findChild(s[i]);
      if(tmp == NULL)
        return false;
      curr = tmp;
    }

    if(curr->getWordMarker())
      return true;
    else
      return false;
  }

  return false;
}
 // Adds a word into the data structure.
 void addWord(string word) {
     
     TrieNode* current = root;
     if (word.size() == 0) {
         root->marker = true;
         return;
     }
     
     for (int i = 0; i < word.size(); ++i) {
         TrieNode* newnode = current->findChild(word[i]);
         if (!newnode) {
             newnode = new TrieNode(word[i]);
             current->children.push_back(newnode);
         }
         
         current = newnode;
         if (i == word.size() - 1) {
             current->marker = true;
         }
     }
 }
Пример #5
0
void Trie::addWord(string s) {
  TrieNode* curr = root;
  if(s.length() == 0) {
    curr->setWordMarker();
    return;
  }

  for(int i = 0; i < s.length(); i++) {
    TrieNode* child = curr->findChild(s[i]);
    if(child != NULL) {
      curr = child;
    } else {
      TrieNode* tmp = new TrieNode();
      tmp->setContent(s[i]);
      curr->appendChild(tmp);
      curr = tmp;
    }

    if(i == s.length() - 1)
      curr->setWordMarker();
  }
}