Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Thu Oct 10 16:45:50 2019
- @author: Issam
- """
- from Fait import Fait
- from regle import regle
- import re
- def inmap(aa,d):
- tod=aa.split(' = ')
- tod[1].strip('\n')
- d[tod[0]]=tod[1]
- def match(tab_premisses,tab_fait):
- for i in tab_premisses:
- if '!=' in i:
- delim=' != '
- elif '<=' in i:
- delim=' <= '
- elif '>=' in i:
- delim=' >= '
- elif '<' in i:
- delim=' < '
- elif '>' in i:
- delim=' > '
- elif '=' in i:
- delim=' = '
- sp=i.split(delim)
- if delim==' = ':
- delim='=='
- # print(sp[0]+' here ')
- if sp[0] in tab_fait:
- if sp[1] == 'Vrai' : sp[1]='True'
- elif sp[1] == 'Faux' : sp[1]='False'
- if tab_fait[sp[0]] == 'Vrai' : tab_fait[sp[0]]='True'
- elif tab_fait[sp[0]] == 'Faux' : tab_fait[sp[0]]='False'
- st=tab_fait[sp[0]]+delim+sp[1]
- #print(st)
- if not eval(st):
- return False
- else : return False
- return True
- def chainageAV(nom_fichier,but) :
- nom_fichier=nom_fichier
- but=but
- #print(but)
- f=open(nom_fichier,"r")
- a=[]
- x=[]
- fait=f.readline()
- while fait:
- if 'alors' in fait:
- x.append(fait)
- elif fait not in '\n':
- a.append(fait)
- fait=f.readline()
- tab_fait = []
- #tab_fait_test= []
- d={}
- for i in a:
- aa=i.strip('\n')
- fait=Fait(aa,-1)
- tab_fait.append(fait)
- inmap(aa,d)
- #print(d)
- #print(tab_fait)
- delim1=' alors '
- delim2='si | et '
- tab_regle=[]
- for i in range(len(x)):
- liste=re.split(delim1,x[i])
- liste1=re.split(delim2,liste[0])
- concl=liste[1].strip('\n')
- liste1.pop(0)
- #print(i,liste1,liste[1])
- aa=regle(i+1,liste1,concl)
- tab_regle.append(aa)
- """
- chainage avant
- """
- wf=open("trace.txt",'w+')
- test=False
- while not test:
- test=True
- tab_fait_new=[]
- for i in tab_regle:
- #print(match(i.premisses,tab_fait_test))
- but1=but.split(' = ')
- co=i.conclusion.split(' = ')
- if ((match(i.premisses,d)) and (but1[0] not in d) and (co[0] not in d)):
- wf.write(i.conclusion + ' ' + str(i.numregle) +'\n')
- print(i.conclusion,i.numregle)
- aa=Fait(i.conclusion,i.numregle)
- tab_fait_new.append(aa)
- #inmap(i.conclusion,d)
- test=False
- tab_fait.append(tab_fait_new)
- for k in tab_fait_new:
- inmap(k.fait,d)
- wf.close
- f.close
- chainageAV("méteorologies.txt","-1 = -69")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement