-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainLabs.py
63 lines (47 loc) · 1.85 KB
/
mainLabs.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
import sys
import pyknow
# yield pyknow.Fact(action="fish")
# yield pyknow.Fact(action="otrajd")
# yield pyknow.Fact(action="vid")
# yield pyknow.Fact(action="priznak")
# @pyknow.Rule(pyknow.Fact(action='fish'),
# pyknow.Fact(name="name" << "cазан"),
# pyknow.Fact(name="otrajd" << "карпообразные"),
# pyknow.Fact(name="priznak" << "губы с 4 усиками"),)
class Greetings(pyknow.KnowledgeEngine):
@pyknow.DefFacts()
def _initial_action(self):
yield pyknow.Fact(action="greet")
@pyknow.Rule(pyknow.Fact(action='greet'),
pyknow.NOT(pyknow.Fact(name=pyknow.W())))
def ask_name(self):
# self.declare(pyknow.Fact(name=input("What's your name? ")))
self.declare(pyknow.Fact(name="NAME"))
@pyknow.Rule(pyknow.Fact(action='greet'),
pyknow.NOT(pyknow.Fact(location=pyknow.W())))
def ask_location(self):
# self.declare(pyknow.Fact(location=input("Where are you? ")))
self.declare(pyknow.Fact(location="RUSSIA"))
@pyknow.Rule(pyknow.Fact(action='greet'),
pyknow.Fact(name="name" << pyknow.W()),
pyknow.Fact(location="location" << pyknow.W()))
def greet(self, name, location):
print("Hi %s! How is the weather in %s?" % (name, location))
class Fish(pyknow.Fact):
pass
class Otrajd(pyknow.Fact):
pass
class Priznak(pyknow.Fact):
pass
class Vid(pyknow.Fact):
pass
def main():
greetingsEngine = Greetings()
greetingsEngine.reset() # Prepare the engine for the execution.
greetingsEngine.run() # Run it!
# print(greetingsEngine.facts)
# graph = greetingsEngine.matcher.show_network()
# print(graph.source)
# graph.render('./Temp/round-table.gv', view=True) # sudo apt-get install graphviz
if __name__ == '__main__':
sys.exit(main())