예제 #1
0
    def __init__(self, target_tree, features):
        """
        constructor: Automate
        input:
                                                                        target_tree = Arbre objectif contenue dans un Tree
                                                                        features = liste des features à prendre en compte pour construire une configuration
        Initialise un automate avec les mots de la phrase
        labels est la liste des different labels de la phrase
        """
        sentence = list()
        self.name = list()
        for vt in target_tree.vertices:
            sentence.append(vt.get_word())

        Automate.__init__(self, None, None, sentence)
        self.target_tree = target_tree

        self.labels = list()
        for word in sentence:
            # print(word.getFeat('FORM'),'\t',word.getFeat('LABEL'))
            l = word.getFeat('LABEL')
            self.name = word.getFeat('FORM')  # pour voir la phrase
            if l is not None:  # Si l n'est pas liée au root
                if l not in self.labels:  # Si l n'est pas déjà dans la liste
                    self.labels.append(l)
        # print(self.labels)

        self.features = features
예제 #2
0
 def __init__(self):
     self.minIDLength = 8
     self.constantAutomate = Automate('config_real.json')
     self.IDAutomate = Automate('config_variabila.json')
     self.reserved = {}
     with open('config.yml') as file:
         self.reserved = yaml.load(file, Loader=yaml.FullLoader)
예제 #3
0
 def post(self):
     data = request.data
     params = request.args
     classId = params["class"]
     df = pd.read_json(data)
     auto = Automate(models)  # Generate a Class
     auto.split_dataframe(df)
     # auto.gridsearchSVM()
     json = {}
     json["crossvalidate"] = auto.get_cross_validation(20)  # 20 fold
     #auto.binarize()
     #auto.split_test_train()
     #json["runtime"] = auto.train_models()
     #json["accuracy"] = auto.get_accuracy()
     #json["precision-recall"] = auto.get_precision_recall()
     #json["roc"] = auto.get_roc()
     return json, 201
예제 #4
0
파일: app.py 프로젝트: daviddao/luminosity
 def post(self):
     data = request.data
     params = request.args
     classId = params["class"]
     df = pd.read_json(data)
     auto = Automate(models) # Generate a Class
     auto.split_dataframe(df)
     # auto.gridsearchSVM()
     json = {}
     json["crossvalidate"] = auto.get_cross_validation(20) # 20 fold
     #auto.binarize()
     #auto.split_test_train()
     #json["runtime"] = auto.train_models()
     #json["accuracy"] = auto.get_accuracy()
     #json["precision-recall"] = auto.get_precision_recall()
     #json["roc"] = auto.get_roc()
     return json, 201
예제 #5
0
파일: main.py 프로젝트: nmhjoyal/LOG2810
def main():

    try:
        automate = Automate("lexique6.txt")

        automate.findWords("abces")
        automate.findWords("abces")
        automate.findWords("abces")
        automate.findWords("abces")
        automate.findWords("abces")
        automate.findWords("abces")
        print(automate.findWords("abc"))

        print(automate.getLabel()[0])
        print(automate.getLabel()[1])

    except IOError:
        print("\nERREUR : Nom de fichier erroné")
    except ValueError:
        print("\nERREUR : Mot cherché n'existe pas dans ce lexique")
    except TypeError:
        print("\nERREUR : Mot de type inconnu")
예제 #6
0
def result():
    """
    usage:
    .../allAttemptedResults?rollno=<>&course=<>&regulation=<>

    eg:
    .../allAttemptedResults?rollno=163g1a0505&course=b.tech&regulation=r15

    """
    rollno = request.args.get('rollno')
    course = request.args.get('course')
    regulation = request.args.get('regulation')
    regulation = regulation.upper()
    tmp = course[0:3]
    t = tmp.upper()
    course = t + course[3:]
    regulation = regulation.upper()
    print(rollno, course, regulation)

    x = Automate(rollno=rollno, course=course, regulation=regulation)

    data = x.start()
    return data
