-
Notifications
You must be signed in to change notification settings - Fork 0
/
irregularnounstems.jl
162 lines (123 loc) · 3.64 KB
/
irregularnounstems.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
"A record for a single irregular noun stem."
struct IrregularNounStem <: KanonesIrregularStem
stemid::AbbreviatedUrn
lexid::AbbreviatedUrn
form::AbstractString
noungender::GMPGender
nouncase::GMPCase
nounnumber::GMPNumber
inflectiontype
end
function pos(nounstem::IrregularNounStem)
:noun
end
"""Identify gender of `noun`.
$(SIGNATURES)
"""
function gmpGender(noun::IrregularNounStem)
noun.noungender
end
"""Identify case of `noun`.
$(SIGNATURES)
"""
function gmpCase(noun::IrregularNounStem)
noun.nouncase
end
"""Identify number of `noun`.
$(SIGNATURES)
"""
function gmpNumber(noun::IrregularNounStem)
noun.nounnumber
end
"""Irregular noun stems are citable by Cite2Urn"""
CitableTrait(::Type{IrregularNounStem}) = CitableByCite2Urn()
"""Human-readlable label for an `IrregularNounStem`.
$(SIGNATURES)
Required for `CitableTrait`.
"""
function label(ns::IrregularNounStem)
string("Irregular noun form ", ns.form, " (", label(ns.noungender)," ", label(ns.nouncase), " ", label(ns.nounnumber), ")")
end
"""Identifying URN for an `IrregularNounStem`. If
no registry is included, use abbreviated URN;
otherwise, expand to full `Cite2Urn`.
$(SIGNATURES)
Required for `CitableTrait`.
"""
function urn(ns::IrregularNounStem; registry = nothing)
if isnothing(registry)
ns.stemid
else
expand(ns.stemid, registry)
end
end
"""Compose CEX text for an `IrregularNounStem`.
If `registry` is nothing, use abbreivated URN;
otherwise, expand identifier to full `Cite2Urn`.
$(SIGNATURES)
Required for `CitableTrait`.
"""
function cex(ns::IrregularNounStem; delimiter = "|", registry = nothing)
if isnothing(registry)
join([ns.stemid, label(ns), stemstring(ns), lexeme(ns), inflectionclass(ns), label(ns.noungender), label(ns.nouncase), label(ns.nounnumber) ], delimiter)
else
c2urn = expand(ns.stemid, registry)
join([c2urn, label(ns), stemstring(ns), lexeme(ns), inflectionclass(ns), label(ns.noungender), label(ns.nouncase), label(ns.nounnumber)], delimiter)
end
end
"""
Read one row of a stems table for noun tokens and create a `NounStem`.
$(SIGNATURES)
"""
function readstemrow(usp::IrregularNounIO, delimited::AbstractString; delimiter = "|")
parts = split(delimited, delimiter)
# Example:
#irregnoun.irregn23069a|lsj.n23069|γυνή|feminine|nominative|singular|irregularnoun
if length(parts) < 7
msg = "Too few parts in $(delimited)."
@warn msg
throw(new(ArgumentError(msg)))
end
stemid = StemUrn(parts[1])
lexid = LexemeUrn(parts[2])
stem = knormal(parts[3])
g = gmpGender(parts[4])
c = gmpCase(parts[5])
n = gmpNumber(parts[6])
inflclass = parts[7]
IrregularNounStem(stemid,lexid,stem,g,c,n,inflclass)
end
"""Identify value of stem string for `noun`.
$(SIGNATURES)
"""
function stemstring(noun::IrregularNounStem)
noun.form |> knormal
end
"""Identify lexeme for `noun`.
$(SIGNATURES)
"""
function lexeme(noun::IrregularNounStem)
noun.lexid
end
"""Identify inflection class for `noun`.
$(SIGNATURES)
"""
function inflectionclass(noun::IrregularNounStem)
noun.inflectiontype
end
"""Compose a digital code string for the form identified in `noun`.
$(SIGNATURES)
"""
function code(noun::IrregularNounStem)
# PosPNTMVGCDCat
string( NOUN,"0",code(noun.nounnumber),"000",code(noun.noungender),code(noun.nouncase),"00")
end
"""Compose an abbreviated URN for a rule from a `IrregularNounStem`.
$(SIGNATURES)
"""
function formurn(noun::IrregularNounStem)
FormUrn("$(COLLECTION_ID)." * code(noun))
end
function greekForm(noun::IrregularNounStem)
formurn(noun) |> greekForm
end