| Title: | Match toponyms by similarity |
|---|---|
| Description: | Wraps local-global alignment algorithm borrwed from package Biostrings Works better than global alignment and requires less fine-tuning (although is considerably slower too) https://ro-che.info/articles/2016-12-11-local-alignment. Allows to inspect the matching and act accordingly. |
| Authors: | Facundo Muñoz <[email protected]> |
| Maintainer: | Facundo Muñoz <[email protected]> |
| License: | GPL-3 |
| Version: | 0.5 |
| Built: | 2026-09-30 08:38:50 UTC |
| Source: | https://forge.inrae.fr/umr-astre/topomatch |
Best matches
best_matches(x)best_matches(x)
x |
|
The original list of toponyms with their best-ranked candidates.
best_matches(topomatch(c("a", "b"), c("A", "X")))best_matches(topomatch(c("a", "b"), c("A", "X")))
Exact toponym matches
exact_matches(x)exact_matches(x)
x |
|
named logical vector
exact_matches(topomatch(c("a", "b"), "A"))exact_matches(topomatch(c("a", "b"), "A"))
Similar toponym matches
similar_matches(x)similar_matches(x)
x |
|
named logical vector
similar_matches(topomatch(c("a", "b"), "A"))similar_matches(topomatch(c("a", "b"), "A"))
Match a list of toponyms against a list of candidates.
topomatch(x, candidates)topomatch(x, candidates)
x |
character vector of terms to match, or data.frames with the same number of columns corresponding to different nested levels of administrative units (e.g. region, department, municipality). |
candidates |
character vector or data.frame of terms to compare against. |
For comparison, strings are trimmed off white spaces, converted to upper-case and special characters transliterated to ASCII.
When comparing places defined at multiple hierarchical levels (using multiple columns), the level-wise scores are multiplied.
A matrix with x in rows and candidates in columns with matching scores.
## Match vectors of toponyms x <- c("abá", "Efé", "IJI", "kkk") cand <- c("aba", "ef", "iji", "opo", "Uvu") topomatch(x, cand) ## Match data.frames of toponyms defined at multiple levels x <- data.frame( region = c("A", "A", "B", "B"), province = c("abá", "Efé", "IJI", "kkk") ) cand <- data.frame( reg = c("a", "à", "b", "c", "b"), prov = c("aba", "ef", "iji", "opo", "Uvu") ) topomatch(x, cand)## Match vectors of toponyms x <- c("abá", "Efé", "IJI", "kkk") cand <- c("aba", "ef", "iji", "opo", "Uvu") topomatch(x, cand) ## Match data.frames of toponyms defined at multiple levels x <- data.frame( region = c("A", "A", "B", "B"), province = c("abá", "Efé", "IJI", "kkk") ) cand <- data.frame( reg = c("a", "à", "b", "c", "b"), prov = c("aba", "ef", "iji", "opo", "Uvu") ) topomatch(x, cand)
Build a function for transcription.
transcribe(obj, fixes = NULL)transcribe(obj, fixes = NULL)
obj |
A |
fixes |
A Named character vector of manual fixes. |
If there are any unmatched toponyms, they must be manually matched in fixes for transcription. On the other hand, fixes can provide matches for incorrect associations. See examples.
A function that takes a character vector among the original terms and returns a character vector with the corresponding matches.
(perfect <- topomatch("AFGHANISTAN", "Afghanistan")) transcribe(perfect)("Afghanistan") terms <- c("foo", "bar", "foobar", "X") (mat <- topomatch(terms, c("Foo", "Bar"))) setNames(transcribe(mat, fixes = c(X = "Bar"))(terms), terms) ## You can still transcribe terms that do not need fixes # transcribe(mat)(terms) # Error: X is not fixed transcribe(mat)(c("foo", "bar")) # Works even if X remains unfixed.(perfect <- topomatch("AFGHANISTAN", "Afghanistan")) transcribe(perfect)("Afghanistan") terms <- c("foo", "bar", "foobar", "X") (mat <- topomatch(terms, c("Foo", "Bar"))) setNames(transcribe(mat, fixes = c(X = "Bar"))(terms), terms) ## You can still transcribe terms that do not need fixes # transcribe(mat)(terms) # Error: X is not fixed transcribe(mat)(c("foo", "bar")) # Works even if X remains unfixed.
Remove the whitespace before or after a string of character
trim(x, internal = TRUE)trim(x, internal = TRUE)
x |
character vector, matrix or array. |
internal |
logical. Whether to replace sequential internal by a single space |
A character object of the same type.
Robert J. Hijmans and Jacob van Etten. The code was borrowed
from function trim in package raster.
trim(c(" hi folks ! ", " hello world "))trim(c(" hi folks ! ", " hello world "))
Vector of toponyms with more than one plausible candidate with the same score.
unmatched(x)unmatched(x)
x |
|
named logical vector
unmatched(topomatch(c("a", "b"), c("A", "X")))unmatched(topomatch(c("a", "b"), c("A", "X")))