Class NCTestAutoModelValidator
- java.lang.Object
-
- org.apache.nlpcraft.model.tools.test.NCTestAutoModelValidator
-
public class NCTestAutoModelValidator extends Object
Auto-validator for models based onNCIntentSample
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 forNCIntentSample
annotations and their corresponding callback methods, submitting each sample input sentences fromNCIntentSample
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
-
As a standalone application supplying model classes using
-
-
Constructor Summary
Constructors Constructor Description NCTestAutoModelValidator()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
isValid()
Performs validation based onNCIntentSample
annotations.static boolean
isValid(Class<NCModel> claxx)
Performs validation based onNCIntentSample
annotations for given model.static boolean
isValid(String mdlIds)
Performs validation based onNCIntentSample
annotations for given models.static boolean
isValid(String... mdlIds)
Performs validation based onNCIntentSample
annotations for given models.static boolean
isValid(Collection<String> mdlIds)
Performs validation based onNCIntentSample
annotations for given models.static void
main(String[] args)
Performs validation based onNCIntentSample
annotations.
-
-
-
Method Detail
-
main
public static void main(String[] args) throws Exception
Performs validation based onNCIntentSample
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 onNCIntentSample
annotations. Similar to the standardmain(String[])
, this method expects model classes supplied usingNLPCRAFT_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 onNCIntentSample
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 onNCIntentSample
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 onNCIntentSample
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 onNCIntentSample
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()
-
-