t_res.geoparser.linking.Linker

class t_res.geoparser.linking.Linker(resources_path: str, experiments_path: Optional[str] = '../experiments', linking_resources: Optional[dict] = {})

The Linker class provides methods for entity linking, which is the task of associating mentions in text with their corresponding entities in a knowledge base.

Parameters:
  • resources_path (str) – The path to the linking resources.

  • experiments_path (str, optional) – The path to the experiments directory. Default is “../experiments/”.

  • linking_resources (dict, optional) – Dictionary containing the necessary linking resources. Defaults to dict() (an empty dictionary).

This base class should not be instatiated directly. Instead use a subclass constructor.

disambiguate(candidates: List[SentenceCandidates]) Predictions

Perform entity disambiguation given a list of already identified toponyms and selected candidates.

Parameters:

candidates – A list of SentenceCandidates instances.

Returns:

A Predictions instance representing the identified and

linked toponyms.

Return type:

Predictions

disambiguation_scores(links: List[WikidataLink], string_similarity: float) Dict[str, float]

Compute disambiguation scores for a given list Wikidata links.

Parameters:
  • links – A list of WikidataLink instances.

  • string_similarity – (Optional) the string similarity score for the candidate match.

Returns:

A dictionary containing disambiguation scores, keyed by Wikidata ID.

Return type:

dict

empty_candidates(mention: Mention, ranking_method: str, place_of_pub_wqid: str, place_of_pub: str)

Returns an empty Candidates instance.

load()

Loads the linking resources and assigns them to instance variables.

method_name: str = None
new() Linker

Static constructor.

Parameters:

kwargs (dict) – A dictionary of keyword arguments matching the arguments to a subclass __init__ constructor, plus a method_name argument to specify the desired subclass.

Returns:

A Linker subclass instance.

Return type:

Linker

run(matches: CandidateMatches, place_of_pub_wqid: Optional[str] = None, place_of_pub: Optional[str] = None) MentionCandidates

Execute the linking process. Each Linker subclass must implement a linking method by overriding this function.

Parameters:
  • matches – A CandidatesMatches instance.

  • origin_wqid (Optional[str]) – The Wikidata ID of the place of publication.

Returns:

The candidates identified by the linking process.

Return type:

Candidates

wkdt_class(wqid: str) Optional[str]

Returns the Wikidata class for the given Wikidata entry, if available.

linking.RANDOM_SEED = 42