def feat_vect(deps, pos, vect): trees = listTree.build_ListTrees(deps, pos) nones = [] tuples = [] quotes = [] questions = [] antecedents = [] consequents = [] neg_verbs = [] neg_all = [] commit_starts = [] for num in range(len(trees)): tree = trees[num] ''' verbs, all_neg = tree.get_neg() if verbs: neg_verbs.extend(verbs) verbs = sorted(list(set(verbs)), key=lambda node: node.start) ranged = build_ranges(verbs, 'neg_verbs') tuples.extend(ranged[0]) commit_starts.extend(ranged[1]) neg_verbs.extend(ranged[2]) if all_neg: neg_all.extend(all_neg) all_neg = sorted(list(set(all_neg)), key=lambda node: node.start) ranged = build_ranges(all_neg, 'neg_all') tuples.extend(ranged[0]) commit_starts.extend(ranged[1]) neg_all.extend(ranged[2]) ''' question = tree.get_question() if question != None: questions.extend(question) question = sorted(list(set(question)), key=lambda node: node.start) ranged = build_ranges(question, 'question') tuples.extend(ranged[0]) commit_starts.extend(ranged[1]) questions.extend(ranged[2]) for node in question: node.commitment = True condit = tree.get_cond() if condit[0] != None and condit[1] != None: ant, cons = condit antecedents.extend(ant) ant = sorted(list(set(ant)), key=lambda node: node.start) ranged = build_ranges(ant, 'antecedent') tuples.extend(ranged[0]) commit_starts.extend(ranged[1]) antecedents.extend(ranged[2]) for node in ant: node.commitment = True consequents.extend(cons) cons = sorted(list(set(cons)), key=lambda node: node.start) ranged = build_ranges(cons, 'consequent') tuples.extend(ranged[0]) commit_starts.extend(ranged[1]) antecedents.extend(ranged[2]) for node in cons: node.commitment = True if len(trees) > 0: quotes = trees[0].get_quotes() if len(quotes) > 0: quotes= sorted(list(set(quotes)), key=lambda node: node.start) ranged = build_ranges(quotes, 'quote', is_quote=True) tuples.extend(ranged[0]) commit_starts.extend(ranged[1]) quotes.extend(ranged[2]) for node in quotes: node.commitment = True for tree in trees: curr = tree.start while curr != None: nones.append(curr) curr = curr.nxt commits = quotes + questions + antecedents + consequents + neg_all + neg_verbs nones = [node for node in nones if node not in commits] nones = sorted(list(set(nones)), key=lambda node: node.start) ranged = build_ranges(nones, 'none') tuples.extend(ranged[0]) nones.extend(ranged[2]) name = "NONE_" for node in nones: update(name, node, vect) name = "QUOTE_" for node in quotes: update(name, node, vect) name = "QUESTION_" for node in questions: update(name, node, vect) name = "ANTECEDENT_" for node in antecedents: update(name, node, vect) name = "CONSEQUENT_" for node in consequents: update(name, node, vect) ''' name = "NEG_VERBS_" for node in neg_verbs: update(name, node, vect) name = "NEG_ALL_" for node in neg_all: update(name, node, vect) ''' return tuples
''' return tuples if __name__ == '__main__': import json curr_file = "/home/random/workspace/Persuasion/data/convinceme/output_by_thread/1736/21585.json" j = json.load(open(curr_file)) pos = j[0] deps = j[2] trees = listTree.build_ListTrees(deps, pos) for tree in trees: print tree quotes = trees[0].get_quotes() print print print quotes print print vect = {} tuples = feat_vect(deps, pos, vect) if len(vect) > 0: print vect