-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from neelsmith/wip
Add Latin 25, Latin24 types
- Loading branch information
Showing
9 changed files
with
374 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
"""Define recognized punctuation characters for Latin23 orthography. | ||
$(SIGNATURES) | ||
""" | ||
function latinpunctuation() | ||
".,;:?" | ||
end | ||
|
||
"""Define recognized punctuation characters for Latin23 orthography. | ||
$(SIGNATURES) | ||
""" | ||
function latinwhitespace() | ||
" \n\t" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
|
||
""" | ||
An orthographic system for encoding Latin with a 24-character alphabet. | ||
`i` represents both vocalic and semi-vocalic or consonantal values. | ||
""" | ||
struct Latin24 <: LatinOrthographicSystem | ||
codepoints | ||
tokencategories | ||
tokenizer | ||
end | ||
|
||
OrthographyTrait(::Type{Latin24}) = IsOrthographicSystem() | ||
|
||
"""Implement Orthography's tokenize function for `Latin24`. | ||
$(SIGNATURES) | ||
""" | ||
function tokenize(s::AbstractString, o::Latin24) | ||
tokenizeLatin24(s) | ||
end | ||
|
||
"""Implement `codepoints` function of MID `OrthographicSystem` interface. | ||
$(SIGNATURES) | ||
""" | ||
function codepoints(ortho::Latin24) | ||
ortho.codepoints | ||
end | ||
|
||
"""Implement `tokentypes` function of MID `OrthographicSystem` interface. | ||
$(SIGNATURES) | ||
""" | ||
function tokentypes(ortho::Latin24) | ||
ortho.tokencategories | ||
end | ||
|
||
"""Define range of alphabetic character for Latin24 orthography. | ||
$(SIGNATURES) | ||
""" | ||
function alphabetic(ortho::Latin24) | ||
latinalphabet() | ||
end | ||
|
||
|
||
"""Define range of alphabetic character for Latin24 orthography. | ||
$(SIGNATURES) | ||
""" | ||
function latin24alphabet() | ||
ranges = [ | ||
'a':'i' ; 'k':'v'; 'x':'z'; | ||
'A':'I' ; 'K':'V'; 'X':'Z'; | ||
] | ||
join(ranges,"") | ||
end | ||
|
||
|
||
|
||
|
||
|
||
"""Define recognized punctuation characters for Latin orthographies. | ||
$(SIGNATURES) | ||
""" | ||
function whitespace(ortho::Latin24) | ||
latinwhitespace() | ||
end | ||
|
||
|
||
|
||
"""Instantiate a Latin24 with correct code points and token types. | ||
$(SIGNATURES) | ||
""" | ||
function latin24() | ||
|
||
cps = latin24alphabet() * latinpunctuation() * latinwhitespace() * "+" | ||
ttypes = [ | ||
Orthography.LexicalToken, | ||
#Orthography.NumericToken, | ||
Orthography.PunctuationToken, | ||
EncliticToken | ||
] | ||
Latin24(cps, ttypes, tokenizeLatin24) | ||
end | ||
|
||
"""Define recognized punctuation characters for Latin orthographies. | ||
$(SIGNATURES) | ||
""" | ||
function punctuation(ortho::Latin24) | ||
latinpunctuation() | ||
end | ||
|
||
|
||
"""Tokenize Latin text. | ||
$(SIGNATURES) | ||
""" | ||
function tokenizeLatin24(s::AbstractString) | ||
wsdelimited = split(s) | ||
|
||
depunctuated = map(nows -> splitPunctuation(nows, latin24()), wsdelimited) |> Iterators.flatten |> collect | ||
|
||
tknstrings = [] | ||
for depunctedstr in depunctuated | ||
parts = split(depunctedstr, "+") | ||
if length(parts) == 2 | ||
push!(tknstrings, parts[1]) | ||
push!(tknstrings, string("+", parts[2])) | ||
else | ||
push!(tknstrings, depunctedstr) | ||
end | ||
|
||
end | ||
tkns = map(t -> tokenforstring(t, latin24()), tknstrings) | ||
end | ||
|
||
"""True if all characters in s are alphabetic. | ||
$(SIGNATURES) | ||
""" | ||
function isAlphabetic(s::AbstractString, ortho::Latin24) | ||
#chlist = split(s,"") | ||
alphas = alphabetic(ortho) | ||
tfs = [] | ||
for i in collect(eachindex(s)) | ||
push!(tfs, occursin(s[i], alphas)) | ||
end | ||
nogood = false in tfs | ||
|
||
!nogood | ||
end | ||
|
||
"""True if all characters in s are punctuation. | ||
$(SIGNATURES) | ||
""" | ||
function isPunctuation(s::AbstractString, ortho::Latin24)::Bool | ||
#chlist = split(s,"") | ||
puncts = punctuation(ortho) | ||
tfs = [] | ||
for i in collect(eachindex(s)) | ||
push!(tfs, occursin(s[i], puncts)) | ||
end | ||
nogood = false in tfs | ||
|
||
!nogood | ||
end | ||
|
Oops, something went wrong.