12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- from pattern.fr import parse, split
- texte_brut = u"Le petit chat rugit alors que l'esclave humain tarde a accomplir sa tache de nourrissage du maitre et seigneur.".encode('utf-8')
- texte_traite = parse( texte_brut )
- def imprimer_erreur ( erreur ):
- print '💩 erreur : ' + str( erreur )
- def imprimer_structure_mot ( mot ):
- '''imprime la structure de la phrase'''
- print 'index : ' + str( mot.index )
- print 'string : ' + str( mot.string )
- print '_custom_tags : ' + str( mot._custom_tags )
- print 'sentence : ' + str( mot.sentence )
- print 'pnp : ' + str( mot.pnp )
- print 'chunk : ' + str( mot.chunk )
- print 'lemma : ' + str( mot.lemma )
- print 'type : ' + str( mot.type )
- for phrase in split( texte_traite ):
- print "——————————"
- print "mots :"
- try:
- print phrase.words
- except Exception as erreur:
- imprimer_erreur( erreur )
- print "——————————"
- print "groupes de mots :"
- try:
- print str(phrase.chunks)
- except Exception as erreur:
- imprimer_erreur( erreur )
- print "——————————"
- print "structure, phrase :"
- try:
- print phrase.__dict__.keys()
- except Exception as erreur:
- imprimer_erreur( erreur )
- print "——————————"
- print "structure, mot :"
- try:
- print phrase.words[0].__dict__.keys()
- except Exception as erreur:
- imprimer_erreur( erreur )
- print "——————————"
- print "structure, chunk (groupe de mots) :"
- print phrase.chunks[0].__dict__.keys()
|