< Approximate String Matching Library - ArtLogic
ArtLogic - Approximate String Matching Library

Approximate String Matching Library

Search 4.5 million records in 50 ms and retrieve the 256 most similar records in ranked order using a single thread (Intel(R) Core(TM) i7-9750H 2.60GHz; files stored on a hard disk)
Source code included (MIT License): C++ class library, MFC GUI sample application, dynamic-link library, and Python class with Tk GUI sample application. UTF-8 character encoding supported.)

Features

(1) Features

Unlike probabilistic AI-based searches, this library uses a deterministic approximate string matching algorithm to reliably and rapidly retrieve records ranked by similarity to the query string.
It can search 4.5 million records and return the top 256 candidates ranked by similarity in 50 ms on a single thread.
Download the source code (free) here (https://github.com/TakanobuSaito/simss).

The following explanation follows the operation of the sample application.

C++ sample application (Windows / Visual Studio)
C++ sample application (Windows / Visual Studio)

(1) Terminology: Source Text File, Key Text File, and Index File

The database to be searched is called the “Source Text File.”
For example, the Source Text File may contain the following records:

路検察審査会 0850824 北海道釧路市柏木町4-7
伊達簡易裁判所 0520021 北海道伊達市末永町47-10
八雲簡易裁判所 0493112 北海道二海郡八雲町末広町184
留萌簡易裁判所 0770037 北海道留萌市沖見町2丁目
遠軽簡易裁判所 0990403 北海道紋別郡遠軽町一条通北2丁目3-25
苫小牧市 0530018 北海道苫小牧市旭町4丁目5-6
歌志内市 0730403 北海道歌志内市字本町5
当別町 0610233 北海道石狩郡当別町白樺町58-9
江差町 0430034 北海道檜山郡江差町字中歌町193-1
上ノ国町 0490611 北海道檜山郡上ノ国町字大留100
厚沢部町 0431113 北海道檜山郡厚沢部町新町207
乙部町 0430103 北海道爾志郡乙部町字緑町388
古平町 0460121 北海道古平郡古平町大字浜町40-4
鷹栖町 0711201 北海道上川郡鷹栖町南一条3丁目5-1
東神楽町 0711501 北海道上川郡東神楽町南一条西1丁目3-2
                    
Each record in the Source Text File is divided into columns by delimiters.
The Key Text File consists of one selected column paired with the corresponding record position.
When the first column is used as the key, the Key Text File looks like this:
[0]釧路検察審査会
[68]伊達簡易裁判所
[142]八雲簡易裁判所
[219]留萌簡易裁判所
[287]遠軽簡易裁判所
[379]苫小牧市
[447]歌志内市
[503]当別町
[571]江差町
[645]上ノ国町
[716]厚沢部町
[784]乙部町
[849]古平町
[920]鷹栖町
[994]東神楽町
                    
The Source Text File can be a text file or a database file, whereas the Key Text File is a text file that can be opened in a text editor.
The library creates an Index File for searching from the Key Text File.

Once the Index File has been created, the Key Text File is no longer needed. Approximate string matching requires only the Index File and the Source Text File.

(2) Overview of Operation

An Index File must be created once, before the first search.
If an Index File already exists, it can be loaded and used for searching.

(3) Creating an Index File

See the terminology section above.
Depending on the number of records in the Source Text File, this process may take several minutes to several tens of minutes.

(4) Approximate String Matching

Open the Index File. This completes almost instantly.
Run approximate string matching as many times as needed. Each search takes approximately several tens to a little over 100 ms.

(2) Algorithm

For implementation details, please refer to the source code.
Only the references are listed here.
The algorithm for generating n-gram data and the approximate string matching algorithm come from different sources.

  1. Algorithm for generating n-gram data
  2. Makoto Nagao (ed.), “Formal Models of Language,” Chapter 2 of Natural Language Processing, Iwanami Lectures on Software Science, Vol. 15 (1996).
    The n-gram generation algorithm described in this reference is very fast, but its quicksort stage is a bottleneck.
    Although quicksort is efficient, it can take considerable time with datasets containing millions of records.
    This program accelerates processing by replacing the quicksort stage with a hybrid of recursive counting sort (histogram sort) and quicksort. For small datasets, quicksort alone is used. For large datasets, counting sort first partitions the data into smaller groups, and quicksort is then applied to each group.

  3. Approximate string matching algorithm
  4. Japanese paper: Naoaki Okazaki and Jun’ichi Tsujii, “A Simple and Efficient Algorithm for Approximate String Matching Based on Set Similarity”
    Naoaki Okazaki, and Jun'ichi Tsujii. Simple and Efficient Algorithm for Approximate Dictionary Matching. In Proceedings of the 23rd International Conference on Computational Linguistics (COLING 2010), pages 851—859, Beijing, China, August 2010.
    The implementation is based on these publications.

    Although Naoaki Okazaki has released his own implementation, this program does not refer to or reuse it. It is an independent implementation written from scratch based on the paper (MIT License).

(3) Source Code

Download the source code (free) here (https://github.com/TakanobuSaito/simss).

The library source code is available free of charge.
It is open-source software under the MIT License; commercial use, modification, and redistribution are permitted. All source code is included, as follows:

  1. Library source code (C++/C)
  2. There are no external library dependencies. The library can be built using only the included source code.
    The library can be built on Windows. The core library is not Windows-dependent, so linking a static library on Linux should also be possible (not yet verified).
    The dynamic-link library portion is Windows-dependent, but it can be ported to Linux without much difficulty.
  3. C++ sample program
  4. GUI version of the dynamic-link library import test program (Windows)
  5. Python sample program
  6. GUI version of the dynamic-link library import test program (cross-platform)

Python sample application (cross-platform)
Python sample application (cross-platform)

C++ Class Library and Multilanguage Dynamic-Link Library Reference Manuals

Provided as HTML files