Package org.apache.nlpcraft.model
Interface NCMetadata
-
- All Known Subinterfaces:
NCCompany
,NCContext
,NCConversation
,NCCustomElement
,NCDialogFlowItem
,NCElement
,NCEmbeddedResult
,NCIntentMatch
,NCModel
,NCModelView
,NCRequest
,NCToken
,NCUser
,NCVariant
- All Known Implementing Classes:
org.apache.nlpcraft.model.impl.NCMetadataAdapter
,NCModelAdapter
,NCModelFileAdapter
,NCResult
public interface NCMetadata
Provides support for mutable runtime-only metadata.Read full documentation in Data Model section and review examples.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static NCMetadata
apply(Map<String,Object> map)
Factory for creating metadata out of standard map.Map<String,Object>
getMetadata()
Gets mutable metadata underlying container.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.default <T> T
metax(String prop)
Shortcut method to get given mandatory metadata property.
-
-
-
Method Detail
-
apply
static NCMetadata apply(Map<String,Object> map)
Factory for creating metadata out of standard map.- Parameters:
map
- Map to convert to metadata.- Returns:
- Newly created metadata container.
-
getMetadata
Map<String,Object> getMetadata()
Gets mutable metadata underlying container. Returned map can be used to mutate the metadata or perform any other operations.- Returns:
- Mutable, underlying metadata container.
- See Also:
meta(String)
,metaOpt(String)
,meta(String, Object)
-
metaOpt
default <T> Optional<T> metaOpt(String prop)
Shortcut method to get given optional metadata property. Equivalent to:Optional.ofNullable((T)getMetadata().get(prop));
- Type Parameters:
T
- Type of the metadata property.- Parameters:
prop
- Metadata property name.- Returns:
- Metadata optional property value.
-
meta
default <T> T meta(String prop)
Shortcut method to get given metadata property. Equivalent to:(T)getMetadata().get(prop);
- Type Parameters:
T
- Type of the metadata property.- Parameters:
prop
- Metadata property name.- Returns:
- Metadata property value or
null
if given metadata property not found.
-
metax
default <T> T metax(String prop) throws org.apache.nlpcraft.common.NCException
Shortcut method to get given mandatory metadata property. Equivalent to:T t = (T)getMetadata().get(prop); if (t == null) throw new NCException("Mandatory metadata property not found: " + prop); else return t;
- Type Parameters:
T
- Type of the metadata property.- Parameters:
prop
- Metadata property name.- Returns:
- Metadata property value or throws an exception if given metadata property not found.
- Throws:
org.apache.nlpcraft.common.NCException
- Thrown if given metadata property not found.
-
meta
default <T> T meta(String prop, T dflt)
Shortcut method to get given metadata property. Equivalent to:getMetadata().get(tokId, prop, dflt);
- Type Parameters:
T
- Type of the metadata property.- Parameters:
prop
- Metadata property name.dflt
- Default value to return if specified one isn't set.- Returns:
- Metadata property value or default value if one isn't set.
-
-