Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Thu Oct 10 16:45:50 2019
  4.  
  5. @author: Issam
  6. """
  7.  
  8. from Fait import Fait
  9. from regle import regle
  10. import re
  11.  
  12. def inmap(aa,d):
  13. tod=aa.split(' = ')
  14. tod[1].strip('\n')
  15. d[tod[0]]=tod[1]
  16.  
  17. def match(tab_premisses,tab_fait):
  18. for i in tab_premisses:
  19. if '!=' in i:
  20. delim=' != '
  21. elif '<=' in i:
  22. delim=' <= '
  23. elif '>=' in i:
  24. delim=' >= '
  25. elif '<' in i:
  26. delim=' < '
  27. elif '>' in i:
  28. delim=' > '
  29. elif '=' in i:
  30. delim=' = '
  31. sp=i.split(delim)
  32. if delim==' = ':
  33. delim='=='
  34. # print(sp[0]+' here ')
  35. if sp[0] in tab_fait:
  36. if sp[1] == 'Vrai' : sp[1]='True'
  37. elif sp[1] == 'Faux' : sp[1]='False'
  38. if tab_fait[sp[0]] == 'Vrai' : tab_fait[sp[0]]='True'
  39. elif tab_fait[sp[0]] == 'Faux' : tab_fait[sp[0]]='False'
  40. st=tab_fait[sp[0]]+delim+sp[1]
  41. #print(st)
  42. if not eval(st):
  43. return False
  44. else : return False
  45. return True
  46. def chainageAV(nom_fichier,but) :
  47. nom_fichier=nom_fichier
  48. but=but
  49. #print(but)
  50. f=open(nom_fichier,"r")
  51. a=[]
  52. x=[]
  53. fait=f.readline()
  54. while fait:
  55. if 'alors' in fait:
  56. x.append(fait)
  57. elif fait not in '\n':
  58. a.append(fait)
  59. fait=f.readline()
  60. tab_fait = []
  61. #tab_fait_test= []
  62. d={}
  63. for i in a:
  64. aa=i.strip('\n')
  65. fait=Fait(aa,-1)
  66. tab_fait.append(fait)
  67. inmap(aa,d)
  68. #print(d)
  69.  
  70. #print(tab_fait)
  71. delim1=' alors '
  72. delim2='si | et '
  73. tab_regle=[]
  74. for i in range(len(x)):
  75. liste=re.split(delim1,x[i])
  76. liste1=re.split(delim2,liste[0])
  77. concl=liste[1].strip('\n')
  78. liste1.pop(0)
  79. #print(i,liste1,liste[1])
  80. aa=regle(i+1,liste1,concl)
  81. tab_regle.append(aa)
  82. """
  83. chainage avant
  84.  
  85. """
  86. wf=open("trace.txt",'w+')
  87. test=False
  88. while not test:
  89. test=True
  90. tab_fait_new=[]
  91. for i in tab_regle:
  92. #print(match(i.premisses,tab_fait_test))
  93. but1=but.split(' = ')
  94. co=i.conclusion.split(' = ')
  95. if ((match(i.premisses,d)) and (but1[0] not in d) and (co[0] not in d)):
  96. wf.write(i.conclusion + ' ' + str(i.numregle) +'\n')
  97. print(i.conclusion,i.numregle)
  98. aa=Fait(i.conclusion,i.numregle)
  99. tab_fait_new.append(aa)
  100. #inmap(i.conclusion,d)
  101. test=False
  102. tab_fait.append(tab_fait_new)
  103. for k in tab_fait_new:
  104. inmap(k.fait,d)
  105. wf.close
  106. f.close
  107. chainageAV("méteorologies.txt","-1 = -69")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement