Files
ola5doc/output/sources/pattern__phrase_vers_dot--3-label-pos-longs.py
T

78 lines
2.2 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import imports.arguments as ARG
from pattern.fr import parse, split
texte_brut = ARG.obtenir( '-p', u"Suivez les flèches, attention aux trous." )
texte_traite = parse( texte_brut )
numero_mot = -1
posse = {
"CC" : u"conjonction de coordination",
"CD" : u"nombre cardinal",
"DT" : u"déterminant",
"EX" : u"Existential there",
"FW" : u"mot étranger",
"IN" : u"préposition ou conjonction de subordination",
"JJ" : u"adjectif",
"JJR" : u"adjectif comparatif",
"JJS" : u"adjectif superlatif",
"LS" : u"marqueur d'élément de liste",
"MD" : u"modal",
"NN" : u"nm, singulier ou mass",
"NNS" : u"nom, pluriel",
"NNP" : u"nom propre, singulier",
"NNPS" : u"nom propre, pluriel",
"PDT" : u"predeterminer",
"POS" : u"possessive ending",
"PRP" : u"pronom personnel",
"PRP$" : u"pronom possessif",
"RB" : u"adverbe",
"RBR" : u"adverbe, comparatif",
"RBS" : u"adverbe, superlatif",
"RP" : u"particle",
"SYM" : u"symbole",
}
def imprimer_erreur ( erreur ):
print '💩 erreur : ' + str( erreur )
def demarrer_graphe () :
print 'digraph G {'
print ' graph [ rankdir=LR ];'
def ajouter_noeud_mot ( word, numero ):
print ' ' + str( numero ) + ' [label="' + word.string + '"];'
def ajouter_noeud_type ( word, numero ):
if word.type in posse:
type_pos_label = posse[word.type]
else:
type_pos_label = word.type
type_pos = word.type.replace( '.', 'point' ).replace( ',', 'virgule' )
print ' type__' + str( numero ) + '__' + type_pos + ' [label="' + type_pos_label + '"];'
print ' ' + str( numero ) +' -> type__' + str( numero ) + '__' + type_pos;
def lier_a_noeud_precedent ( numero ):
if ( numero_mot > 0 ):
print ' ' + str( numero - 1 ) + ' -> ' + str ( numero )
def clore_graphe () :
print '}'
demarrer_graphe ()
# pour chaque phrase
for phrase in split( texte_traite ):
# pour chaque mot
for word in phrase.words:
# on incrément le numéro du mot
numero_mot = numero_mot + 1
ajouter_noeud_mot ( word, numero_mot )
ajouter_noeud_type ( word, numero_mot )
lier_a_noeud_precedent ( numero_mot )
clore_graphe ()