Skip to main content

A framework for creating scripting interfaces based on natural syntax.

Project description

nlScript: Natural Language Scripting

This is the Python version of nlScript.

The Natural Language Scripting (nlScript) library provides a framework for replacing graphical user interfaces (GUIs) with a unifiedscripting interface based on natural language.

It provides all the tools necessary for creating domain-specific languages with a natural English syntax for any application:

  • Means to define custom lanugage sentences conveniently.
  • Define for each language expression what should happen upon parsing it.
  • A ready editor to be displayed to the user, equipped with autocompletion based on the defined language.
  • Integrated parsing engine and evaluation environment.
  • Tools for debugging the language.
  • Integrated Error handling

Installation

With pip:

python -m -pip install --upgrade nlScript

Basic usage

The Natural Language Scripting framework offers a convenient way to define the sentences your interface should understand, and provides an auto-completion enabled text editor for users to enter their instructions. The following code snippet shows how to create a parser, how to define a pattern for a sentence for it to parse, and how to display the editor:

# Needed for running a PySide2 application
app = QApplication([])

# Create an instance of the processing backend.
preprocessing = Preprocessing(None)

# Load an example image
preprocessing.open('http://imagej.net/images/clown.jpg')
preprocessing.show()

# Create a parser
parser = Parser()

# Define a function to evaluate the sentence below.
def evaluateSentence(pn):
    # The argument given to evaluate(), a ParsedNode, can be used to
    # evaluate the value of the sentence's variables, here 'stddev'.
    # They are accessed by name.
    stddev = pn.evaluate("stddev")

    # Do the actual blurring, using the processing backend.
    preprocessing.gaussianBlur(stddev)


parser.defineSentence(

    # The template of the sentence: any variable which is read from the user's input
    # is written in '{' and '}', and specified by a name, a type and optionally a quantifier
    "Apply Gaussian blurring with a standard deviation of {stddev:float} pixel(s).",

    # The function specified here will be called upon parsing the sentence above
    Evaluator(evaluateSentence))

# Display an editor, to enter and run user input:
editor = ACEditor(parser)
editor.show()

# Needed for running a PySide2 application
exit(app.exec_())

In this example we state that we expect a literal "Apply Gaussian blurring with a standard deviation of ", followed by a floating point number, which we name "stddev" for later reference, followed by the literal "pixel(s).".

Motivation

Graphical user interfaces can easily become complex and confusing as the number of user input parameters increases. This is particularly true if a workflow needs to be configured, where (i) each step has its own set of parameters, (ii) steps can occur in any order and (iii) steps can be repeated arbitrarily. Consider the configuration of an image pre-processing workflow, which consists of the following algorithms, each having its own set of parameters:

  • Gaussian blurring (standard deviation)
  • Median filtering (window radius)
  • Background subtraction (window radius)
  • Conversion to grayscale
  • Intensity normalization

A traditional graphical user interface (GUI) could e.g. look like this:

where the user can activate the various algorithms and specify their parameters as necessary. This user interface however does not take into account that different algorithms could occur repeatedly, and it does not allow to change the order.

Using Natural Language Scripting, we want to implement a text-based interface which reads and executes text like:

Apply Gaussian blurring with a standard deviation of 3 pixel(s).
Subtract the background with a window readius of 30 pixel(s).
Apply Median filtering with a window radius of 1 pixel(s).
Normalize intensities.
Apply Gaussian blurring with a standard deviation of 1 pixel(s).

More information

License

This project is licensed under the MIT License - see the LICENSE.txt file for details.

This project depends on PySide2, which is licensed under LGPL-3.0 License.

Users are entitled to modify and replace the LGPL-licensed PySide2 library. For more details, please refer to the LGPL-3.0 license text included in the LICENSE file.

If you need to install or modify PySide2, it can be obtained from: PySide2 on PyPI

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nlscript-0.3.0.tar.gz (49.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nlScript-0.3.0-py3-none-any.whl (73.8 kB view details)

Uploaded Python 3

File details

Details for the file nlscript-0.3.0.tar.gz.

File metadata

  • Download URL: nlscript-0.3.0.tar.gz
  • Upload date:
  • Size: 49.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.5

File hashes

Hashes for nlscript-0.3.0.tar.gz
Algorithm Hash digest
SHA256 fb9e497a0ea00e2e08fb345c01a74253c86a4accea1cfc572c4489d71d90a679
MD5 43f4d996052ef04dce6b635e7a61b0b5
BLAKE2b-256 1b4fe9292cfe1deb921794a951eaa4ec16862cdecce9cccb8417780ee6547a81

See more details on using hashes here.

File details

Details for the file nlScript-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: nlScript-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 73.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.5

File hashes

Hashes for nlScript-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 007daa47f4a50b4d1d5b84bfe0bd95c8ec1f0c5fc05b957f0a4c6cce1d371f0f
MD5 ccfed81809ee5d5c910b28fb384fdd27
BLAKE2b-256 5e5104208982e94cb8af98a2850aa4c02ae797dee394e92553143f8412ec831c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page