-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial02.py
More file actions
48 lines (34 loc) · 1.46 KB
/
tutorial02.py
File metadata and controls
48 lines (34 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from PySide2.QtWidgets import QApplication
from nlScript.parser import Parser
from nlScript.ui.ui import ACEditor
from preprocessing import Preprocessing
"""
Tutorial02 extends the previous one by specifying a 2nd parameter to
'defineSentence', an object of type Evaluator. Evaluator is an interface with a
single function evaluate(), which is called upon parsing the corresponding sentence.
For details, see
https://nlScript.github.io/nlScript-java/#evaluating-the-parsed-text
"""
if __name__ == '__main__':
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()
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(
"Apply Gaussian blurring with a standard deviation of {stddev:float} pixel(s).",
# The function specified here will be called upon parsing the sentence above
evaluateSentence)
editor = ACEditor(parser)
editor.show()
exit(app.exec_())