41 lines
1.0 KiB
Python
41 lines
1.0 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"Le petit chat rugit alors que l'esclave humain tarde a accomplir sa tache de nourrissage du maitre et seigneur." )
|
|
texte_traite = parse( texte_brut )
|
|
|
|
numero_mot = -1
|
|
|
|
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 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 )
|
|
lier_a_noeud_precedent ( numero_mot )
|
|
|
|
clore_graphe ()
|