예제 #7
0
class WindowsFrame(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initUI()
        self.automate = Automate()

    def initUI(self):
        self.textEdit = QTextEdit()
        self.textEdit.setReadOnly(True)
        self.setCentralWidget(self.textEdit)
        self.statusBar()

        reconnuAction = QAction(QIcon('reconnu.png'), '&Reconnaitre', self)
        reconnuAction.setShortcut('Ctrl+R')
        reconnuAction.setStatusTip('Reconnaire une texte')
        reconnuAction.triggered.connect(self.reconnu)

        epsilonAction = QAction(QIcon('epsilon.png'),
                                '&Remove Epsilon TranSition', self)
        epsilonAction.setShortcut('Ctrl+E')
        epsilonAction.setStatusTip('Enlever les transitions spontanées')
        epsilonAction.triggered.connect(self.epsilon)

        determiniserAction = QAction(QIcon('determiniser.png'),
                                     '&Determiniser', self)
        determiniserAction.setShortcut('Ctrl+D')
        determiniserAction.setStatusTip('Determiniser cette automate')
        determiniserAction.triggered.connect(self.determiniser)

        minimiserAction = QAction(QIcon('minimiser.png'), '&Minimiser', self)
        minimiserAction.setShortcut('Ctrl+M')
        minimiserAction.setStatusTip('minimiser cette automate')
        minimiserAction.triggered.connect(self.minimiser)

        openAction = QAction(QIcon('open.png'), '&Open', self)
        openAction.setShortcut('Ctrl+O')
        openAction.setStatusTip('Opne File')
        openAction.triggered.connect(self.showOpenDialog)

        saveAction = QAction(QIcon('save.png'), '&Save', self)
        saveAction.setShortcut('Ctrl+S')
        saveAction.setStatusTip('Save File')
        saveAction.triggered.connect(self.showSaveDialog)

        exitAction = QAction(QIcon('exit.png'), '&Exit', self)
        exitAction.setShortcut('Ctrl+Q')
        exitAction.setStatusTip('Exit application')
        exitAction.triggered.connect(self.close)

        self.statusBar().showMessage('Ready')

        menubar = self.menuBar()
        fileMenu = menubar.addMenu('&File')
        fileMenu.addAction(openAction)
        fileMenu.addAction(saveAction)
        fileMenu.addAction(exitAction)

        self.toolbar = self.addToolBar('open')
        self.toolbar.addAction(openAction)
        self.toolbar.addAction(saveAction)
        self.toolbar.addAction(epsilonAction)
        self.toolbar.addAction(determiniserAction)
        self.toolbar.addAction(minimiserAction)
        self.toolbar.addAction(reconnuAction)

        self.setGeometry(300, 300, 250, 150)
        self.setWindowTitle('Statusbar')
        self.show()

    def showOpenDialog(self):
        fname = QFileDialog.getOpenFileName(self, 'Open file', '../res')

        if fname[0]:
            self.automate = automate.openXML(fname[0])[0]
            self.textEdit.setText(self.automate.__str__())

    def showSaveDialog(self):
        fname = QFileDialog.getSaveFileName(self, 'Open file', '../res')

        self.automate.export_XML(fname[0])

    def epsilon(self):
        self.automate.getNFA()
        self.textEdit.setText(self.automate.__str__())

    def determiniser(self):
        self.automate.determiniser()
        self.textEdit.setText(self.automate.__str__())

    def minimiser(self):
        self.automate.minimiser()
        self.textEdit.setText(self.automate.__str__())

    def reconnu(self):
        dialog = Dialog(parent=self)
        if dialog.exec_():
            self.model.appendRow((
                QtGui.QStandardItem(dialog.name()),
                QtGui.QStandardItem(str(dialog.age())),
            ))

            dialog.destroy()
예제 #8
0
def allUrls():
    x = Automate.getAllUrls()
    x = x[7:-5]
    return jsonify(x)
예제 #9
0
def allResults():
    data = Automate.getPublishedResults()
    return jsonify({
        'published_results': data
    })
예제 #10
0
from state import State
from transition import Transition
from parser import *

print("DEBUT PROGRAMME\n")

s1=State(1, True, True)
s2=State(2, False, False)
t1= Transition(s1,"a",s1)
t2=Transition(s1,"a",s2)
t4=Transition(s2,"a", s2)
t5=Transition(s2,"b",s2)
t6= Transition(s1,"a",s1)
t7= Transition(s2,"b",s1)
listeT1 = [t1,t2,t4,t5,t6,t7]
a=Automate(listStates=[], label="a", listTransitions=listeT1)
print(a)


s3=State(1,True,False)
s4=State(2,False,True)

tb1= Transition(s3,"b",s3)
tb2= Transition(s3,"a",s4)
tb3= Transition(s4,"b",s4)
tb4= Transition(s4,"c",s3)
tb5 = Transition(s3,"b",s4)
listeT2 = [tb1,tb2,tb3,tb4,tb5]
b=Automate(listStates=[s3,s4], label= "b", listTransitions = listeT2)
print(b)
예제 #11
0
def main():
    ### EXERCICE 2
    # Création des états et des transitions
    s0 = State(0, True, False)
    s1 = State(1, False, False)
    s2 = State(2, False, True)
    t1 = Transition(s0, "a", s1)
    t2 = Transition(s0, "b", s1)
    t3 = Transition(s1, "a", s2)
    t4 = Transition(s1, "b", s2)
    t5 = Transition(s2, "a", s0)
    t6 = Transition(s2, "b", s1)

    # On crée l'automate 0 à partir de transitions
    auto = Automate([t1, t2, t3, t4, t5, t6])
    print(auto)
    # On crée l'automate 1 à partir de transitions et d'états (auto et auto1 sont identiques)
    auto1 = Automate([t1, t2, t3, t4, t5, t6], [s0, s1, s2])
    print(auto1)
    # On crée l'automate 2 à partir d'un fichier
    auto2 = Automate.creationAutomate("exempleAutomate.txt")
    print(auto2)
    """# On print l'automate 0 dans un pdf
    auto.show("auto_ListeTrans")
    # On print l'automate 0 dans un pdf
    auto1.show("auto1_ListeTrans")
    # On print l'automate 0 dans un pdf
    auto2.show("auto2_ListeTrans")"""

    # TRAVAIL SUR L'AUTOMATE 0
    # On supprime une transition (t1) et on affiche le résultat
    auto.removeTransition(t1)
    print(auto)
    # On rajoute la transition supprimée et on affiche le résultat
    auto.addTransition(t1)
    print(auto)
    # On supprime l'état 1 (s1) de l'automate 0 et on affiche le résultat
    auto.removeState(s1)
    print(auto)
    # On ajoute l'état 1 (s1) de l'automate 0 et on affiche le résultat
    auto.addState(s1)
    print(auto)
    # On affiche les transitions de l'automate 0
    print(auto.getListTransitionsFrom(s1))
    print()

    ### EXERCICE 3
    # On récupère l'automate auto1 pour effectuer les tests
    print("\nTest de la fonction succ sur auto1\n")
    print(auto1.succ([s0, s1, s2], "a"))
    print()

    # On vérifie si un mot est accepté ou non par l'automate auto1
    print("\nLes mots sont-ils acceptés par auto1\n")
    print("L'automate auto1 accepte-t-il le mot '' : " +
          str(Automate.accepte(auto1, "")))
    print("L'automate auto1 accepte-t-il le mot 'aababaabbba' : " +
          str(Automate.accepte(auto1, "aababaabbba")))
    print()

    # On vérifie si les automates auto1 et auto2 sont complets
    print("\nLes automates sont-ils complets ?\n")
    print("L'automate auto1 est-il complet : " +
          str(Automate.estComplet(auto1, auto1.getAlphabetFromTransitions())))
    print("L'automate auto2 est-il complet : " +
          str(Automate.estComplet(auto2, auto2.getAlphabetFromTransitions())))
    print()

    # On vérifie si les automates auto1 et auto2 sont déterministes
    print("Les automates sont-ils déterministes ?\n")
    print("L'automate auto1 est-il déterministe : " +
          str(Automate.estDeterministe(auto1)))
    print("L'automate auto2 est-il déterministe : " +
          str(Automate.estDeterministe(auto2)))
    print()

    # On complète l'automate auto2
    #auto2.show("Avant_la_completion.pdf")
    new_auto2 = Automate.completeAutomate(copy.deepcopy(auto2),
                                          auto2.getAlphabetFromTransitions())
    #new_auto2.show("Apres_la_completion.pdf")

    ss0 = State(0, True, False)
    ss1 = State(1, True, False)
    ss2 = State(2, False, False)
    ss3 = State(3, False, True)
    tt1 = Transition(ss0, "a", ss0)
    tt2 = Transition(ss0, "b", ss0)
    tt3 = Transition(ss0, "b", ss1)
    tt4 = Transition(ss1, "a", ss2)
    tt5 = Transition(ss2, "b", ss3)

    # On effectue des tests avec la fonction complementaire
    autotest = Automate([tt1, tt2, tt3, tt4, tt5])
    print(autotest)
    #autotest.show("autotest_avant_comp")
    new_autotest2 = Automate.complementaire(
        autotest, autotest.getAlphabetFromTransitions())
    print(new_autotest2)
    #new_autotest2.show("resulat_comp")

    # On effectue des tests sur un automate provenant d'un sujet de partiel
    print("\nTest sur l'examen\n")
    so1 = State(1, True, False)
    so2 = State(2, False, False)
    so3 = State(3, False, True)
    to1 = Transition(so1, "a", so1)
    to2 = Transition(so1, "a", so2)
    to3 = Transition(so2, "a", so3)
    to4 = Transition(so2, "b", so2)
    to5 = Transition(so3, "b", so3)
    to6 = Transition(so3, "b", so2)
    to7 = Transition(so3, "a", so1)

    auto3 = Automate([to1, to2, to3, to4, to5, to6, to7], [so1, so2, so3])
    print(auto3)
    #auto3.show("Automate_Examen")
    print("\nL'automate auto3 est-il complet ? " +
          str(Automate.estComplet(auto3, auto3.getAlphabetFromTransitions())) +
          "\n")
    auto3_comp = Automate.completeAutomate(copy.deepcopy(auto3),
                                           auto3.getAlphabetFromTransitions())
    print("\nL'automate auto3_comp est-il complet ? " + str(
        Automate.estComplet(auto3_comp,
                            auto3_comp.getAlphabetFromTransitions())) + "\n")
    #auto3_comp.show("Automate_Examen_Complété")

    auto3_n = Automate([to1, to2, to3, to4, to5, to6, to7], [so1, so2, so3])
    print("\nL'automate auto3_n est-il déterministe ? " +
          str(Automate.estDeterministe(auto3_n)) + "\n")
    auto3_det = Automate.determinisation(auto3_n)
    print("\nL'automate auto3_det est-il déterministe ? " +
          str(Automate.estDeterministe(auto3_det)) + "\n")
    #auto3_det.show("Automate_Examen_Determinise")

    print("\nL'automate complémentaire de l'automate auto3 de base\n")
    auto3_complementaire = Automate.complementaire(
        copy.deepcopy(auto3),
        copy.deepcopy(auto3).getAlphabetFromTransitions())
    print(auto3_complementaire)
    #auto3_complementaire.show("post_complementaire")

    # On utilise la fonction de concatenation entre deux automates
    prime1 = State(0, True, False)
    prime2 = State(1, False, True)
    prime3 = State(2, True, False)
    prime4 = State(3, False, True)

    tprime1 = Transition(prime1, "a", prime2)
    tprime2 = Transition(prime2, "b", prime2)
    tprime3 = Transition(prime3, "c", prime3)
    tprime4 = Transition(prime3, "a", prime4)

    auto_exam1 = Automate([tprime1, tprime2])
    auto_exam2 = Automate([tprime3, tprime4])

    auto_exam_c = Automate.concatenation(auto_exam1, auto_exam2)
    print(auto_exam_c)

    # On utilise la fonction d'union entre deux automates
    st1 = State(1, True, False)
    st2 = State(2, False, True)
    tr1 = Transition(st1, "a", st1)
    tr2 = Transition(st1, "b", st2)
    tr3 = Transition(st2, "a", st2)
    auto_st_tr1 = Automate([tr1, tr2, tr3])

    st3 = State(3, True, False)
    st4 = State(4, False, True)
    tr4 = Transition(st3, "a", st4)
    tr5 = Transition(st3, "b", st4)
    tr6 = Transition(st3, "c", st4)
    tr7 = Transition(st4, "a", st4)
    auto_st_tr2 = Automate([tr4, tr5, tr6, tr7])

    auto_test_union = Automate.union(copy.deepcopy(auto_st_tr1),
                                     copy.deepcopy(auto_st_tr2))
    print(auto_test_union)

    # On utilise la fonction d'intersection entre deux automates

    auto_test_intersection = Automate.intersection(copy.deepcopy(auto_st_tr1),
                                                   copy.deepcopy(auto_st_tr2))
    print(auto_test_intersection)
예제 #12
0
class Analyser:
    '''
        Incarca dictionarul mlp c++
    '''
    def __init__(self):
        self.minIDLength = 8
        self.constantAutomate = Automate('config_real.json')
        self.IDAutomate = Automate('config_variabila.json')
        self.reserved = {}
        with open('config.yml') as file:
            self.reserved = yaml.load(file, Loader=yaml.FullLoader)

    '''
        Analizeaza codul de pe fiecare linie primita din codul sursa
    '''

    def analyse(self, lines):
        self.code = []
        self.errors = []
        # print()
        # print(self.reserved)
        contorL = 1
        for uLine in lines:
            line = uLine.strip('\t \n ').split(' ')
            for atom in line:
                if not self.analyseAtom(atom):
                    self.errors.append((atom, contorL))
            contorL += 1

    '''
        Analizeaza un atom cautand din ce categorie face parte
    '''

    def analyseAtom(self, atom):
        if atom == '':
            return True
        if atom in self.reserved.keys():
            self.code.append((atom, self.reserved[atom]))
            return True
        elif self.IDAutomate.verifySequence(
                atom) and len(atom) < self.minIDLength:  #identificator ID
            self.code.append((atom, self.reserved['ID']))
            return True
        elif self.constantAutomate.verifySequence(atom):  #identificator CONST
            self.code.append((atom, self.reserved['CONST']))
            return True
        elif self.isComposed(atom):
            return True
        return False

    '''
        Analizeaza daca atomul este compus (fara spatii)
    '''

    def isComposed(self, atom):
        for x in self.reserved.keys():
            pos = atom.find(x)
            if (pos != -1):
                atomFound = atom[pos:pos + len(x)]
                left = atom[:pos]
                right = atom[pos + len(x):]
                resultLeft = self.analyseAtom(left)
                self.code.append((atomFound, self.reserved[atomFound]))
                return resultLeft and self.analyseAtom(right)
        return False
예제 #13
0
파일: test.py 프로젝트: romanethoirey/Logic
from automate import Automate

#2.1 Creation d'automates
#1.
s0 = State(0, True, False)
s1 = State(1, False, False)
s2 = State(2, False, True)

t1 = Transition(s0, "a", s0)
t2 = Transition(s0, "b", s1)
t3 = Transition(s1, "a", s2)
t4 = Transition(s1, "b", s2)
t5 = Transition(s2, "a", s0)
t6 = Transition(s2, "b", s0)

autom = Automate([t1, t2, t3, t4, t5, t6])
#print(autom)
#autom.show("A_ListeTrans")

#2.
auto1 = Automate([t1, t2, t3, t4, t5, t6], [s0, s1, s2])
#print(auto1)
#auto1.show("A_ListeTrans")

#les automates sont identiques

#3.

auto2 = Automate.creationAutomate("auto.txt")
#print(auto2)
#auto2.show("A_ListeTrans")
예제 #14
0
from automate import Automate
from state import State
from transition import Transition
from parser import *

print "\n|Testons les méthodes de la classe Automate|\n"

## On crée les deux atomates de tests

## Préparations pour la création de l'automate a
s = State(1, False, False)
s2 = State(1, True, False)
t = Transition(s, "a", s)
t2 = Transition(s, "a", s2)
s.insertPrefix(2)
a = Automate([t, t2])
a.prefixStates(3)
s1 = State(1, True, False)
s2 = State(2, False, True)
t1 = Transition(s1, "a", s1)
t2 = Transition(s1, "a", s2)
t3 = Transition(s1, "b", s2)
t4 = Transition(s2, "a", s2)
t5 = Transition(s2, "b", s2)
liste = [t1, t2, t3, t4, t5]
## Création de l'automate a
a = Automate(listStates=[], label="a", listTransitions=liste)
## Traitements sur l'automate a (modifications)
a.prefixStates(0)
a.removeTransition(t5)
a.removeTransition(t5)
예제 #15
0
from automate import Automate
from state import State
from transition import Transition

print("\nFabrication des automates . . .\n")

# auto1
s0_1 = State(0, True, True)
s1_1 = State(1, False, False)
t1_1 = Transition(s0_1, "a", s0_1)
t2_1 = Transition(s0_1, "b", s1_1)
t3_1 = Transition(s1_1, "a", s1_1)
t4_1 = Transition(s1_1, "b", s0_1)
trans1 = [t1_1, t2_1, t3_1, t4_1]
auto1 = Automate(trans1, label="auto1")

# auto2
s0_2 = State(0, True, False)
s1_2 = State(1, False, True)
t1_2 = Transition(s0_2, "b", s0_2)
t2_2 = Transition(s0_2, "a", s1_2)
t3_2 = Transition(s1_2, "b", s1_2)
t4_2 = Transition(s1_2, "a", s0_2)
trans2 = [t1_2, t2_2, t3_2, t4_2]
auto2 = Automate(trans2, label="auto2")

# auto3
s1_3 = State(1, True, False)
s2_3 = State(2, False, False)
s3_3 = State(3, False, True)
예제 #16
0
파일: exo1.py 프로젝트: elhaouajihiba/maths
# t4 : Transition
t4 = Transition(s1,"b",s2)
# t5 : Transition
t5 = Transition(s2,"a",s0)
# t6 : Transition
t6 = Transition(s2,"b",s1)

# liste_trans : list[Transition]
liste_trans = [t,t1,t2,t3,t4,t5,t6]

# liste_etats : list[State]
liste_etats = [s0,s1,s2]

## creation de l’automate
# auto : Automate
auto = Automate(liste_trans)

# auto1 : Automate
auto1 = Automate(liste_trans, liste_etats)

# auto2 : Automate
auto2 = Automate.creationAutomate("auto.txt")


print(auto)
auto.show("exo1")

#print(auto1)
#auto1.show("exo1_2")

#print(auto2)
예제 #17
0
파일: main.py 프로젝트: UgoMou/Projets
#import projet
s0 = State(0, True, False)
s1 = State(1, False, False)
s2 = State(2, False, True)
t1 = Transition(s0, 'a', s0)
t2 = Transition(s0, 'b', s1)
t3 = Transition(s1, 'a', s2)
t4 = Transition(s1, 'b', s2)
t5 = Transition(s2, 'a', s0)
t6 = Transition(s2, 'b', s1)
L = [t1, t2, t3, t4, t5, t6]
#auto=Automate(L)

print(" -auto est l'automate suivant : ")
autoB = Automate.creationAutomate("tripleA.txt")
autoA = Automate.creationAutomate("auto.txt")
#autoA.show('autoA')
#autoB.show('autoB')

#print(autoA)
#print(autoB)
"""Cet automate est complet et déterministe
On test maintenant la fonction succ avec a,b et c (sachant qu'auto2 ne contient pas de transition c
"""

print "\n TEST SUCC \n"

print('# test succ pour autoA.succ(auto2.listStates,"a") : ')
print(autoA.succ(autoA.listStates, "a"))
예제 #18
0
 def __init__(self):
     super().__init__()
     self.initUI()
     self.automate = Automate()
예제 #19
0
# t1 : Transition
t1 = Transition(s0,"a",s0)
# t2 : Transition
t2 = Transition(s0,"b",s1)
# t3 : Transition 
t3 = Transition(s1,"a",s2)
# t4 : Transition
t4 = Transition(s1,"b",s2)
# t5 : Transition
t5 = Transition(s2,"a",s0)
# t6 : Transition
t6 = Transition(s2,"b",s1)

## création de l'automate
# auto,auto1 : Automate
auto = Automate([t1,t2,t3,t4,t5,t6])
auto1 = Automate([t1,t2,t3,t4,t5,t6],[s0,s1,s2])

print(auto)
auto.show("A_ListeTrans")
print(auto1)
auto1.show("A1_ListeTrans")
## auto est bien indentique à auto1

# auto2 : Automate
auto2 = Automate.creationAutomate("auto2.txt")
print(auto2)
auto2.show("A2_listeTrans")

# t : Transition
t = Transition(s0,"a",s1)
예제 #20
0
            l1.remove(e)
            l2.remove(e)
            return equalList(l1,l2)
        else:
            return False

#####
# Définition des différents automates de test
#####

# auto1 reconnait les mots sur {a,b} ayant un nombre impair de a 
# Déterministe/Complet

s01 = State(0,True,False)
s11 = State(1,False,True)
auto1 = Automate([Transition(s01,'b',s01),Transition(s01,'a',s11),Transition(s11,'b',s11),Transition(s11,'a',s01)])

# auto2 reconnait les mots de la forme a*b*
# Déterministe/Non Complet

s02 = State(0,True,True)
s12 = State(1,False,True)
auto2 = Automate([Transition(s02,'a',s02),Transition(s02,'b',s12),Transition(s12,'b',s12)])

# auto3 (exemple dans le sujet) reconnait les mots avec 3 a consécutifs
# ND/NC

s03 = State(0,True,False)
s13 = State(1,False,False)
s23 = State(2,False,False)
s33 = State(3,False,True)
예제 #21
0
print("DEBUT PROGRAMME\n")

# Automate A0
s_a0_0 = State(0, True, True)
s_a0_1 = State(1, False, False)
s_a0_2 = State(2, False, False)
s_a0_3 = State(3, False, False)
t_a0_1 = Transition(s_a0_0, "b", s_a0_0)
t_a0_2 = Transition(s_a0_0, "c", s_a0_0)
t_a0_3 = Transition(s_a0_0, "a", s_a0_1)
t_a0_4 = Transition(s_a0_1, "b", s_a0_2)
t_a0_5 = Transition(s_a0_2, "c", s_a0_3)
t_a0_6 = Transition(s_a0_3, "b", s_a0_0)
lt_a0 = [t_a0_1, t_a0_2, t_a0_3, t_a0_4, t_a0_5, t_a0_6]
aut0 = Automate(lt_a0)
# Automate A1
s_a1_0 = State(0, True, False)
s_a1_1 = State(1, False, False)
s_a1_2 = State(2, False, True)
t_a1_0 = Transition(s_a1_0, "a", s_a1_1)
t_a1_1 = Transition(s_a1_1, "a", s_a1_0)
t_a1_2 = Transition(s_a1_1, "b", s_a1_2)
t_a1_3 = Transition(s_a1_2, "b", s_a1_2)
lt_a1 = [t_a1_0, t_a1_1, t_a1_2, t_a1_3]
aut1 = Automate(lt_a1)
# Automate A2
s_a2_0 = State(0, True, False)
s_a2_1 = State(1, False, False)
s_a2_2 = State(2, False, True)
t_a2_0 = Transition(s_a2_0, "a", s_a2_1)
예제 #22
0
from automate import Automate
from state import State
from transition import Transition
from parser import *
#from essai import Essai

#import projet

print("DEBUT PROGRAMME\n")

s = State(1, False, False)
s2 = State(1, True, False)
t = Transition(s, "a", s)
t2 = Transition(s, "a", s2)
s.insertPrefix(2)
a = Automate([t, t2])
a.prefixStates(3)
a.show("justep")
"""
print "etat s " + s.id
print "s "+ str(s)
print "t "+ str(t)
print "a "+ str(a)
"""

print("s=s2? " + str(s == s2))
print("t=t2? " + str(t == t2))

s1 = State(1, True, False)
s2 = State(2, False, True)
t1 = Transition(s1, "a", s1)
예제 #23
0
from state import State
from transition import Transition
from parser import *

s0 = State(0, True, False)
s1 = State(1, False, False)
s2 = State(2, False, True)

t1 = Transition(s0, 'a', s0)
t2 = Transition(s0, 'b', s1)
t3 = Transition(s1, 'a', s2)
t4 = Transition(s1, 'b', s2)
t5 = Transition(s2, 'a', s0)
t6 = Transition(s2, 'b', s1)

auto1 = Automate([t1, t2, t3, t4, t5, t6], [s0, s1, s2])

# Exercice de base

# Test fonction succ

suc01_a = auto1.succ([s0, s1], 'a')
print("La liste des successeur de 0 et de 1 avec la lettre a sont :", suc01_a)

# Test fonction accepte

if Automate.accepte(auto1, "abba"):
    print("L'automate accepte le mot abba")
else:
    print("L'automate n'accepte pas le mot abba")
예제 #24
0
# création d'états
# s0 state
s0 = State(0, True, False)
# s1 state
s1 = State(1, False, True)
# s2 state
s2 = State(2, False, True)
#Création de transitions
t1 = Transition(s0, "a", s0)
t2 = Transition(s0, "b", s1)
t3 = Transition(s1, "a", s2)
t4 = Transition(s1, "b", s2)
t5 = Transition(s2, "a", s0)
t6 = Transition(s2, "b", s1)
# affichage de l'automate
auto = Automate([t1, t2, t3, t4, t5, t6])
print(auto)
auto.show("A_ListeTrans")

# Créations de l'automate à l'aide de ses transitions et états :
auto1 = Automate([t1, t2, t3, t4, t5, t6], [s0, s1, s2])
print(auto1)
auto1.show("A_ListeEtats")
# Création de l'aitomate à partir d'un fichier texte :
auto2 = Automate.creationAutomate("auto.txt")
print(auto2)
auto2.show("A_texte")
"""
# Premières manipulations
t = Transition(s0,"a",s0)
auto.removeTransition(t)