-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprolog_creator.rb
More file actions
39 lines (25 loc) · 818 Bytes
/
prolog_creator.rb
File metadata and controls
39 lines (25 loc) · 818 Bytes
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
family_file = File.open('relationships_data.data', 'r')
parents_file = File.open('code_to_name.data', 'r')
code_to_name = Hash.new
code_to_sex = Hash.new
family_file.each do |line|
m = line.match(/([\w]+) = ([\w]+) ([\w]+) \(([\w])\)/)
code_to_name[m[1].to_sym] = "#{m[2].downcase}_#{m[3].downcase}"
code_to_sex[m[1].to_sym] = m[4].to_sym
end
relations = Array.new
parents_file.each do |line|
m = line.match(/([\w]+)->([\w]+)/)
relations << {parent: "#{code_to_name[m[1].to_sym]}",
descendant: "#{code_to_name[m[2].to_sym]}"}
end
f = File.new('out.pl', 'w')
relations.each do |r|
f.write("parent(#{r[:parent]}, #{r[:descendant]}).\n")
end
code_to_sex.each do |c|
f.write("sex(#{code_to_name[c[0]]}, #{c[1].downcase}).\n")
end
f.close
family_file.close
parents_file.close