Package 'topomatch'

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

Help Index


Best matches

Description

Best matches

Usage

best_matches(x)

Arguments

x

topomatch object

Value

The original list of toponyms with their best-ranked candidates.

Examples

best_matches(topomatch(c("a", "b"), c("A", "X")))

Exact toponym matches

Description

Exact toponym matches

Usage

exact_matches(x)

Arguments

x

topomatch object

Value

named logical vector

Examples

exact_matches(topomatch(c("a", "b"), "A"))

Similar toponym matches

Description

Similar toponym matches

Usage

similar_matches(x)

Arguments

x

topomatch object

Value

named logical vector

Examples

similar_matches(topomatch(c("a", "b"), "A"))

Toponomy matching

Description

Match a list of toponyms against a list of candidates.

Usage

topomatch(x, candidates)

Arguments

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.

Details

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.

Value

A matrix with x in rows and candidates in columns with matching scores.

Examples

## 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)

Transcribe toponyms according to a topomatch table

Description

Build a function for transcription.

Usage

transcribe(obj, fixes = NULL)

Arguments

obj

A topomatch object.

fixes

A Named character vector of manual fixes.

Details

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.

Value

A function that takes a character vector among the original terms and returns a character vector with the corresponding matches.

Examples

(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.

Trim whitespaces

Description

Remove the whitespace before or after a string of character

Usage

trim(x, internal = TRUE)

Arguments

x

character vector, matrix or array.

internal

logical. Whether to replace sequential internal by a single space

Value

A character object of the same type.

Author(s)

Robert J. Hijmans and Jacob van Etten. The code was borrowed from function trim in package raster.

Examples

trim(c("    hi folks    !   ", "    hello   world    "))

Unmatched toponyms

Description

Vector of toponyms with more than one plausible candidate with the same score.

Usage

unmatched(x)

Arguments

x

topomatch object

Value

named logical vector

Examples

unmatched(topomatch(c("a", "b"), c("A", "X")))