{"id":32619189,"url":"https://github.com/fnl/lexikos","last_synced_at":"2026-06-29T20:31:08.055Z","repository":{"id":10314461,"uuid":"12440714","full_name":"fnl/lexikos","owner":"fnl","description":"a minimal acyclic deterministic finite state automaton (MADFA)","archived":false,"fork":false,"pushed_at":"2014-02-03T14:11:40.000Z","size":232,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-30T18:03:00.936Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fnl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-08-28T17:54:32.000Z","updated_at":"2014-11-27T14:29:00.000Z","dependencies_parsed_at":"2022-09-12T06:01:49.616Z","dependency_job_id":null,"html_url":"https://github.com/fnl/lexikos","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/fnl/lexikos","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnl%2Flexikos","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnl%2Flexikos/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnl%2Flexikos/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnl%2Flexikos/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fnl","download_url":"https://codeload.github.com/fnl/lexikos/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnl%2Flexikos/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34942665,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-29T02:00:05.398Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-30T18:00:47.590Z","updated_at":"2026-06-29T20:31:08.050Z","avatar_url":"https://github.com/fnl.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"Lexicos\n=======\n\nSynopsis\n--------\n\nThis library provides a set-like data structure for [Scala][1], a *Lexicon*.\n\n  [1]: http://www.scala-lang.org/\n\nAbout\n-----\n\nA *Lexicon* is a specialized, immutable, sorted set of sequences containing elements of a generic, but ordered type:\n\n```scala\nLexicon[T \u003c% Ordered[T]] \u003c: SortedSet[Seq[T]]\n```\n\nIt can be used to scan indexed input sequences for the presence of any sequence contained in the set at a given offset in the input sequence.\n\nImplementation\n--------------\n\nTo achieve this behaviour, a Lexicon creates a minimal acyclic deterministic finite state automaton (MADFA) representation of all sequences it contains. To build that MADFA, it uses the linear ( _O(n)_ ) MADFA construction algorithm (see \"Algorithm 1\") described in [Daciuk et al.][2], Comp Ling 2000. Matching the entire set against an input sequence is also approximately linear wrt. the length _m_ of the input sequence ( _O(m)_ ).\n\n  [2]: http://www.mitpressjournals.org/doi/abs/10.1162/089120100561601\n\nAPI\n---\n\nIn addition to the default [SortedSet API][3], a Lexicon provides the following methods:\n\n  [3]: http://www.scala-lang.org/api/2.10.0/index.html#scala.collection.SortedSet\n\n```scala\n/** A Minimal Acyclic DFA (MADFA) data structure for sets of sequences (\"words\")\n  * containing elements (\"symbols\").\n  * A Lexicon has to be built from the sequences (\"words\") in their natural order.\n  * All sequences except the '''empty word''' are valid words. */\nclass Lexicon[T \u003c% Ordered[T]]\n    extends SortedSet[Seq[T]]\n    with SortedSetLike[Seq[T], Lexicon[T]] with Serializable {\n\n  /** Generate a digraph representation of the underlying MADFA in Graphviz DOT format.\n    * @param id name (graph 'ID' in DOT notation) to use for the digraph */\n  def dot(id: String = \"MADFA\"): String\n\n  /** Find the end index of a word in the lexicon that is the longest common prefix in input at\n    * offset `start`.\n    * @param input string to check\n    * @param start offset at which to begin matching (default: 0)\n    * @return the matched word's end offset if any */\n  def indexOf(input: IndexedSeq[T], start: Int = 0): Option[Int] \n\n  /** Get an iterator for all words in the lexicon that start with `prefix`. */\n  def iterator(prefix: Seq[T]): Iterator[Seq[T]]\n\n  /** Get the number of states in the underlying MADFA. */\n  def length: Int\n\n  /** Get the word in the lexicon that is the longest common prefix of `input` at offset `start`.\n    * This is equal to calling `input.slice(start, lexicon.indexOf(input, start).get)` if such a\n    * word and end offset exist.\n    * @param input string to check\n    * @param start offset at which to begin matching (default: 0)\n    * @return the matched word if any */\n  def lookup(input: IndexedSeq[T], start: Int = 0): Option[Seq[T]]\n\n}\n\nobject Lexicon extends {\n\n  /** Build a new Lexicon from a collection of `words`. */\n  def apply[T \u003c% Ordered[T]](words: Seq[T]*): Lexicon[T]\n\n  /** Fetch a new, empty Lexicon. */\n  def empty[T \u003c% Ordered[T]] = new Lexicon[T]\n\n  /** Build a new Lexicon from a sequence of `words`.\n    * This method ensures word order and removes duplicates. */\n  def fromSeq[T \u003c% Ordered[T]](words: Seq[Seq[T]]): Lexicon[T]\n\n  /** Build a new Lexicon from an iterator over ordered, unique `words`.\n    * The caller needs to ensure uniqueness and [natural] order of the words.\n    * @throws AssertionError if the words are not in order or unique */\n  def fromIterator[T \u003c% Ordered[T]](words: Iterator[Seq[T]]): Lexicon[T]\n\n}\n```\n\nCopyright\n---------\n\n\u0026copy; Florian Leitner 2013. All rights reserved.\n\nLicense\n-------\n\nThis library is made available under the terms of the [Apache License, Version 2.0][4].\n\n  [4]: http://www.apache.org/licenses/LICENSE-2.0.html\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnl%2Flexikos","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffnl%2Flexikos","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnl%2Flexikos/lists"}