-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner
executable file
·57 lines (46 loc) · 1.33 KB
/
runner
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
#!/usr/bin/env ruby
DEFAULT_ENV = :production
NEWLINE = "\n"
require_relative '../config/app'
def read_lines_from_file(path)
File.read(path).split(NEWLINE).map(&:chomp).map(&:strip).reject(&:empty?)
end
def get_input
STDIN.gets.chomp.strip
end
if ARGV.count == 2
input = read_lines_from_file(ARGV[0])
queries = read_lines_from_file(ARGV[1])
knowledge_base = KnowledgeBase.new(input)
File.open('output.txt', 'w') do |file|
queries.each do |query|
file.puts "Answers for #{query}:"
knowledge_base.ask(query).each do |answer|
file.puts answer
end
end
end
else
puts 'Type clauses for knowledge base separating them by enter (=> for implication, AND for conjunction)'
puts 'Type "end" at the end'
puts 'E.g.:'
puts 'Knows(Anna, x)'
puts 'Female(x) AND StudiesOn(PW, x) => Knows(x, Jan)'
puts 'Female(Jadwiga) AND StudiesOn(PW, Jadwiga)'
puts 'end'
clauses = []
while (input_line = get_input).downcase != 'end'
clauses << input_line if !input_line.empty?
end
knowledge_base = KnowledgeBase.new(clauses)
puts 'Type your queries'
puts 'E.g. Knows(x, Jan)'
puts 'You can exit by typing "exit"'
while (query = get_input).downcase != 'exit'
next if query.empty?
puts "Answers for #{query}:"
knowledge_base.ask(query).each do |answer|
puts answer
end
end
end