private boolean dfs(String word, int index, WordTrieNode p) {
    	if (index == word.length() - 1) {
    		if (word.charAt(index) == '.') {
    			for (WordTrieNode node : p.nexts.values()) {
    				if (node.isWord) {
    					return true;
    				}
    			}
    			return false;
    		} else {
    			WordTrieNode endNode = p.nexts.get(word.charAt(index));
    			return endNode != null && endNode.isWord;
    		}
    	}
    	
    	if (index >= word.length()) {
    		return false;
    	}
    	
    	if (word.charAt(index) == '.') {
    		boolean res = false;
    		for (WordTrieNode node : p.nexts.values()) {
    			res |= dfs(word, index + 1, node);
    		}
    		return res;
    	} else {
    		if (p.nexts.containsKey(word.charAt(index))) {
    			return dfs(word, index + 1, p.nexts.get(word.charAt(index)));
    		} else {
    			return false;
    		}
    	}
    }