commited all contents created by participants
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from pattern.fr import parse, split
|
||||
|
||||
texte_brut = u"Suivez les flèches, attention aux trous.".encode('utf-8')
|
||||
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 ()
|
||||
Reference in New Issue
Block a user