Class NCTestAutoModelValidator


  • public class NCTestAutoModelValidator
    extends Object
    Auto-validator for models based on NCIntentSample annotations. This class takes one or more model IDs (or class names) and performs validation. Validation consists of starting an embedded probe with a given model, scanning for NCIntentSample annotations and their corresponding callback methods, submitting each sample input sentences from NCIntentSample annotation and checking that resulting intent matches the intent the sample was attached to.

    Note that there can be more than one NCIntentSample annotation attached to the intent callback. Each such annotation will trigger conversation STM reset before its samples will be submitted. This gives an opportunity to test samples both with and without conversational context as well as the same sample but with multiple different conversation contexts.

    This class can be used in two modes:

    • As a standalone application supplying model classes using NLPCRAFT_TEST_MODELS system property. In this mode it can be used to automatically test models from IDE, maven builds, etc. without creating a separate, dedicated unit test for it.
    • As a utility class that can be called programmatically from other classes, e.g. unit tests. See various isValid(...) methods for more details.

    See Alarm Clock, Light Switch, and Weather Bot examples for usage of model auto-validator.

    See Also:
    NCIntentSample, NCIntent, NCIntentRef
    • Constructor Detail

      • NCTestAutoModelValidator

        public NCTestAutoModelValidator()
    • Method Detail

      • main

        public static void main​(String[] args)
                         throws Exception
        Performs validation based on NCIntentSample annotations.

        Entry point for a standalone application that expects model classes supplied using NLPCRAFT_TEST_MODELS system property. This system property should have a comma separated list of data model class names. In this mode it can be used to automatically test models from IDE, maven builds, etc. without creating a separate, dedicated unit test for it.

        Note that standard validation output will be printed out to the configured logger (e.g. log4j), if any.

        Parameters:
        args - These arguments are ignored.
        Throws:
        Exception - Thrown in case of any unexpected errors during validation. Note that standard validation output will be printed out to the configured logger.
      • isValid

        public static boolean isValid()
                               throws Exception
        Performs validation based on NCIntentSample annotations. Similar to the standard main(String[]), this method expects model classes supplied using NLPCRAFT_TEST_MODELS system property. This system property should have a comma separated list of data model class names.
        Returns:
        True if no validation errors found, false otherwise. Note that standard validation output will be printed out to the configured logger (e.g. log4j), if any.
        Throws:
        Exception - Thrown in case of any unexpected errors during validation. Note that standard validation output will be printed out to the configured logger (e.g. log4j), if any.
      • isValid

        public static boolean isValid​(Class<NCModel> claxx)
                               throws Exception
        Performs validation based on NCIntentSample annotations for given model.
        Parameters:
        claxx - Data model class.
        Returns:
        True if no validation errors found, false otherwise. Note that standard validation output will be printed out to the configured logger (e.g. log4j), if any.
        Throws:
        Exception - Thrown in case of any unexpected errors during validation. Note that standard validation output will be printed out to the configured logger (e.g. log4j), if any.
      • isValid

        public static boolean isValid​(String... mdlIds)
                               throws Exception
        Performs validation based on NCIntentSample annotations for given models.
        Parameters:
        mdlIds - One or more ID of the model to validate.
        Returns:
        True if no validation errors found, false otherwise. Note that standard validation output will be printed out to the configured logger (e.g. log4j), if any.
        Throws:
        Exception - Thrown in case of any unexpected errors during validation. Note that standard validation output will be printed out to the configured logger (e.g. log4j), if any.
        See Also:
        NCModelView.getId()
      • isValid

        public static boolean isValid​(String mdlIds)
                               throws Exception
        Performs validation based on NCIntentSample annotations for given models.
        Parameters:
        mdlIds - Comma separate list of one or more model IDs to validate.
        Returns:
        True if no validation errors found, false otherwise. Note that standard validation output will be printed out to the configured logger.
        Throws:
        Exception - Thrown in case of any unexpected errors during validation. Note that standard validation output will be printed out to the configured logger.
        See Also:
        NCModelView.getId()
      • isValid

        public static boolean isValid​(Collection<String> mdlIds)
                               throws Exception
        Performs validation based on NCIntentSample annotations for given models.
        Parameters:
        mdlIds - Collection of model IDs to validate.
        Returns:
        True if no validation errors found, false otherwise. Note that standard validation output will be printed out to the configured logger (e.g. log4j), if any.
        Throws:
        Exception - Thrown in case of any unexpected errors during validation. Note that standard validation output will be printed out to the configured logger (e.g. log4j), if any.
        See Also:
        NCModelView.getId()