-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.py
140 lines (128 loc) · 3.26 KB
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
from contextlib import contextmanager
import json
from time import sleep
from tqdm import trange
import yaml
from panoptes.ling.english import English
from panoptes.ling.glue.idiolect import Idiolect
from panoptes.ling.tree.arg_loader import ArgLoader
from panoptes.ling.tree.deep.sentence import DeepSentence
from panoptes.ling.verb.verb import DeepVerb
@contextmanager
def step(name):
indent = ' ' * 4
print()
print(indent + name)
print(indent + '-' * len(name))
print()
yield
sleep(1.337)
dump = lambda x: json.dumps(x, indent=4, sort_keys=True)
dump = lambda x: yaml.safe_dump(x)
with step('Setup'):
loader = ArgLoader()
english = English()
with step('Verb'):
obj = {
'lemma': 'be',
'polarity': {
'tf': True,
'is_contrary': False,
},
'tense': 'PRESENT',
'aspect': {
'is_perf': False,
'is_prog': False,
},
'modality': {
'flavor': 'IMPERATIVE',
'is_cond': False,
},
'verb_form': 'FINITE',
'is_pro_verb': False,
}
be = DeepVerb.load(obj)
print(dump(be.dump()))
with step('Implied subject'):
obj = {
'type': 'PersonalPronoun',
'declension': 'YALL',
'ppcase': 'SUBJECT',
}
yall = loader.load(obj)
print(dump(yall.dump()))
with step('Locative argument'):
obj = {
'type': 'DeepCommonNoun',
'possessor': None,
'selector': {
'correlative': 'PROX',
'n_min': 'SING',
'n_max': 'SING',
'of_n_min': 'SING',
'of_n_max': 'SING',
},
'number': None,
'attributes': [],
'noun': 'place',
'rels_nargs': [],
}
here = loader.load(obj)
print(dump(here.dump()))
with step('Temporal argument'):
obj = {
'type': 'DeepCommonNoun',
'possessor': None,
'selector': {
'correlative': 'PROX',
'n_min': 'SING',
'n_max': 'SING',
'of_n_min': 'SING',
'of_n_max': 'SING',
},
'number': None,
'attributes': [],
'noun': 'time',
'rels_nargs': [],
}
now = loader.load(obj)
print(dump(now.dump()))
with step('Content clause'):
obj = {
'type': 'DeepContentClause',
'status': 'ACTUAL',
'purpose': 'INFO',
'is_intense': False,
'verb': be.dump(),
'adverbs': [],
'rels_vargs': [
('AGENT', yall.dump()),
('PLACE', here.dump()),
('TIME', now.dump()),
],
'subj_index': 0,
}
clause = loader.load(obj)
print(dump(clause.dump()))
with step('Sentence'):
obj = {
'type': 'DeepSentence',
'root': obj,
}
sentence = DeepSentence.load(obj, loader)
print(dump(sentence.dump()))
with step('Idiolect'):
obj = {
'archaic_pro_adverbs': False,
'contractions': True,
'pedantic_plurals': False,
'stranding': True,
'split_infinitive': True,
'subjunctive_were': True,
'whom': False,
}
idiolect = Idiolect(**obj)
print(dump(idiolect.__dict__))
with step('Result'):
text = english.say(sentence, idiolect)
print('$', text) # "Be here now."