2.5.0 • Published 8 months ago

pelias-parser v2.5.0

Weekly downloads
222
License
MIT
Repository
github
Last release
8 months ago

Pelias Parser

A natural language classification engine for geocoding.

This library contains primitive 'building blocks' which can be composed together to produce a powerful and flexible natural language parser.

The project was designed and built to work with the Pelias geocoder, so it comes bundled with a parser called AddressParser which can be included in other npm project independent of Pelias.

It is also possible to modify the configuration of AddressParser, the dictionaries or the semantics. You can also easily create a completely new parser to suit your own domain.

AddressParser Example

30 w 26 st nyc 10010

(0.95) ➜ [
  { housenumber: '30' },
  { street: 'w 26 st' },
  { locality: 'nyc' },
  { postcode: '10010' }
]

Application Interfaces

You can access the library via three different interfaces:

  • all parts of the codebase are available in javascript via npm
  • on the command line via the node bin/cli.js script
  • through a web service via the node server/http.js script

the web service provides an interactive demo at the URL /parser/parse

Quick Start

A quick and easy way to get started with the library is to use the command-line interface:

node bin/cli.js West 26th Street, New York, NYC, 10010

cli


Architecture Description

Please refer to the CLI screenshot above for a visual reference.

Tokenization

Tokenization is the process of splitting text into individual words.

The splitting process used by the engine maintains token positions, so it's able to 'remember' where each character was in the original input text.

Tokenization is coloured blue on the command-line.

Span

The most primitive element is called a span, this is essentially just a single string of text with some metadata attached.

The terms word, phrase and section (explained below) are all just ways of using a span.

Section Boundaries

Some parsers like libpostal ignore characters such as comma, tab, newline and quote.

While it's unrealistic to expect commas always being present, it's very useful to record their positions when they are.

These boundary positions help to avoid parsing errors for queries such as Main St, East Village being parsed as Main St East in Village.

Once sections are established there is no 'bleeding' of information between sections, avoiding the issue above.

Word Splitting

Each section is then split in to individual words, by default this simply considers whitespace as a word boundary.

As per the section, the original token positions are maintained.

Phrase Generation

May terms such as 'New York City' span multiple words, these multi-word tokens are called phrases.

In order to be able to classify phrase terms, permutations of adjacent words are generated.

Phrase generation is performed per-section, so it will not generate a phrase which contains words from more than one section.

Phrase generation is controlled by a configuration which specifies things like the minimum & maximum amount of words allowed in a phrase.

Token Graph

A graph is used to associate word, phrase and section elements to each other.

The graph is free-form, so it's easy to add a new relationship between terms in the future, as required.

Graph Example:

// find the next word in this section
word.findOne('next')

// find all words in this phrase
phrase.findAll('child')

Classification

Classification is the process of establishing that a word or phrase represents a 'concept' (such as a street name).

Classification can be based on:

  • Dictionary matching (usually with normalization applied)
  • Pattern matching (such as regular expressions)
  • Composite matching (such as relative positioning)
  • External API calls (such as calling other services)
  • Other semantic matching techniques

Classification is coloured green and red on the command-line.

Classifier Types

The library comes with three generic classifiers which can be extended in order to create a new classifier:

  • WordClassifier
  • PhraseClassifier
  • SectionClassifier

Classifiers

The library comes bundled with a range of classifiers out-of-the box.

You can find them in the /classifier directory, dictionary-based classifiers usually store their data in the /resources directory.

Example of some of the included classifiers:

// word classifiers
HouseNumberClassifier
PostcodeClassifier
StreetPrefixClassifier
StreetSuffixClassifier
CompoundStreetClassifier
DirectionalClassifier
OrdinalClassifier
StopWordClassifier

// phrase classifiers
IntersectionClassifier
PersonClassifier
GivenNameClassifier
SurnameClassifier
PersonalSuffixClassifier
PersonalTitleClassifier
ChainClassifier
PlaceClassifier
WhosOnFirstClassifier

Solvers

Solving is the final process, where solutions are generated based on all the classifications that have been made.

Each parse can contain multiple solutions, each is provided with a confidence score and is displayed sorted from highest scoring solution to lowest scoring.

The core of this process is the ExclusiveCartesianSolver module.

This solver generates all the possible permutations of the different classifications while taking care to:

  • ensure the same span position is not used more than once
  • ensure that the same classification is not used more than once.

After the ExclusiveCartesianSolver has run there are additional solvers which can:

  • filter the solutions to remove inconsistencies
  • add new solutions to provide additional functionality (such as intersections)

Solution Masks

It is possible to produce a simple mask for any generated solution, this is useful for comparing the solution to the original text:

VVV VVVV NN SSSSSSS AAAAAA PPPPP
Foo Cafe 10 Main St London 10010 Earth      

Contributing

Please fork and pull request against upstream master on a feature branch. Pretty please; provide unit tests.

Unit tests

You can run the unit test suite using the command:

$ npm test

Continuous Integration

CI tests every release against all supported Node.js versions.

Versioning

We rely on semantic-release and Greenkeeper to maintain our module and dependency versions.

Greenkeeper badge

2.5.0

8 months ago

2.4.0

1 year ago

2.3.1

1 year ago

2.3.0

2 years ago

2.2.1

2 years ago

2.2.0

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

1.63.0

3 years ago

1.62.0

3 years ago

1.61.0

3 years ago

1.60.0

3 years ago

1.59.0

3 years ago

1.58.0

3 years ago

1.57.2

3 years ago

1.57.1

3 years ago

1.57.0

4 years ago

1.56.1

4 years ago

1.56.0

4 years ago

1.55.0

4 years ago

1.54.0

4 years ago

1.53.0

4 years ago

1.52.0

4 years ago

1.51.0

4 years ago

1.50.0

4 years ago

1.49.1

4 years ago

1.49.0

4 years ago

1.48.0

4 years ago

1.47.1

4 years ago

1.47.0

4 years ago

1.46.0

4 years ago

1.45.2

4 years ago

1.45.1

4 years ago

1.45.0

4 years ago

1.44.0

4 years ago

1.43.1

4 years ago

1.43.0

4 years ago

1.42.0

4 years ago

1.41.0

4 years ago

1.40.0

4 years ago

1.39.1

5 years ago

1.39.0

5 years ago

1.38.0

5 years ago

1.37.0

5 years ago

1.36.0

5 years ago

1.35.0

5 years ago

1.34.0

5 years ago

1.33.0

5 years ago

1.32.0

5 years ago

1.31.0

5 years ago

1.30.0

5 years ago

1.29.0

5 years ago

1.28.0

5 years ago

1.27.1

5 years ago

1.27.0

5 years ago

1.26.0

5 years ago

1.25.0

5 years ago

1.24.0

5 years ago

1.23.0

5 years ago

1.22.0

5 years ago

1.21.0

5 years ago

1.20.0

5 years ago

1.19.0

5 years ago

1.18.0

5 years ago

1.17.0

5 years ago

1.16.0

5 years ago

1.15.0

5 years ago

1.14.0

5 years ago

1.13.0

5 years ago

1.12.0

5 years ago

1.11.0

5 years ago

1.10.0

5 years ago

1.9.0

5 years ago

1.8.0

5 years ago

1.7.0

5 years ago

1.6.0

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago