Class NCResult

  • All Implemented Interfaces:
    Serializable, NCMetadata

    public class NCResult
    extends org.apache.nlpcraft.model.impl.NCMetadataAdapter
    implements Serializable, NCMetadata
    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)
    Note that all of these types have specific meaning only for REST applications that interpret them accordingly. For example, the REST client interfacing between NLPCraft and Amazon Alexa or Apple HomeKit can only accept text result type and ignore everything else.
    See Also:
    Serialized Form
    • 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)
        Creates text 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)
        Creates html result.
        Parameters:
        html - HTML markup.
        Returns:
        Newly created query result.
      • json

        public static NCResult json​(String json)
        Creates json result. Note that this method will test given JSON string for validness by using com.google.gson.Gson JSON utility. If JSON string is invalid the IllegalArgumentException 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)
        Creates yaml 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 available.
      • setIntentId

        public void setIntentId​(String intentId)
        Sets optional intent ID.
        Parameters:
        intentId - Intent ID to set for this result.