-
Notifications
You must be signed in to change notification settings - Fork 0
/
noundeclensions.jl
206 lines (169 loc) · 5.72 KB
/
noundeclensions.jl
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
"""Decline all case-number combinations of `lex`, a noun.
$(SIGNATURES)
"""
function decline(lex::LexemeUrn, kd::Kanones.FilesDataset; withvocative::Bool = false)
stemmatches = filter(s -> lexeme(s) == lex, stemsarray(kd))
declinedforms = []
for stem in stemmatches
forms = filter(f -> gmpGender(f) == gmpGender(stem), Kanones.nounforms())
rules = filter(r -> inflectionclass(r) == inflectionclass(stem), rulesarray(kd))
for f in forms
rulematches = filter(r -> formurn(r) == formurn(f), rules)
if !isempty(rulematches)
push!(declinedforms, generate(stem, rulematches[1]))
end
end
end
declinedforms
end
"""Compose markdown table with a declension of a single noun.
$(SIGNATURES)
"""
function declension_md(lex::LexemeUrn, kd::Kanones.FilesDataset)
labels = ["nominative", "genitive", "dative", "accusative", "vocative"]
lines = [
"| | Singular | Plural |",
"| --- | --- | --- |"
]
arry = decline(lex, kd)
for i in 1:5
push!(lines, string("| **", labels[i], "** | ", arry[i], " | ", arry[i + 5], " |"))
end
join(lines,"\n")
end
"""Compose markdown for a dictionary entry for a single noun,
$(SIGNATURES)
"""
function lexicon_noun_md(lex::LexemeUrn, kd::Kanones.FilesDataset)
# 1.
stemdata = filter(stemsarray(kd)) do stem
stem.lexid == lex
end
genderlist = map(stem -> Kanones.gender(stem), stemdata) |> unique
#gender = join(genderlist, ", or ")
noms = []
gens = []
if isempty(genderlist)
@warn("No gender found for lexeme $(lex)!")
throw(ArgumentError("lexicon_noun_md: bad data, no gender found for $(lex)"))
else
for g in genderlist
if isnothing(g)
@warn("No gender found for lexeme $(lex)!")
throw(ArgumentError("lexicon_noun_md: bad data, no gender found for $(lex)"))
end
end
end
# 2.
noms_form = GMFNoun(genderlist[1], gmpCase("nominative"), gmpNumber("singular")) |> formurn
push!(noms,generate(lex, noms_form, kd))
# 3.
gens_form = GMFNoun(genderlist[1], gmpCase("genitive"), gmpNumber("singular")) |> formurn
push!(gens, generate(lex, gens_form, kd))
nomforms = Iterators.flatten(noms) |> collect |> unique
genforms = Iterators.flatten(gens) |> collect |> unique
if isempty(noms) || isempty(gens)
@warn("lexicon_noun_md: could not generate nominative and genitive singular for $(lex)")
""
else
genderstrings = map(g -> label(g)[1] * ".", filter(g -> ! isnothing(g), genderlist))
string(join(nomforms, " or "), ", ", join(genforms, " or "), ", *", join(genderstrings, " or "), "*")
end
end
"""Find gender property for a Kanones stem.
Returns `nothing` if stem does not have a gender property.
$(SIGNATURES)
"""
function gender(stem::T) where {T <: KanonesStem}
if stem isa IrregularNounStem
stem.noungender
elseif stem isa NounStem
stem.gender
else
nothing
end
end
#=
"""Compose markdown table with aligned declensions of multiple nouns.
$(SIGNATURES)
"""
function declension_md(lexlist::Array, kd::Kanones.FilesDataset; withvocative::Bool = false)
labels = ["nominative", "genitive", "dative", "accusative"]
gendervalues = genders(lexlist, kd)
inflclasses = stemtypes(lexlist, kd)
hdr = "| | "
for i in 1:length(lexlist)
hdr = hdr * string("`", inflclasses[i], "` |")
end
lines = [
"**Singular**",
"",
hdr,
"| --- | " * repeat( " :--- |", length(lexlist))
]
for y in 1:length(labels)
row = string("| **", labels[y], "** | ")
for x in 1:length(lexlist)
form = FormUrn("$(COLLECTION_ID).201000$(gendervalues[x])$(y)00")
surface = generatenoun( form, lexlist[x], kd)
row = row * string(join(surface, ", "), " | ")
end
push!(lines, row)
end
push!(lines,"")
push!(lines,"**Plural**")
push!(lines, "")
hdr2 = "| | "
for i in 1:length(lexlist)
hdr2 = hdr2 * string(" |")
end
push!(lines, hdr2)
push!(lines, "| --- | " * repeat( " :--- |", length(lexlist)))
for y in 1:length(labels)
row = string("| **", labels[y], "** | ")
for x in 1:length(lexlist)
form = FormUrn("$(COLLECTION_ID).203000$(gendervalues[x])$(y)00")
surface = generatenoun( form, lexlist[x], kd)
row = row * string(join(surface, ", "), " | ")
end
push!(lines, row)
end
join(lines, "\n")
end
"""Look up integer code for gender for a list of nouns.
$(SIGNATURES)
"""
function genders(lexlist, kd::Kanones.FilesDataset)
stems = stemsarray(kd)
nounstems = filter(s -> typeof(s) == NounStem, stems)
genderlist = []
for lex in lexlist
stemmatches = filter(s -> s.lexid == lex, nounstems)
if isempty(stemmatches)
@warn "No matches in dataset for lexeme $lex"
push!(genderlist, nothing)
else
push!(genderlist, code(gmpGender(stemmatches[1])))
end
end
genderlist
end
"""Look up integer code for gender for a list of nouns.
$(SIGNATURES)
"""
function stemtypes(lexlist::Array, kd::Kanones.FilesDataset)
stems = stemsarray(kd)
nounstems = filter(s -> typeof(s) == NounStem, stems)
stemtypes = []
for lex in lexlist
stemmatches = filter(s -> s.lexid == lex, nounstems)
if isempty(stemmatches)
@warn "No matches in dataset for lexeme $lex"
push!(stemtypes, nothing)
else
push!(stemtypes, stemmatches[1].inflectionclass)
end
end
stemtypes
end
=#