un-premier-essai-avec-pattern~20171216-160720.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # coding:utf-8
  2. from pattern.fr import parse, split
  3. texte = parse(u"Le chat joue au tennis.")
  4. def imprimer_structure_mot ( mot ):
  5. '''imprime la structure de la phrase'''
  6. print 'index : ' + str( mot.index )
  7. print 'string : ' + str( mot.string )
  8. print '_custom_tags : ' + str( mot._custom_tags )
  9. print 'sentence : ' + str( mot.sentence )
  10. print 'pnp : ' + str( mot.pnp )
  11. print 'chunk : ' + str( mot.chunk )
  12. print 'lemma : ' + str( mot.lemma )
  13. print 'type : ' + str( mot.type )
  14. for phrase in split( texte ):
  15. print "——————————"
  16. print "mots :"
  17. print phrase.words
  18. print "——————————"
  19. print "groupes de mots :"
  20. print phrase.chunks
  21. print "——————————"
  22. print "structure, phrase :"
  23. print phrase.__dict__.keys()
  24. print "——————————"
  25. print "structure, mot :"
  26. print phrase.words[0].__dict__.keys()
  27. print "——————————"
  28. print "structure, chunk (groupe de mots) :"
  29. print phrase.chunks[0].__dict__.keys()
  30. '''
  31. for mot in phrase.words:
  32. # print mot.__dict__.keys()
  33. print "---"
  34. imprimer_structure_mot( mot )
  35. # imprimer_la_structure_de_la_phrase( phrase.words[0] )
  36. '''