Worked example: build your own CitableParser
1. Define your parser type
Import CitableParserBuilder
, and define your parser as a subtype of CitableParser
.
using CitableParserBuilder
struct FakeParser <: CitableParser
label
end
fakeParser = FakeParser("Parser generating dummy values")
# output
FakeParser("Parser generating dummy values")
2. Implement parsetoken
Be sure to import CitableParserBuilder: parsetoken
before defining a method of parsetoken
for your parser's type. You're done! You can now use parsetoken
and all the other functions of the ParserTrait
.
import CitableParserBuilder: parsetoken
function parsetoken(s::AbstractString, parser::FakeParser, ortho::T; data = nothing) where {T <: OrthographicSystem}
# Returns only the same analysis no matter
# what the token is
[
Analysis(
s,
LexemeUrn("fakeparser.nolexemeanalysis"),
FormUrn("fakeparser.noformanalysis"),
StemUrn("fakeparser.nostemanalysis"),
RuleUrn("fakeparser.noruleanalysis")
)
]
end
tokenparses = parsetoken("word", fakeParser)
tokenparses[1].token
# output
"word"
wordlist = split("More than one word")
listparses = parselist(wordlist, fakeParser)
length(listparses)
# output
4