-
Notifications
You must be signed in to change notification settings - Fork 0
/
adjectiverules.jl
147 lines (120 loc) · 3.38 KB
/
adjectiverules.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
"Inflectional rule for adjectives."
struct AdjectiveRule <: KanonesRule
ruleid::AbbreviatedUrn
inflectionclass
ending
agender::GMPGender
acase::GMPCase
anumber::GMPNumber
adegree::GMPDegree
end
"""Identifying URN for an `AdjectiveRule`. If
no registry is included, use abbreviated URN;
otherwise, expand to full `Cite2Urn`.
$(SIGNATURES)
Required for `CitableTrait`.
"""
function urn(adj::AdjectiveRule; registry = nothing)
if isnothing(registry)
adj.ruleid
else
expand(adj.ruleid, registry)
end
end
"""Identify `adj` with a `RuleUrn`.
$(SIGNATURES)
"""
function ruleurn(adj::AdjectiveRule)
adj.ruleid
end
"""Identify gender for `adj`.
$(SIGNATURES)
"""
function gmpGender(adj::AdjectiveRule)
adj.agender
end
"""Identify case for `adj`.
$(SIGNATURES)
"""
function gmpCase(adj::AdjectiveRule)
adj.acase
end
"""Identify number for `adj`.
$(SIGNATURES)
"""
function gmpNumber(adj::AdjectiveRule)
adj.anumber
end
"""Identify degree for `adj`.
$(SIGNATURES)
"""
function gmpDegree(adj::AdjectiveRule)
adj.adegree
end
"""Identify inflection class for `rule`.
$(SIGNATURES)
"""
function inflectionclass(rule::AdjectiveRule)
rule.inflectionclass
end
"""Identify ending for `rule`.
$(SIGNATURES)
"""
function ending(rule::AdjectiveRule)
rule.ending
end
"""Implementation of reading one row of a rules table for uninflected tokens.
$(SIGNATURES)
"""
function readrulerow(usp::AdjectiveIO, delimited::AbstractString; delimiter = "|")
parts = split(delimited, delimiter)
if length(parts) < 7
msg = "Invalid syntax for adjective rule: too few components in $(delimited)"
throw(ArgumentError(msg))
else
ruleid = RuleUrn(parts[1])
inflclass = parts[2]
ending = knormal(parts[3])
g = gmpGender(parts[4])
c = gmpCase(parts[5])
n = gmpNumber(parts[6])
d = gmpDegree(parts[7])
AdjectiveRule(ruleid, inflclass, ending, g,c,n,d)
end
end
"""Adjective rules are citable by Cite2Urn"""
CitableTrait(::Type{AdjectiveRule}) = CitableByCite2Urn()
"""Human-readlable label for an `AdjectiveRule`.
$(SIGNATURES)
Required for `CitableTrait`.
"""
function label(adj::AdjectiveRule)
string("Adjective inflection rule: ending -", adj.ending, " in class ", adj.inflectionclass, " can be ", label(adj.agender), " ", label(adj.acase), " ", label(adj.anumber), " ", label(adj.adegree),".")
end
"""Compose CEX text for an `AdjectiveRule`.
If `registry` is nothing, use abbreivated URN;
otherwise, expand identifier to full `Cite2Urn`.
$(SIGNATURES)
Required for `CitableTrait`.
"""
function cex(adj::AdjectiveRule; delimiter = "|", registry = nothing)
if isnothing(registry)
join([adj.ruleid, label(adj), ending(adj), inflectionclass(adj), formurn(adj)], delimiter)
else
c2urn = expand(adj.ruleid, registry)
join([c2urn, label(adj),ending(adj), inflectionclass(adj), formurn(adj)], delimiter)
end
end
"""Compose digital code for morphological form identified in `rule`.
$(SIGNATURES)
"""
function code(rule::AdjectiveRule)
#PosPNTMVGCDCat
string(ADJECTIVE,"0",code(rule.anumber),"000",code(rule.agender),code(rule.acase),code(rule.adegree),"0")
end
"""Compose an abbreviated URN for a morphological form identified in `rule`.
$(SIGNATURES)
"""
function formurn(rule::AdjectiveRule)
FormUrn("$(COLLECTION_ID)." * code(rule) )
end