private fun filter_regexp(unfilteredTrie: Trie?): SentenceFilteredTrie? { var trie: SentenceFilteredTrie? = nullif (unfilteredTrie.hasRules()) if (matchesSentence(unfilteredTrie))trie =SentenceFilteredTrie(unfilteredTrie) else return nullif (unfilteredTrie.hasExtensions()) for ((key, unfilteredChildTrie): Map.Entry<Int,Trie?> in unfilteredTrie.getChildren().entrySet()) {val nextTrie: SentenceFilteredTrie? = filter_regexp(unfilteredChildTrie)if (nextTrie != null) {if (trie == null) trie= SentenceFilteredTrie(unfilteredTrie)trie.children.put(key, nextTrie)}}return trie}
Alternate filter that uses regular expressions , walking the grammar trie and matching the source side of each rule collection against the input sentence . Failed matches are discarded , and trie nodes extending from that position need not be explored .