In [1]:
from spacy.en import English
from spacy.symbols import nsubj, VERB
from pattern.en import conjugate, PAST, PRESENT, FUTURE, tenses, SINGULAR, PLURAL, SUBJUNCTIVE, IMPERATIVE
from itertools import tee
import string
from HTMLParser import HTMLParser
from tenseflow import change_tense, get_subjects_of_verb
from tenseflow.utils import pairwise

In [2]:
npl = English()

In [3]:
text = u'The rooms were filled with cupboards and book-shelves.'
doc = npl(text)
print([(x.text, x.tag_, x.dep_, list(x.ancestors)) for x in list(doc.sents)[0]])
change_tense(text,'future')


[(u'The', u'DT', u'det', [rooms, filled]), (u'rooms', u'NNS', u'nsubjpass', [filled]), (u'were', u'VBD', u'auxpass', [filled]), (u'filled', u'VBN', u'ROOT', []), (u'with', u'IN', u'prep', [filled]), (u'cupboards', u'NNS', u'pobj', [with, filled]), (u'and', u'CC', u'cc', [cupboards, with, filled]), (u'book', u'NN', u'compound', [shelves, cupboards, with, filled]), (u'-', u'HYPH', u'punct', [shelves, cupboards, with, filled]), (u'shelves', u'NNS', u'conj', [cupboards, with, filled]), (u'.', u'.', u'punct', [filled])]
Out[3]:
u'The rooms will be filled with cupboards and book- shelves.'

In [7]:
text = u'The will says otherwise.'
doc = npl(text)
print([(x.text, x.tag_, x.dep_, list(x.ancestors)) for x in list(doc.sents)[0]])
change_tense(text,'future')


[(u'The', u'DT', u'det', [will, says]), (u'will', u'NN', u'nsubj', [says]), (u'says', u'VBZ', u'ROOT', []), (u'otherwise', u'RB', u'advmod', [says]), (u'.', u'.', u'punct', [says])]
Out[7]:
u'The will say otherwise.'

In [6]:
text = u'I will be filled.'
doc = npl(text)
print([(x.text, x.tag_, x.dep_, list(x.ancestors)) for x in list(doc.sents)[0]])
change_tense(text,'future')


[(u'I', u'PRP', u'nsubjpass', [filled]), (u'will', u'MD', u'aux', [filled]), (u'be', u'VB', u'auxpass', [filled]), (u'filled', u'VBN', u'ROOT', []), (u'.', u'.', u'punct', [filled])]
Out[6]:
u'I will be fill.'

In [28]:
text = u'The rooms were filled with cupboards and book-shelves.'
doc = npl(text)
tok = [x for x in list(doc.sents)[0] if x.text == 'filled'][0]
tok.dep_


Out[28]:
u'ROOT'

In [28]:
aa = conjugate('will', tense=PRESENT, person=3, number=SINGULAR, negated=True)
aa


Out[28]:
u"won't"

In [7]:
text = u'I have gone to the store.'
doc = npl(text)
print([(x.text, x.tag_, x.dep_) for x in list(doc.sents)[0]])
change_tense(text,'past')


[(u'I', u'PRP', u'nsubj'), (u'have', u'VBP', u'aux'), (u'gone', u'VBN', u'ROOT'), (u'to', u'IN', u'prep'), (u'the', u'DT', u'det'), (u'store', u'NN', u'pobj'), (u'.', u'.', u'punct')]
Out[7]:
u'I had went to the store.'

In [12]:
text = u'I will have lived.'
doc = npl(text)
print([(x.text, x.tag_) for x in list(doc.sents)[0]])
change_tense(text,'future')


[(u'I', u'PRP'), (u'will', u'MD'), (u'have', u'VB'), (u'lived', u'VBN'), (u'.', u'.')]
Out[12]:
u'I will live.'

In [9]:
text = u'I will have five cookies.'
doc = npl(text)
print([(x.text, x.tag_) for x in list(doc.sents)[0]])
change_tense(text,'future')


[(u'I', u'PRP'), (u'will', u'MD'), (u'have', u'VB'), (u'five', u'CD'), (u'cookies', u'NNS'), (u'.', u'.')]
Out[9]:
u'I will five cookies.'

In [13]:
a = conjugate('do',tense=PAST, person=3, number=SINGULAR)
a


Out[13]:
u'did'

In [5]:
doc = npl(u'The will says otherwise.')

In [4]:
change_tense('The will says otherwise.','future')


Out[4]:
u'The will say otherwise.'

In [6]:



Out[6]:
[(u'The', u'DT'),
 (u'did', u'VBD'),
 (u'say', u'VB'),
 (u'otherwise', u'RB'),
 (u'.', u'.')]

In [8]:


In [16]:
tok.vocab


Out[16]:
<spacy.vocab.Vocab at 0x1190d0830>

In [ ]: