Tutorial 01

Table of contents Next

Description

This is a basic example how nlScript works in principle. It demonstrates the three steps involved:

Please note that the 2nd argument to 'defineSentence' is undefined, so that nothing actually happens when the user clicks on the editor's Run button.

This will be addressed in Tutorial02

For details, see also

The code


<!doctype html>
<html>
  <body>
    <!-- The HTML element that will hold the editor -->
    <div id="nls-container"></div>

    <!-- The only javascript file needed for nlScript -->
    <script src="https://cdn.jsdelivr.net/npm/@nlscript/nlscript@0.3.0/dist/umd/nlScript.js"></script>

    <script>
      // Step 1: Create a parser
      let parser = new nlScript.Parser();
    
      // Step 2: Define the sentences to parse
      //         A sentence may contain one or more variables, which are specified
      //         as {name:type:quantifier}.
      //
      //         The quantifier is optional.
      //
      //         More information about how to declare variables can be found at
      //         https://nlScript.github.io/nlScript-java/variables.html.
      //
      //         More information about other built-in types, apart from 'float', can be found at
      //         https://nlScript.github.io/nlScript-java/#built-in-types
      parser.defineSentence(
        "Apply Gaussian blurring with a standard deviation of {stddev:float} pixel(s).",
        undefined);
      
      // Step 3: Display an editor for the user to enter the input text
      new nlScript.ACEditor(parser, document.getElementById("nls-container"));
    </script>
  </body>
</html>

Demo

The result

There is no result yet, because we haven't specified what to do upon parsing the sentence.