High-performance dictionary compilation and multi-pattern matching library for MoonBit.
///|
test {
let entries = [
@moonlexicon.Entry::{ keyword: "MoonBit", label: "language", weight: 10 },
{ keyword: "lexicon", label: "library", weight: 8 },
]
let lexicon = @moonlexicon.compile(entries)
assert_true(lexicon.contains("MoonBit"))
let automaton = @moonlexicon.compile_automaton(entries)
let hits = automaton.find_leftmost_longest("MoonBit lexicon")
debug_inspect(
[
for hit in hits => hit.keyword
],
content=(
#|["MoonBit", "lexicon"]
),
)
}moon run cmd/mainMoonBit language 0 7 10
lexicon library 8 15 8moon run --target native cmd/benchkeyword<TAB>label<TAB>weight
MoonBit<TAB>language<TAB>10
lexicon<TAB>library<TAB>81..5 | ForEach-Object {
(Measure-Command { moon run --target native cmd/bench | Out-Null }).TotalMilliseconds
}moon fmt --check
moon check --target all --deny-warn
moon test --target all --deny-warn
moon run --target native cmd/benchpub(all) struct AnalysisReport {
text_length : Int
match_count : Int
distinct_label_count : Int
distinct_keyword_count : Int
total_weight : Int
covered_characters : Int
unmatched_characters : Int
coverage_percent : Int
overlap_count : Int
longest_span : Int
matches : Array[LexiconMatch]
} derive(Eq, ToJson, Debug)fn Automaton::fuzzy_matches(self : Automaton, text : String, query : String, max_distance? : Int) -> Array[LexiconMatch]fn DictionaryCatalog::lookup(self : DictionaryCatalog, name : String, keyword : String) -> Array[Entry]fn DictionaryCatalog::register_entries(self : DictionaryCatalog, name : String, entries : ArrayView[Entry]) -> Unitfn DictionaryCatalog::scan_query(self : DictionaryCatalog, text : String, query : MatchQuery) -> Array[CatalogHit]pub(all) struct RankedCandidate {
candidate : Candidate
explanation : CandidateExplanation
} derive(Eq, ToJson, Debug)let DICTIONARY_FORMAT_VERSION : Stringfn ascii_bytes_to_string(bytes : Bytes) -> Stringfn benchmark_description() -> Stringfn benchmark_expected_surface_count(size : Int) -> Intfn benchmark_expected_weight(size : Int) -> Intfn benchmark_matches_expected(result : BenchmarkResult, dictionary_size : Int, repeats : Int) -> Boolfn benchmark_text_checksum(text : String) -> Intfn benchmark_text_for_size(size : Int, repeats : Int) -> Stringfn benchmark_workload_checksum(size : Int, repeats : Int) -> Intfn byte_backend_description() -> Stringfn byte_slice(bytes : Bytes, start : Int, end : Int) -> Bytesfn bytes_are_ascii(bytes : Bytes) -> Boolfn bytes_hex_preview(bytes : Bytes, limit : Int) -> Stringfn candidates_at_least(candidates : ArrayView[RankedCandidate], minimum_score : Int) -> Array[RankedCandidate]fn candidates_with_occurrences(candidates : ArrayView[RankedCandidate], minimum_occurrences : Int) -> Array[RankedCandidate]fn context_windows(text : String, matches : ArrayView[LexiconMatch], radius : Int) -> Array[ContextWindow]fn count_normalization_whitespace(text : String) -> Intfn dictionary_format_description() -> Stringfn escape_dictionary_field(value : String) -> Stringfn escaped_character_count(value : String) -> Intfn explain_candidate(matches : ArrayView[LexiconMatch], keyword : String, label : String) -> CandidateExplanation?fn highlight_matches(text : String, matches : ArrayView[LexiconMatch], prefix : String, suffix : String) -> Stringfn integer_width(value : Int) -> Intfn invert_delta(before : ArrayView[Entry], after : ArrayView[Entry], delta : DictionaryDelta) -> DictionaryDeltafn is_dictionary_payload(payload : String) -> Boolfn levenshtein(a : String, b : String, max_distance? : Int) -> Intfn matches_in_range(matches : ArrayView[LexiconMatch], start : Int, end : Int) -> Array[LexiconMatch]fn non_ascii_byte_count(bytes : Bytes) -> Intfn normalization_reports(entries : ArrayView[Entry], options : NormalizationOptions) -> Array[EntryNormalizationReport]fn normalized_lookup(lexicon : Lexicon, query : String, options : NormalizationOptions) -> Array[Entry]fn overlapping_matches(matches : ArrayView[LexiconMatch], target : LexiconMatch) -> Array[LexiconMatch]fn percentage(numerator : Int, denominator : Int) -> Intfn redact_labels(text : String, matches : ArrayView[LexiconMatch], labels : ArrayView[String], replacement : String) -> Stringfn scan_bytes_for_label(automaton : Automaton, bytes : Bytes, label : String) -> Array[LexiconMatch]fn segment_with_options(lexicon : Lexicon, text : String, options : SegmentationOptions) -> TokenSequencefn similarity_score(a : String, b : String) -> Intfn string_to_ascii_bytes(text : String) -> Bytes?fn unescape_dictionary_field(value : String) -> StringInstall
Download zipHigh-performance dictionary compilation and multi-pattern matching library for MoonBit.