def test_freqt(self): frequent_subtrees = freqt.freqt(self.root, 0.2) self.assertEqual(len(frequent_subtrees), 4) frequent_subtrees = freqt.freqt(self.root, 0.15) self.assertEqual(len(frequent_subtrees), 5)
parser.add_option("-t", "--timeout", dest="timeout", type="int", default="0", help="Bounds the maximum time that any call to" + "frequent_subtrees can take. Default is no timeout.") (options, args) = parser.parse_args() if len(args) != 2: parser.error("Must specify tree_file and minsup") (tree_file, minsup_str) = args minsup = float(minsup_str) # Generate a tree f = open(tree_file) tree_string = f.readline() f.close() root = tree.OrderedTreeNode("root") root.build_tree_from_string(tree_string) # Discover subtrees that occur with frequency greater than 0.2 in subtree frequent_subtrees = freqt.freqt(root, minsup, options.timeout) print "# ==== Size: Original Tree ====\n" print "digraph {\n%s}\n\n" % root.print_tree() for key in sorted(frequent_subtrees.keys(), reverse=True): print "# ==== Size: %d ====\n" % key for subtree in frequent_subtrees[key]: print "digraph {\n%s}\n" % \ tree.OrderedTreeNode.unrooted_build_tree_from_string(subtree).print_tree()