Hello,
I wrote a module to use the Part of Speech Tagger Hunpos in web2py.
The module takes a text file tokenized as one token (word) per line as input and perfectly creates and writes into another text file with one token and its POS (Part of Speech) Tag separated with a tab character in one line.
Here is a part of my output file to give an idea how it looks:
Literature NN
gives VBZ
a DT
form NN
to TO
life NN
, ,
helps VBZ
us PRP
to TO
know VB
who WP
we PRP
are VBP
, ,
how WRB
we PRP
feel VBP
and CC
what WP
is VBZ
the DT
point NN
of IN
the DT
whole JJ
unutterably JJ
rummy NN
business NN
. .
When I try to open and read from the output file and write the items inside into the mysql database it simply does not insert the items.
Here is the part of my code that I used for database insertion:
...
# Write to database
with io.open(outfile, 'r') as ffile:
id_list = []
for line in ffile:
if not line.isspace():
pt = line.split('\t')
_id = db.en_pos_analysis.insert(token=pt[0],postag=pt[1])
id_list.append(_id)
print 'POS Tagging completed'
return
I used the same syntax in other modules of the program before and there was no problem inserting in the database.
Thanks in advance.