Entity Mapper#

In this example, we will map the name of the Person with either a Company or City using the english-entity domain. We will center the mapping around the Person entity and attempt to find all relations with the concepts found in the given sentence. As such, we use Person as the left hand side (lhs), and for the right hand side (rhs) we use Company and City. This results in the mappings: Person -> Company and Person -> City. We also want the gender of the Person so we need to format the gender field using a f-string format like Gender=Person.gender

Introduction#

entity_mapper -i "John Dow works for EyeOnText in Antwerp." --lhs "Person" --rhs "Company,City" -p english,entity --fields "Person,City,Company,Gender=Person.gender"
[
    {"id": "stream_id_111203124502395056", "Person": "John Dow", "Company": "EyeOnText", "Gender": "male"},
    {"id": "stream_id_111203124502395056", "Person": "John Dow", "City": "Antwerp", "Gender": "male"}
]

You can add the -o test.csv option to save it to a CSV file.

Options#

See all the options: EntityMapper API

Using the API#

from eot.wowool.native.core import PipeLine
from eot.wowool.entity_mapper import EntityMapper
from eot.wowool.io.console import console
from eot.wowool.utility.diagnostics import print_diagnostics
import json

pipeline = PipeLine("english,entity")
mapper = EntityMapper(
    lhs="Person",
    rhs=["Company", "City"],
    fields=["Person", "City", "Company", "Gender=Person.gender"],
)
doc = pipeline("John Smith works as a software engineer in EyeOnText.")
doc = mapper(doc)
if doc.results("eot_entity_mapper"):
    print(json.dumps(doc.results("eot_entity_mapper"), indent=2))
else:
    print_diagnostics(doc, console)

Note

City is None as there was no city in the input.

[
  {
    "Person": "John Smith",
    "City": null,
    "Company": "EyeOnText",
    "Gender": "male"
  }
]