Package org.apache.nlpcraft.model.tools.test

Contains model testing framework.

Here's an code snippet of using direct test client for Alarm Clock example illustrating the usage of test framework together with JUnit 5:

 public class AlarmTest {
     private NCTestClient cli;

     @BeforeEach
     void setUp() throws NCException, IOException {
         NCEmbeddedProbe.start(AlarmModel.class);

         cli = new NCTestClientBuilder().newBuilder().build();

         cli.open("nlpcraft.alarm.ex");
     }

     @AfterEach
     void tearDown() throws NCException, IOException {
         if (cli != null)
             cli.close();

         NCEmbeddedProbe.stop();
     }

     @Test
     public void test() throws NCException, IOException {
         // Empty parameter.
         assertTrue(cli.ask("").isFailed());

         // Only latin charset is supported.
         assertTrue(cli.ask("El tiempo en EspaƱa").isFailed());

         // Should be passed.
         assertTrue(cli.ask("Ping me in 3 minutes").isOk());
         assertTrue(cli.ask("Buzz me in an hour and 15mins").isOk());
         assertTrue(cli.ask("Set my alarm for 30s").isOk());
     }
 }
 

You can also automatically verify the same model by using NCTestAutoModelValidator class without any additional coding utilizing NCIntentSample or NCIntentSampleRef annotation on the models' callback method. This automatic model validation consists of starting an embedded probe with a given model, scanning for these annotations and their corresponding callback methods, submitting each sample input sentences from the annotations and checking that resulting intent matches the intent the sample was attached to.

Add necessary classpath and run the following command:

     java -ea -DNLPCRAFT_TEST_MODELS=org.apache.nlpcraft.examples.alarm.AlarmModel org.apache.nlpcraft.model.tools.test.NCTestAutoModelValidator