taf_post_processor module
- class py_amr2fred.taf_post_processor.TafPostProcessor
Bases:
objectA class for post-processing RDF graphs by performing entity disambiguation using Word Sense Disambiguation (WSD) and linking entities to external knowledge bases.
- disambiguate(text: str, rdf_graph: Graph, namespace: str | None = 'http://www.ontologydesignpatterns.org/ont/fred/domain.owl#') Graph
Disambiguates entities in an RDF graph using Word Sense Disambiguation (WSD) and links them to WordNet synsets.
- Parameters:
- Return type:
Graph
- Returns:
The updated RDF graph with disambiguated entities linked to WordNet.
- disambiguate_usea(text: str, rdf_graph: Graph, namespace: str | None = 'http://www.ontologydesignpatterns.org/ont/fred/domain.owl#') Graph
Disambiguates entities in a multilingual RDF graph using Word Sense Disambiguation (WSD) with the Usea algorithm and aligns them with WordNet synsets.
This method processes an RDF graph by identifying entities requiring disambiguation, performing WSD on the input text, and linking the identified entities to appropriate WordNet synsets (either WN30 or WN31). If no disambiguation is found, the original graph is returned unchanged.
- Parameters:
text (str) – The textual content from which entities are disambiguated.
rdf_graph (Graph) – The RDF graph containing entities to be disambiguated.
namespace – The namespace prefix (optional) for filtering entities. Defaults to Glossary.FRED_NS.
- Return type:
Graph
- Returns:
The updated RDF graph with entities linked to WordNet synsets when possible.
- link_to_wikidata(rdf_graph: Graph) Graph
Links entities in the RDF graph to Wikidata using Wikipedia mappings.
This method identifies entities in the RDF graph that are aligned with DBpedia and attempts to link them to their corresponding Wikidata entities. It ensures that the required database for mapping is available, downloading and extracting it if necessary.
- Parameters:
rdf_graph (Graph) – The input RDF graph containing entities to be linked.
- Returns:
The RDF graph with additional owl:sameAs links to Wikidata entities.
- Return type:
Graph
- wsd_usea(text: str)
Performs Word Sense Disambiguation (WSD) using the Usea services.
This method preprocesses the input text and applies WSD via external Usea services. It first sends the text to a preprocessing endpoint and then performs WSD on the processed output, returning disambiguated tokens.