import nltk
import pdb
import sys
import re
from nltk import *

class RulesGenerator:
  def __init__(self, grammarFile, sentencesFile):
    self.grammarFile   = grammarFile
    self.sentencesFile = sentencesFile

    self.loadGrammar()
    self.loadSentences()

  def loadGrammar(self):
    with open(self.grammarFile, 'r') as f:
      my_grammar = grammar.FeatureGrammar.fromstring(f.read())
      self.parser = nltk.FeatureEarleyChartParser(my_grammar)

  def loadSentences(self):
    with open(self.sentencesFile, 'r') as f:
      self.sentences = f.readlines()

  def generateRules(self, outputFile):
    with open(outputFile, 'w') as f:
      for sentence in self.sentences:
        if sentence.startswith('#'): continue

        sanitizedSentence = re.sub(r'(\.|\,|\')', ' ', sentence).lower()
        sys.stdout.write(sanitizedSentence)

        trees = self.parser.parse(sanitizedSentence.split())
        for tree in trees:
          print(tree)
          print(tree.label()['SEM'])
          tree.draw()

  def writeRule(self, f, tree):
    #sem = tree.label()['SEM']
    pass

if __name__ == '__main__':
  generator = RulesGenerator('grammaire.cfg', 'texte.txt')
  generator.generateRules('out.clp')

@@ -37,16 +37,35 @@
 port re%0A
+import unicodedata%0A
 from nlt
@@ -771,51 +771,38 @@
 e = 
-re.sub(r'(%5C.%7C%5C,%7C%5C')', ' ', sentence).lower(
+self.sanitizeSentence(sentence
 )%0A  
@@ -991,16 +991,16 @@
 'SEM'%5D)%0A
-
         
@@ -1010,24 +1010,292 @@
 ree.draw()%0A%0A
+  def sanitizeSentence(self, sentence):%0A    sanitizedSentence = re.sub(r'(%5C.%7C%5C,%7C%5C')', ' ', sentence).lower()%0A    sanitizedSentence = ''.join((c for c in unicodedata.normalize('NFD', sanitizedSentence) if unicodedata.category(c) != 'Mn'))%0A    return sanitizedSentence%0A%0A
   def writeR

Remove diacritics on sentence