Dictionary, thesaurus and term expansion utilities used in natural language processing (NLP).
Contents
Overview
The dictosaurus package provides natural language processing (NLP) utilities used in information retrieval systems. It includes dictionary, thesaurus and term expansion utilities and is intended for information retrieval system applications.
Refer to the references to learn more about information retrieval systems.
Usage
In the pubspec.yaml of your flutter project, add the following dependency:
dependencies:
dictosaurus: <latest_version>
In your code file add the following import:
// import the core interfaces, classes and mixins of the `dictosaurus` library
import 'package:dictosaurus/dictosaurus.dart';
// import the typedefs library to use types defined in the `dictosaurus` package.
import 'package:dictosaurus/type_definitions.dart';
Use of the Dictosaurus is demonstrated below.
// define a term with incorrect spelling.
final misspeltTerm = 'appel';
// define a correctly spelled term.
final term = 'swim';
// get a Dictosaurus instance from an implementation class (not shown here)
final dictoSaurus = await getDictoSaurus();
// get spelling correction suggestions
final corrections = await dictoSaurus.suggestionsFor(misspeltTerm, 5);
// expand the term
final expansions = await dictoSaurus.expandTerm(term, 5);
// get a dictionary entry properties
final entry = await dictoSaurus.getEntry(term);
// get the defintions
final definitions = entry.synonymsOf();
// get the synonyms when used as a verb
final synonyms = entry.synonymsOf(PartOfSpeech.verb);
// get the antonyms
final antonyms = entry.antonymsOf();
// get the inflections
final inflections = entry.inflectionsOf();
// get the phrases
final phrases = entry.phrasesWith();
API
Please refer to the API documentation.
The DictionaryEntry interface is an object model for a term or word with immutable properties (term, stem, lemma, language). The DictionaryEntry interface also enumerates variants of the term with different values for part-of-speech, definition, etymology, pronunciation, synonyms, antonyms and inflections, each with one or more example phrases.
Three interfaces provide dictionary, thesaurus and term expansion functions:
- the Dictionary interface exposes methods that return the properties (etymologies, pronunciations, definitions, inflections, phrases, synonyms or antonyms) of a
term, or a translation of aterm; and - the AutoCorrect interface exposes methods that return alternative spellings for a
termor terms that start with the same characters.
The DictoSaurus interface implements the Dictionary and AutoCorrect interfaces.
The DictoSaurus interface also exposes the expandTerm method that performs term-expansion, returning a list of terms in descending order of relevance (best match first). The (expanded) list of terms includes the term, its synonyms (if any) and spelling correction suggestions.
We use an interface > implementation mixin > base-class > implementation class pattern:
- the
interfaceis an abstract class that exposes fields and methods but contains no implementation code. Theinterfacemay expose a factory constructor that returns animplementation classinstance; - the
implementation mixinimplements theinterfaceclass methods, but not the input fields; and - the
base-classis an abstract class with theimplementation mixinand exposes a default, unnamed generative const constructor for sub-classes. The intention is thatimplementation classesextend thebase class, overriding theinterfaceinput fields with final properties passed in via a const generative constructor. The class naming convention for this pattern is "Interface" > "InterfaceMixin" > "InterfaceBase".
Definitions
The following definitions are used throughout the documentation:
corpus- the collection ofdocumentsfor which anindexis maintained.character filter- filters characters from text in preparation of tokenization.Damerau–Levenshtein distance- a metric for measuring theedit distancebetween twotermsby counting the minimum number of operations (insertions, deletions or substitutions of a single character, or transposition of two adjacent characters) required to change oneterminto the other (from Wikipedia).dictionary (in an index)- a hash ofterms(vocabulary) to the frequency of occurence in thecorpusdocuments.document- a record in thecorpus, that has a unique identifier (docId) in thecorpus's primary key and that contains one or more text fields that are indexed.document frequency (dFt)- the number of documents in thecorpusthat contain a term.edit distance- a measure of how dissimilar two terms are by counting the minimum number of operations required to transform one string into the other (from Wikipedia).etymology- the study of the history of the form of words and, by extension, the origin and evolution of their semantic meaning across time (from Wikipedia).Flesch reading ease score- a readibility measure calculated from sentence length and word length on a 100-point scale. The higher the score, the easier it is to understand the document (from Wikipedia).Flesch-Kincaid grade level- a readibility measure relative to U.S. school grade level. It is also calculated from sentence length and word length (from Wikipedia).IETF language tag- a standardized code or tag that is used to identify human languages in the Internet. (from Wikepedia).index- an inverted index used to look updocumentreferences from thecorpusagainst avocabularyofterms.index-elimination- selecting a subset of the entries in an index where thetermis in the collection oftermsin a search phrase.inverse document frequency (iDft)- a normalized measure of how rare atermis in the corpus. It is defined aslog (N / dft), where N is the total number of terms in the index. TheiDftof a rare term is high, whereas theiDftof a frequent term is likely to be low.Jaccard indexmeasures similarity between finite sample sets, and is defined as the size of the intersection divided by the size of the union of the sample sets (from Wikipedia).Map<String, dynamic>is an acronym for"Java Script Object Notation", a common format for persisting data.k-gram- a sequence of (any) k consecutive characters from aterm. Ak-gramcan start with "$", denoting the start of the term, and end with "$", denoting the end of the term. The 3-grams for "castle" are { $ca, cas, ast, stl, tle, le$ }.lemma or lemmatizer- lemmatisation (or lemmatization) in linguistics is the process of grouping together the inflected forms of a word so they can be analysed as a single item, identified by the word's lemma, or dictionary form (from Wikipedia).Natural language processing (NLP)is a subfield of linguistics, computer science, and artificial intelligence concerned with the interactions between computers and human language, in particular how to program computers to process and analyze large amounts of natural language data (from Wikipedia).Part-of-Speech (PoS) taggingis the task of labelling every word in a sequence of words with a tag indicating what lexical syntactic category it assumes in the given sequence (from Wikipedia).Phonetic transcription- the visual representation of speech sounds (or phones) by means of symbols. The most common type of phonetic transcription uses a phonetic alphabet, such as the International Phonetic Alphabet (from Wikipedia).postings- a separate index that records whichdocumentsthevocabularyoccurs in. In a positionalindex, the postings also records the positions of eachtermin thetextto create a positional invertedindex.postings list- a record of the positions of atermin adocument. A position of atermrefers to the index of thetermin an array that contains all thetermsin thetext. In a zonedindex, thepostings listsrecords the positions of eachtermin thetextazone.stem or stemmer- stemming is the process of reducing inflected (or sometimes derived) words to their word stem, base or root form (generally a written word form) (from Wikipedia).stopwords- common words in a language that are excluded from indexing.term- a word or phrase that is indexed from thecorpus. Thetermmay differ from the actual word used in the corpus depending on thetokenizerused.term filter- filters unwanted terms from a collection of terms (e.g. stopwords), breaks compound terms into separate terms and / or manipulates terms by invoking astemmerand / orlemmatizer.term expansion- finding terms with similar spelling (e.g. spelling correction) or synonyms for a term.term frequency (Ft)- the frequency of atermin an index or indexed object.term position- the zero-based index of atermin an ordered array oftermstokenized from thecorpus.text- the indexable content of adocument.token- representation of atermin a text source returned by atokenizer. The token may include information about thetermsuch as its position(s) (term position) in the text or frequency of occurrence (term frequency).token filter- returns a subset oftokensfrom the tokenizer output.tokenizer- a function that returns a collection oftokens fromtext, after applying a character filter,termfilter, stemmer and / or lemmatizer.vocabulary- the collection oftermsindexed from thecorpus.zone- the field or zone of a document that a term occurs in, used for parametric indexes or where scoring and ranking of search results attribute a higher score to documents that contain a term in a specific zone (e.g. the title rather that the body of a document).
References
- Manning, Raghavan and Schütze, "Introduction to Information Retrieval", Cambridge University Press, 2008
- University of Cambridge, 2016 "Information Retrieval", course notes, Dr Ronan Cummins, 2016
- Wikipedia (1), "Inverted Index", from Wikipedia, the free encyclopedia
- Wikipedia (2), "Lemmatisation", from Wikipedia, the free encyclopedia
- Wikipedia (3), "Stemming", from Wikipedia, the free encyclopedia
- Wikipedia (4), "Synonym", from Wikipedia, the free encyclopedia
- Wikipedia (5), "Jaccard Index", from Wikipedia, the free encyclopedia
- Wikipedia (6), "Flesch–Kincaid readability tests", from Wikipedia, the free encyclopedia
- Wikipedia (7), "Edit distance", from Wikipedia, the free encyclopedia
- Wikipedia (8), "Damerau–Levenshtein distance", from Wikipedia, the free encyclopedia
- Wikipedia (9), "Natural language processing", from Wikipedia, the free encyclopedia
- Wikipedia (10), "IETF language tag", from Wikipedia, the free encyclopedia
- Wikipedia (11), "Phonetic transcription", from Wikipedia, the free encyclopedia
- Wikipedia (12), "Etymology", from Wikipedia, the free encyclopedia
- Wikipedia (13), "Part-of-speech tagging", from Wikipedia, the free encyclopedia
- Wikipedia (14), "Damerau–Levenshtein distance", from Wikipedia, the free encyclopedia
Issues
If you find a bug please fill an issue.
This project is a supporting package for a revenue project that has priority call on resources, so please be patient if we don't respond immediately to issues or pull requests.
Libraries
- dictosaurus
- The
dictosauruspackage providesnatural language processing (NLP)utilities used ininformation retrieval systems. It includes dictionary, thesaurus and term expansion utilities and is intended forinformation retrieval systemapplications. - extensions
- Exports the extension methods exposed by this package. Also exports
the extensions from the
text_analyzerandgmconsult_dart_corepackages. - type_definitions
- Import the
type_definitionslibrary to use types defined in thedictosauruspackage.
