public interface NCElement extends Serializable
Data model element defines an semantic entity that will be detected in the user input. A model element typically is one or more individual words that have a consistent semantic meaning and typically denote a real-world object, such as persons, locations, number, date and time, organizations, products, etc. Such object can be abstract or have a physical existence.
Read full documentation in Data Model section and review examples.
NCCustomParser
Modifier and Type | Method and Description |
---|---|
default String |
getDescription()
Gets optional element description.
|
default List<String> |
getGroups()
Gets the list of groups this elements belongs to.
|
String |
getId()
Gets unique ID of this element.
|
default Map<String,Object> |
getMetadata()
Gets optional user-defined element's metadata.
|
default String |
getParentId()
Gets optional ID of the immediate parent element.
|
default List<String> |
getSynonyms()
Gets the list of synonyms by which this semantic element will be recognized by.
|
default NCValueLoader |
getValueLoader()
Gets optional dynamic value loader.
|
default List<NCValue> |
getValues()
Gets optional map of
values for this element. |
String getId()
This unique ID should be human readable for simpler debugging and testing of the model.
Although element ID could be any arbitrary string it is highly recommended to have
element ID as a lower case string starting with some model prefix, followed by colon and
then the element's name. For example, some built-in NLPCraft IDs are: nlpcraft:date
,
nlpcraft:city
.
Few important notes:
nlpcraft:
are reserved for built-in NLPCraft IDs.
JSON
If using JSON/YAML model presentation this is set by id
property:
"elements": [ { "id": "phone:act", "description": "Phone action.", "synonyms": [ "{give|*} {call|phone|ring|dial|dial up|ping|contact}" ] } ]
NCToken.getId()
default List<String> getGroups()
Model element can belong to one or more groups. By default the element belongs to a single group whose group
ID is equal to its ID
. The proper grouping of the model elements is required for operation
of Short-Term-Memory (STM) in conversation
(if and when conversation
is used). Specifically, a token (i.e. found model element) that is part of the group set will override
other tokens from the same set or a its superset. In other words, tokens with a smaller group set
(more specific token) will override the tokens from a larger group set (more generic tokens).
Note that built-in tokens (including from 3rd party token providers) belong to a single group whose group ID is equal to their IDs.
JSON
If using JSON/YAML model presentation this is set by groups
property:
"elements": [ { "id": "phone:act", "description": "Phone action.", "groups": ["group1", "group2"] "synonyms": [ "{give|*} {call|phone|ring|dial|dial up|ping|contact}" ] } ]
ID
.NCConversation
,
getId()
default Map<String,Object> getMetadata()
token
for this element
is detected in the input this metadata is merged into NCToken.getMetadata()
method returned metadata.
JSON
If using JSON/YAML model presentation this is set by description
property:
"elements": [ { "id": "phone:act", "description": "Phone action.", "synonyms": [ "{give|*} {call|phone|ring|dial|dial up|ping|contact}" ], "metadata": { "str": "val1", "num": 100, "bool": false } } ]
null
if none provided. Default implementation return null
.default String getDescription()
JSON
If using JSON/YAML model presentation this is set by description
property:
"elements": [ { "id": "phone:act", "description": "Phone action.", "synonyms": [ "{give|*} {call|phone|ring|dial|dial up|ping|contact}" ] } ]
null
.default List<NCValue> getValues()
values
for this element.
Each element can generally be recognized either by one of its synonyms or values. Elements and their values are analogous to types and instances of that type in programming languages. Each value has a name and optional set of its own synonyms by which that value, and ultimately its element, can be recognized by. Note that value name itself acts as an implicit synonym even when no additional synonyms added for that value.
Consider this example. A model element x:car
can have:
{transportation|transport|*} {vehicle|car|sedan|auto|automobile|suv|crossover|coupe|truck}
mercedes
with synonyms (mercedes, mercedes-benz, mb, benz)
bmw
with synonyms (bmw, bimmer)
chevrolet
with synonyms (chevy, chevrolet)
x:car
element will be recognized by any of the following input sub-string:
transport car
benz
automobile
transport vehicle
sedan
chevy
bimmer
x:car
JSON
If using JSON/YAML model presentation this is set by values
property:
"elements": [ { "id": "phone:act", "description": "Phone action.", "synonyms": [ "{give|*} {call|phone|ring|dial|dial up|ping|contact}" ], "values": [ { "name": "name1", "synonyms": ["syn1", "syn2"] } ] } ]
null
if not defined.default String getParentId()
NCModel.query(NCQueryContext)
method.
JSON
If using JSON/YAML model presentation this is set by parentId
property:
"elements": [ { "id": "phone:act", "description": "Phone action.", "parentId": "parent", "synonyms": [ "{give|*} {call|phone|ring|dial|dial up|ping|contact}" ] } ]
null
if not specified. Default implementation returns
null
.default List<String> getSynonyms()
JSON
If using JSON/YAML model presentation this is set by synonyms
property:
"elements": [ { "id": "phone:act", "description": "Phone action.", "synonyms": [ "{give|*} {call|phone|ring|dial|dial up|ping|contact}" ] } ]
default NCValueLoader getValueLoader()
getValues()
method. Default implementation returns null
.
JSON
If using JSON/YAML model presentation this is set by valueLoader
property with value
of a fully qualified class name implementing NCValueLoader
interface. Note that
only one instance of the value loader will be created per model and given class name:
"elements": [ { "id": "phone:act", "description": "Phone action.", "synonyms": [ "{give|*} {call|phone|ring|dial|dial up|ping|contact}" ], "values": [ { "name": "name1", "synonyms": ["syn1", "syn2"] } ], "valueLoader": "my.package.ValueLoader" } ]
Copyright © 2020 NLPCraft. All rights reserved.