public class EntityMapper extends Object
This class is configured through the addEntityMapping(EntityType, String)
method, that allows to specify a
mapping from an abstract entity to a concrete entity name. This mapping is used to retrieve
IntentRecognitionProvider
specific entities, and deploy xatkit generically on different platforms.
This class also defines the setFallbackEntityMapping(String)
, that allows to handle abstract entities
that do not have a concrete mapping in the IntentRecognitionProvider
platform.
The mapping for a given abstract entity can be retrieved by calling the getMappingFor(EntityType)
with the
abstractEntity
type as parameter.
Note: this class does not support CustomEntityDefinition
mapping (see
getMappingForCustomEntity(CustomEntityDefinition)
). Since these entities are defined dynamically there is
no facilities to map them in a static way. Concrete EntityMapper
s tailored to a given intent recognition
platform can override the method getMappingForCustomEntity(CustomEntityDefinition)
to implement this
dynamic mapping.
IntentRecognitionProvider
Modifier and Type | Field and Description |
---|---|
protected Map<String,String> |
entities
The
Map storing the abstract-to-concrete entity mappings. |
protected static String |
FALLBACK_ENTITY_KEY
The key used to register the concrete fallback entity.
|
Constructor and Description |
---|
EntityMapper()
Constructs a new
EntityMapper . |
Modifier and Type | Method and Description |
---|---|
void |
addCustomEntityMapping(com.xatkit.intent.CustomEntityDefinition entityDefinition,
String concreteEntity)
Adds a new mapping between the provided
entityDefinition and the given concreteEntity . |
void |
addEntityMapping(com.xatkit.intent.EntityDefinition entityDefinition,
String concreteEntity)
Adds a new mapping between the provided
entityDefinition and the given concreteEntity . |
void |
addEntityMapping(com.xatkit.intent.EntityType abstractEntityType,
String concreteEntity)
Adds a new mapping between the provided
abstractEntityType and the given concreteEntity . |
String |
getMappingFor(com.xatkit.intent.EntityDefinition abstractEntity)
Returns the
concreteEntity mapped to the provided abstractEntity . |
String |
getMappingFor(com.xatkit.intent.EntityType abstractEntityType)
Returns the
concreteEntity mapped to the provided abstractEntityType . |
protected String |
getMappingForCustomEntity(com.xatkit.intent.CustomEntityDefinition customEntityDefinition)
Returns the
String representing the entity mapped from the provided customEntityDefinition . |
void |
removeMappingFor(com.xatkit.intent.EntityDefinition abstractEntity)
Removes the
concreteEntity mapped to the provided abstractEntity . |
void |
setFallbackEntityMapping(String concreteEntity)
Sets the default mapping for
abstractEntities that are not mapped to concrete implementations. |
protected static String FALLBACK_ENTITY_KEY
entities
public EntityMapper()
EntityMapper
.
This constructor initializes this class with an empty mapping, that can be populated using
addEntityMapping(EntityType, String)
and setFallbackEntityMapping(String)
.
public void addEntityMapping(com.xatkit.intent.EntityType abstractEntityType, String concreteEntity)
abstractEntityType
and the given concreteEntity
.
The stored mapping can be accessed by calling getMappingFor(EntityDefinition)
with abstractEntityType
as parameter.
abstractEntityType
- the EntityType
representing the abstract entity to mapconcreteEntity
- the String
representing the concrete entity to associate to the provided abstractEntityType
NullPointerException
- if the provided abstractEntityType
or concreteEntity
is null
getMappingFor(EntityDefinition)
public void addEntityMapping(com.xatkit.intent.EntityDefinition entityDefinition, String concreteEntity)
entityDefinition
and the given concreteEntity
.
The stored mapping can be accessed by calling getMappingFor(EntityDefinition)
with entityDefinition
as parameter.
entityDefinition
- the EntityDefinition
to mapconcreteEntity
- the mapped value associated to the provided entityDefinition
NullPointerException
- if the provided entityDefinition
or concreteEntity
is null
getMappingFor(EntityDefinition)
public void addCustomEntityMapping(com.xatkit.intent.CustomEntityDefinition entityDefinition, String concreteEntity)
entityDefinition
and the given concreteEntity
.
The stored mapping can be accessed by calling getMappingFor(EntityDefinition)
with entityDefinition
as parameter.
entityDefinition
- the CustomEntityDefinition
to mapconcreteEntity
- the mapped value associated to the provided entityDefinition
NullPointerException
- if the provided entityDefinition
or concreteEntity
is null
getMappingFor(EntityDefinition)
public void setFallbackEntityMapping(String concreteEntity)
abstractEntities
that are not mapped to concrete implementations.
This method allows to specify a concreteEntity
that will be mapped to all the abstractEntities
that does not have a direct implementation in the IntentRecognitionProvider
platform. (see
getMappingFor(EntityType)
).
concreteEntity
- the String
representing the concrete entity to use as fallback entityNullPointerException
- if the provided concreteEntity
is null
IllegalArgumentException
- if a concreteEntity
is already registered as fallback entitygetMappingFor(EntityType)
public String getMappingFor(com.xatkit.intent.EntityType abstractEntityType)
concreteEntity
mapped to the provided abstractEntityType
.
This method looks in the registered mappings (set by calling addEntityMapping(EntityType, String)
) and
returns the one associated to the provided abstractEntityType
. If there is no direct mapping for the
abstractEntityType
, the fallback entity (set by calling setFallbackEntityMapping(String)
) is
returned.
abstractEntityType
- the String
representing the abstract entity to retrieve the concrete mapping
fromconcreteEntity
mapped to the provided abstractEntityType
, or null
if there is
no such mappingNullPointerException
- if the provided abstractEntityType
is null
addEntityMapping(EntityType, String)
,
setFallbackEntityMapping(String)
public String getMappingFor(com.xatkit.intent.EntityDefinition abstractEntity)
concreteEntity
mapped to the provided abstractEntity
.
This method looks in the registered mappings (set by calling addEntityMapping(EntityType, String)
) and
returns the one associated to name extracted from the provided abstractEntity
. Name extraction will
downcast the provided EntityDefinition
to BaseEntityDefinition
, and compute the
EntityDefinition
name from its associated EntityType
literal.
If there is no direct mapping for the abstractEntity
extracted name, the fallback entity (set by
calling setFallbackEntityMapping(String)
is returned.
abstractEntity
- the EntityDefinition
representing the abstract entity to retrieve the concrete
mapping fromconcreteEntity
mapped to the provided abstractEntity
, or null
if there is
no such mappingNullPointerException
- if the provided abstractEntity
is null
IllegalArgumentException
- if the provided EntityDefinition
is a BaseEntityDefinition
and its entityType
reference is null
XatkitException
- if the provided abstractEntity
is not supportedprotected String getMappingForCustomEntity(com.xatkit.intent.CustomEntityDefinition customEntityDefinition)
String
representing the entity mapped from the provided customEntityDefinition
.
Note: this method looks for a registered mapping associated to the provided customEntityDefinition
's name. Concrete EntityMapper
s tailored to a given intent recognition platform
can override this method to compute advanced mapping for CustomEntityDefinition
s.
public void removeMappingFor(com.xatkit.intent.EntityDefinition abstractEntity)
concreteEntity
mapped to the provided abstractEntity
.abstractEntity
- the EntityDefinition
representing the abstract entity to retrieve the concrete
mapping fromNullPointerException
- if the provided abstractEntity
is null
IllegalArgumentException
- if the provided EntityDefinition
is a
BaseEntityDefinition
and its entityType
reference is null
XatkitException
- if the provided abstractEntity
is not supportedCopyright © 2020 SOM Research Lab. All rights reserved.