-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrs.py
79 lines (60 loc) · 1.55 KB
/
rs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
relation="a"
graph={}
print "\nEntrez vos relations \nVeuillez entrer la relation <<is_a>> avec cet orthograph. \nTerminez avec une ligne vide:\n"
while len(relation) !=0:
relation = raw_input("")
if len(relation)==0:
break
relation=relation.split(" ")
if len(relation)!=3:
print "Syntax erronée. Re-ecrivez votre phrase:"
continue
if not relation[1] in graph:
graph[relation[1]]=[]
#a=relation.pop(0)
#b=relation.pop(-1)
#relation='_'.join(relation)
graph[relation[1]].append((relation[0],relation[2]))
print "Graph construit:"
print graph
print "\n"
question= raw_input("Entrez votre question avec la syntax suivante (sans les '<,>'):\n< amine mange soterelle ? >\n") #<qui mange amine ?> \n2- <amine mange qui ?>\n3- <amine mange sautrelle ?>")
question=question.split(" ")
m1=[]
m2=[]
m1.append(question[0])
m2.append(question[2])
dontstop=True
while dontstop:
dontstop=False
for element in m1:
for tupl in graph["is_a"]:
if element == tupl[1] and not (tupl[0] in m1):
m1.append(tupl[0])
dontstop=True
print "M1 propagé"
print m1
print "\n"
dontstop=True
while dontstop:
dontstop=False
for element in m2:
for tupl in graph["is_a"]:
if element == tupl[1] and not (tupl[0] in m2):
m2.append(tupl[0])
dontstop=True
print "M2 propagé"
print m2
print "\n"
solution=[]
for a in m1:
for b in m2:
if (a,b) in graph[question[1]]:
solution.append((a,b))
if len(solution)==0:
print "Il n y a pas de solution"
else:
print "Solutions:"
for (a,b) in solution:
print a+" "+question[1]+" "+b