-
Notifications
You must be signed in to change notification settings - Fork 0
/
participlerules.jl
163 lines (132 loc) · 3.75 KB
/
participlerules.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
"""Inflectional rule for participial form.
$(SIGNATURES)
"""
struct ParticipleRule <: KanonesVerbalRule
ruleid::AbbreviatedUrn
inflectionclass
ending
ptense::GMPTense
pvoice::GMPVoice
pgender::GMPGender
pcase::GMPCase
pnumber::GMPNumber
end
"""Identify tense property of `rule`.
$(SIGNATURES)
"""
function gmpTense(rule::ParticipleRule)
rule.ptense
end
"""Identify voice property of `rule`.
$(SIGNATURES)
"""
function gmpVoice(rule::ParticipleRule)
rule.pvoice
end
"""Identify gender property of `rule`.
$(SIGNATURES)
"""
function gmpGender(rule::ParticipleRule)
rule.pgender
end
"""Identify case property of `rule`.
$(SIGNATURES)
"""
function gmpCase(rule::ParticipleRule)
rule.pcase
end
"""Identify number property of `rule`.
$(SIGNATURES)
"""
function gmpNumber(rule::ParticipleRule)
rule.pnumber
end
"""Participle rules are citable by Cite2Urn"""
CitableTrait(::Type{ParticipleRule}) = CitableByCite2Urn()
"""Human-readlable label for a `ParticipleRule`.
$(SIGNATURES)
Required for `CitableTrait`.
"""
function label(ptcpl::ParticipleRule)
string("Participle inflection rule: ending -", ptcpl.ending, " in class ", ptcpl.inflectionclass, " can be ", label(ptcpl.ptense), " ", label(ptcpl.pvoice), " ", label(ptcpl.pgender), " ", label(ptcpl.pcase), " ", label(ptcpl.pnumber), ".")
end
"""Identifying URN for a `ParticipleRule`. If
no registry is included, use abbreviated URN;
otherwise, expand to full `Cite2Urn`.
$(SIGNATURES)
Required for `CitableTrait`.
"""
function urn(ptcpl::ParticipleRule; registry = nothing)
if isnothing(registry)
ptcpl.ruleid
else
expand(ptcpl.ruleid, registry)
end
end
"""Identify inflection class for `rule`
$(SIGNATURES)
"""
function inflectionclass(rule::ParticipleRule)
rule.inflectionclass
end
"""Identify inflectional ending for `rule`
$(SIGNATURES)
"""
function ending(rule::ParticipleRule)
rule.ending
end
"""Compose CEX text for a `VerbalAdjectiveRule`.
If `registry` is nothing, use abbreivated URN;
otherwise, expand identifier to full `Cite2Urn`.
$(SIGNATURES)
Required for `CitableTrait`.
"""
function cex(ptcpl::ParticipleRule; delimiter = "|", registry = nothing)
if isnothing(registry)
join([ptcpl.ruleid, label(ptcpl), ending(ptcpl), inflectionclass(ptcpl), formurn(ptcpl)], delimiter)
else
c2urn = expand(ptcpl.ruleid, registry)
join([c2urn, label(ptcpl)], delimiter)
end
end
"""Read one row of a rules table for infinitives and create an`ParticipleRule`.
$(SIGNATURES)
"""
function readrulerow(usp::ParticipleIO, delimited::AbstractString; delimiter = "|")
parts = split(delimited, delimiter)
if length(parts) < 5
msg = "Invalid syntax for finite verb rule: too few components in $(delimited)"
throw(ArgumentError(msg))
else
ruleid = RuleUrn(parts[1])
inflclass = parts[2]
ending = parts[3]
t = gmpTense(parts[4])
v = gmpVoice(parts[5])
g = gmpGender(parts[6])
c = gmpCase(parts[7])
n = gmpNumber(parts[8])
ParticipleRule(ruleid, inflclass, ending,t,v,g,c,n)
end
# Rule|StemClass|Ending|Person|Number|Tense|Mood|Voice
end
"""Compose string of digits for form in `rule`.
$(SIGNATURES)
"""
function code(rule::ParticipleRule)
# PosPNTMVGCDCat
string(PARTICIPLE,"0",code(rule.pnumber), code(rule.ptense), "0", code(rule.pvoice), code(rule.pgender), code(rule.pcase),"00")
end
"""Compose an abbreviated URN for a rule from a `ParticipleRule`.
$(SIGNATURES)
"""
function ruleurn(rule::ParticipleRule)
rule.ruleid
end
"""Compose an abbreviated URN for a rule from an `InfinitiveRule`.
$(SIGNATURES)
"""
function formurn(rule::ParticipleRule)
# PosPNTMVGCDCat
FormUrn("$(COLLECTION_ID)." * code(rule))
end