Package org.apache.nlpcraft.model
Class NCResult
- java.lang.Object
-
- org.apache.nlpcraft.model.NCResult
-
- All Implemented Interfaces:
Serializable
public class NCResult extends Object implements Serializable
Data model result returned from model intent callbacks. Result consists of the text body and the type. The type is similar in notion to MIME types. The following is the list of supported result types:Result types. Result Type Factory Method text
text(String)
html
html(String)
json
json(String)
yaml
yaml(String)
text
result type and ignore everything else.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getBody()
Gets result body.String
getIntentId()
Get optional intent ID.Collection<NCToken>
getTokens()
Gets tokens that were used to produce this query result.String
getType()
Gets result type.static NCResult
html(String html)
Createshtml
result.static NCResult
json(String json)
Createsjson
result.void
setBody(String body)
Sets result body.void
setIntentId(String intentId)
Sets optional intent ID.void
setTokens(Collection<NCToken> tokens)
Sets a collection of tokens that was used to produce this query result.void
setType(String type)
Set result type.static NCResult
text(String txt)
Createstext
result.static NCResult
yaml(String yaml)
Createsyaml
result.
-
-
-
Constructor Detail
-
NCResult
public NCResult(String body, String type)
Creates new result with given body and type.- Parameters:
body
- Result body.type
- Result type.- Throws:
IllegalArgumentException
- Thrown if type is invalid.
-
NCResult
public NCResult()
No-arg constructor.
-
-
Method Detail
-
text
public static NCResult text(String txt)
Createstext
result.- Parameters:
txt
- Textual result. Text interpretation will be defined by the client receiving this result.- Returns:
- Newly created query result.
-
html
public static NCResult html(String html)
Createshtml
result.- Parameters:
html
- HTML markup.- Returns:
- Newly created query result.
-
json
public static NCResult json(String json)
Createsjson
result. Note that this method will test given JSON string for validness by usingcom.google.gson.Gson
JSON utility. If JSON string is invalid theIllegalArgumentException
exception will be thrown.- Parameters:
json
- Any JSON string to be rendered on the client.- Returns:
- Newly created query result.
- Throws:
IllegalArgumentException
- Thrown if given JSON string is invalid.
-
yaml
public static NCResult yaml(String yaml)
Createsyaml
result.- Parameters:
yaml
- Any YAML string to be rendered on the client.- Returns:
- Newly created query result.
-
setBody
public void setBody(String body)
Sets result body.- Parameters:
body
- Result body.
-
setType
public void setType(String type)
Set result type.- Parameters:
type
- Result type.- Throws:
IllegalArgumentException
- Thrown if type is invalid.
-
getTokens
public Collection<NCToken> getTokens()
Gets tokens that were used to produce this query result. Note that the returned tokens can come from the current request as well as from the conversation (i.e. from previous requests). Order of tokens is not important.- Returns:
- Gets tokens that were used to produce this query result.
- See Also:
setTokens(Collection)
-
setTokens
public void setTokens(Collection<NCToken> tokens)
Sets a collection of tokens that was used to produce this query result. Note that the returned tokens can come from the current request as well as from the conversation (i.e. from previous requests). Order of tokens is not important.Providing these tokens is necessary for proper STM operation. If conversational support isn't used setting these tokens is not required. Note that built-in intent based matched automatically sets these tokens.
- Parameters:
tokens
- Collection of tokens that was used to produce this query result.- See Also:
getTokens()
-
getType
public String getType()
Gets result type.- Returns:
- Result type.
-
getBody
public String getBody()
Gets result body.- Returns:
- Result body.
-
getIntentId
public String getIntentId()
Get optional intent ID.- Returns:
- Intent ID or
null
if intent ID was not provided.
-
setIntentId
public void setIntentId(String intentId)
Sets optional intent ID.- Parameters:
intentId
- Intent ID to set for this result.
-
-