Mercurial > hg > chourdakisreiss2018dmrn
comparison demo.py @ 1:2082aeb1f1be tip
added demo and readme file
author | Emmanouil Theofanis Chourdakis <e.t.chourdakis@qmul.ac.uk> |
---|---|
date | Wed, 19 Dec 2018 06:51:16 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:56c43da2d64c | 1:2082aeb1f1be |
---|---|
1 import clausiepy as cp | |
2 quote="Crows are feeding on rubbish at a garbage dump." | |
3 | |
4 # Extract clauses | |
5 clauses = cp.clausie(quote) | |
6 | |
7 # Extract propositions | |
8 propositions = cp.extract_propositions(clauses) | |
9 | |
10 queries = [] | |
11 | |
12 # For every proposition, remove auxiliary verb and construct queries | |
13 # (see paper) | |
14 | |
15 keys = ('subject', 'verb', 'indirect object', 'direct object', 'complement', 'adverb') | |
16 | |
17 queries = [] | |
18 | |
19 for prop in propositions: | |
20 | |
21 # Normal queries based on propositions with verbs | |
22 for L in range(len(keys), 1, -1): | |
23 chosen_keys = keys[:L] | |
24 propo = {} | |
25 for key in chosen_keys: | |
26 if key in prop: | |
27 propo[key] = prop[key] | |
28 p0 = cp.proposition_text(propo, chosen_keys) | |
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) | |
30 if len(prop_text) > 0 and prop_text not in queries: | |
31 queries.append(prop_text) | |
32 | |
33 # Subjects and objects independently | |
34 p0 = cp.proposition_text(prop, ['subject']) | |
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) | |
36 if len(prop_text) > 0 and prop_text not in queries: | |
37 queries.append(prop_text) | |
38 | |
39 p0 = cp.proposition_text(prop, ['indirect object']) | |
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) | |
41 if len(prop_text) > 0 and prop_text not in queries: | |
42 queries.append(prop_text) | |
43 | |
44 p0 = cp.proposition_text(prop, ['direct object']) | |
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) | |
46 if len(prop_text) > 0 and prop_text not in queries: | |
47 queries.append(prop_text) | |
48 | |
49 # Adverb | |
50 p0 = cp.proposition_text(prop, ['adverb']) | |
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) | |
52 if len(prop_text) > 0 and prop_text not in queries: | |
53 queries.append(prop_text) | |
54 | |
55 | |
56 print("Queries:") | |
57 for query in queries: | |
58 print(query) |