plint

French poetry validator (local mirror of https://gitlab.com/a3nm/plint)
git clone https://a3nm.net/git/plint/
Log | Files | Refs | README

posplay.py (1323B)


      1 #!/usr/bin/python3
      2 # -*- coding: utf-8
      3 
      4 import os
      5 from common import normalize
      6 from nltk.tag.stanford import POSTagger
      7 from pprint import pprint
      8 
      9 def postag(l):
     10   l2 = []
     11   idxes = []
     12   for (b, w, a) in l:
     13     for i, x in enumerate([b, w, a]):
     14       if (i == 1):
     15        idxes.append(len(l2))
     16       if (len(x.strip()) > 0) or i == 1:
     17         l2.append(x)
     18   tags = st.tag(l2)
     19   l3 = []
     20   for idx in idxes:
     21     l3.append(tags[idx][1])
     22   #pprint(l)
     23   #pprint(tags)
     24   #pprint(l3)
     25   return l3
     26 
     27 os.environ['JAVAHOME'] = '/usr/bin'
     28 # depends on http://nltk.org/nltk3-alpha/ and stanfond pos tagger
     29 # st = POSTagger('stanford-postagger-full-2013-11-12/models/english-bidirectional-distsim.tagger', 'stanford-postagger-full-2013-11-12/stanford-postagger.jar')
     30 st = POSTagger('stanford-postagger-full-2013-11-12/models/french.tagger',
     31 'stanford-postagger-full-2013-11-12/stanford-postagger.jar', encoding='utf-8')
     32 x = "Rome à qui vient ton bras d' immoler mon amant".split()
     33 print( st.tag(x))
     34 #x = "L' autre mime en riant l' infirme qui volait".split()
     35 #print( st.tag(x))
     36 #x = "Quelle est la vitesse aérienne d' une hirondelle à vide ?".split()
     37 #x = "La souffleuse, , , l'hindoue, elle a lentement péché, l' autre l autre l'autre la belle lésine,".split()
     38 #print( st.tag('What is the airspeed of an unladen swallow ?'.split()))