e@1
|
1 import clausiepy as cp
|
e@1
|
2 quote="Crows are feeding on rubbish at a garbage dump."
|
e@1
|
3
|
e@1
|
4 # Extract clauses
|
e@1
|
5 clauses = cp.clausie(quote)
|
e@1
|
6
|
e@1
|
7 # Extract propositions
|
e@1
|
8 propositions = cp.extract_propositions(clauses)
|
e@1
|
9
|
e@1
|
10 queries = []
|
e@1
|
11
|
e@1
|
12 # For every proposition, remove auxiliary verb and construct queries
|
e@1
|
13 # (see paper)
|
e@1
|
14
|
e@1
|
15 keys = ('subject', 'verb', 'indirect object', 'direct object', 'complement', 'adverb')
|
e@1
|
16
|
e@1
|
17 queries = []
|
e@1
|
18
|
e@1
|
19 for prop in propositions:
|
e@1
|
20
|
e@1
|
21 # Normal queries based on propositions with verbs
|
e@1
|
22 for L in range(len(keys), 1, -1):
|
e@1
|
23 chosen_keys = keys[:L]
|
e@1
|
24 propo = {}
|
e@1
|
25 for key in chosen_keys:
|
e@1
|
26 if key in prop:
|
e@1
|
27 propo[key] = prop[key]
|
e@1
|
28 p0 = cp.proposition_text(propo, chosen_keys)
|
e@1
|
29 prop_text = " ".join(" ".join([p1.text for p1 in p if p1.dep_ not in ['aux', 'det']]) for p in p0 if len(p) > 0)
|
e@1
|
30 if len(prop_text) > 0 and prop_text not in queries:
|
e@1
|
31 queries.append(prop_text)
|
e@1
|
32
|
e@1
|
33 # Subjects and objects independently
|
e@1
|
34 p0 = cp.proposition_text(prop, ['subject'])
|
e@1
|
35 prop_text = " ".join(" ".join([p1.text for p1 in p if p1.dep_ not in ['aux', 'det']]) for p in p0 if len(p) > 0)
|
e@1
|
36 if len(prop_text) > 0 and prop_text not in queries:
|
e@1
|
37 queries.append(prop_text)
|
e@1
|
38
|
e@1
|
39 p0 = cp.proposition_text(prop, ['indirect object'])
|
e@1
|
40 prop_text = " ".join(" ".join([p1.text for p1 in p if p1.dep_ not in ['aux', 'det', 'prep']]) for p in p0 if len(p) > 0)
|
e@1
|
41 if len(prop_text) > 0 and prop_text not in queries:
|
e@1
|
42 queries.append(prop_text)
|
e@1
|
43
|
e@1
|
44 p0 = cp.proposition_text(prop, ['direct object'])
|
e@1
|
45 prop_text = " ".join(" ".join([p1.text for p1 in p if p1.dep_ not in ['aux', 'det', 'prep']]) for p in p0 if len(p) > 0)
|
e@1
|
46 if len(prop_text) > 0 and prop_text not in queries:
|
e@1
|
47 queries.append(prop_text)
|
e@1
|
48
|
e@1
|
49 # Adverb
|
e@1
|
50 p0 = cp.proposition_text(prop, ['adverb'])
|
e@1
|
51 prop_text = " ".join(" ".join([p1.text for p1 in p if p1.dep_ not in ['aux', 'det', 'prep']]) for p in p0 if len(p) > 0)
|
e@1
|
52 if len(prop_text) > 0 and prop_text not in queries:
|
e@1
|
53 queries.append(prop_text)
|
e@1
|
54
|
e@1
|
55
|
e@1
|
56 print("Queries:")
|
e@1
|
57 for query in queries:
|
e@1
|
58 print(query)
|