public interface NCToken extends Serializable
NCQueryContext.getVariants()
method) user input. A single
token corresponds to a one or more words, sequential or not, in the user sentence.
Configuring Token Providers
Token providers (built-in or 3rd party) have to be enabled in the REST server configuration.
Data models also have to specify tokens they are expecting the REST server and probe to detect. This is done to
limit the unnecessary processing since implicit enabling of all token providers and all tokens can lead to a
significant slow down of processing. REST server configuration
property nlpcraft.server.tokenProvides
provides the list of enabled token providers.
Data models provide their required tokens in NCModelView.getEnabledTokens()
method.
Read full documentation in Data Model section and review examples.
NCElement
,
NCQueryContext.getVariants()
Modifier and Type | Method and Description |
---|---|
List<String> |
getAncestors()
Gets the list of all parent IDs from this token up to the root.
|
int |
getEndCharIndex()
Gets end character index of this token in the original text.
|
List<String> |
getGroups()
Gets the list of groups this token belongs to.
|
String |
getId()
If this token represents user defined model element this method returns
the ID of that element.
|
Map<String,Object> |
getMetadata()
Gets token metadata.
|
String |
getParentId()
Gets the optional parent ID of the model element this token represents.
|
List<NCToken> |
getPartTokens()
Gets the list of tokens this tokens is composed of.
|
String |
getServerRequestId()
Gets ID of the server request this token is part of.
|
int |
getStartCharIndex()
Gets start character index of this token in the original text.
|
String |
getValue()
Gets the value if this token was detected via element's value (or its synonyms).
|
default boolean |
isChildOf(String tokId)
Tests whether this token is a child of given token ID.
|
default <T> T |
meta(String prop)
Shortcut method to get given metadata property.
|
default <T> T |
meta(String prop,
T dflt)
Shortcut method to get given metadata property.
|
default <T> Optional<T> |
metaOpt(String prop)
Shortcut method to get given optional metadata property.
|
Map<String,Object> getMetadata()
Read full documentation on metadata in Data Model section and review examples.
meta(String)
,
metaOpt(String)
,
meta(String, Object)
default <T> Optional<T> metaOpt(String prop)
Optional.ofNullable((T)getMetadata().get(prop));
T
- Type of the metadata property.prop
- Metadata property name.default <T> T meta(String prop)
(T)getMetadata().get(prop);
T
- Type of the metadata property.prop
- Metadata property name.default <T> T meta(String prop, T dflt)
getMetadata().get(tokId, prop, dflt);
T
- Type of the metadata property.prop
- Metadata property name.dflt
- Default value to return if specified one isn't set.String getServerRequestId()
String getId()
ID
metadata property.NCElement.getId()
,
getMetadata()
String getParentId()
null
if not available.NCElement.getParentId()
,
getAncestors()
List<String> getAncestors()
getParentId()
default boolean isChildOf(String tokId)
return getAncestors().contains(tokId);
tokId
- Ancestor token ID.true
this token is a child of given token ID, false
otherwise.List<NCToken> getPartTokens()
String getValue()
null
. Only applicable for user-defined model elements (built-in tokens
do not have values).null
, if not available.NCElement.getValues()
List<String> getGroups()
NCElement.getGroups()
int getStartCharIndex()
int getEndCharIndex()
Copyright © 2020 NLPCraft. All rights reserved.