0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Find matching names in text, taking account of names that overlap but are different (Waterloo and Waterloo East stations, for example).
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 0
 Project Readme

Name Finder

Find names from a know list in a text, taking account of names that may overlap. For example, Waterloo and Waterloo East are separate stations; NameFinder, knowing both, will not give a false match for Waterloo in a text that mentions Waterloo East.

Examples

require "name_finder"

stations = [
  "Bermondsey",
  "South Bermondsey",
  "Southwark",
  "Waterloo",
  "Waterloo East"
]

nf = NameFinder.new
stations.each do |station|
  nf.add station
end

It can find the best matching name even when one name is the same as part of another, whether they overlap at the start:

nf.find_in "Change here for trains from Waterloo East"
# => "Waterloo East"

nf.find_in "This train terminates at Waterloo"
# => "Waterloo"

or at the end:

nf.find_in "Escalator closed at Bermondsey station"
# => "Bermondsey"

nf.find_in "Use South Bermondsey station for Millwall FC"
# => "South Bermondsey"

It can also find all the matching names, without false positives for names that are part of a longer name:

nf.find_all_in "South Bermondsey and Waterloo East"
# => ["South Bermondsey", "Waterloo East"]

Names that are part of a longer name are still found when listed separately, however:

nf.find_all_in "South Bermondsey and Bermondsey"
# => ["South Bermondsey", "Bermondsey"]

Limitations

The present implementation handles only the letters A-Z. This can be customised by subclassing NameFinder and changing the implementation of normalize. The normalize method must use the same delimiter between words as is returned by the delimiter method (normally a single space).