-
Notifications
You must be signed in to change notification settings - Fork 0
/
pnv_person.rb
84 lines (72 loc) · 1.94 KB
/
pnv_person.rb
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
76
77
78
79
80
81
82
83
class Pnv_person
@@categories = [
"prefix",
"givenName",
"patronym",
"givenNameSuffix",
"infixTitle",
"surnamePrefix",
"baseSurname",
"trailingPatronym",
"honorificSuffix",
"disambiguatingDescription"
]
@@combinations = [
"surname",
"literalName",
"firstName",
"infix",
"suffix"
]
@naam = Hash.new
def initialize
@naam = Hash.new
end
def add categorie,value
if @naam[categorie].nil?
@naam[categorie] = value
else
@naam[categorie] += " #{value}"
STDERR.puts "added #{categorie} more than once (#{@naam[categorie]})"
end
STDERR.puts "#{categorie} is unknown as a name part" if !@@categories.include? categorie
end
def get categorie
return combine categorie if @@combinations.include? categorie
return @naam[categorie] unless @@categories.include? categorie
return "unknown name part: #{categorie}"
end
def combine categorie
if categorie.eql?("literalName")
result = ""
@@categories.each do |cat|
result += " #{@naam[cat]}"
end
return clean result
elsif categorie.eql?("surname")
return clean "#{@naam['surnamePrefix']} #{@naam['baseSurname']}"
elsif categorie.eql?("first")
return clean "#{@naam['givenName']} #{@naam['patronym']} #{@naam['givenNameSuffix']}"
elsif categorie.eql?("infix")
return clean "#{@naam['InfixTitle']} #{@naam['surnamePrefix']}"
elsif categorie.eql?("suffix")
return clean "#{@naam['tralingPatronym']} #{@naam['honorificSuffix']} #{@naam['disambiguatingDescription']}"
end
end
def clean text
text.gsub(/ +/," ").gsub(/' /,"'").strip
end
def to_h
return @naam
end
def to_s
res = "{\n"
@naam.each do |k,v|
res += " #{k} => #{v},\n"
end
res.strip!
res = res[0..-2] if res[-1..-1].eql?(',')
res += "}"
return res
end
end