Transpiled version (40577L) is out of date.
1 | // script that recognizes images or performs some kind of analysis on an image |
2 | concept G22Analyzer > G22LeftArrowScript {
|
3 | new Ref<G22GalleryImage> exampleImage; |
4 | |
5 | @Override GazelleV_LeftArrowScriptParser makeParser() {
|
6 | var parser = super.makeParser(); |
7 | parser.addVar("image", BufferedImage.class, false);
|
8 | parser.addVar("imageStream", SourceTriggeredStream.class, false);
|
9 | parser.addVar("context", G22AnalysisContext.class, false);
|
10 | ret parser; |
11 | } |
12 | |
13 | class CompiledAnalyzer > LASCompileResult {
|
14 | settable double timeout = 10; |
15 | |
16 | G22AnalysisContext createAnalysisContext(BufferedImage image) {
|
17 | ret new G22AnalysisContext(g22utils(), image); |
18 | } |
19 | |
20 | // evaluate directly without registration or timeout |
21 | O get_impl(G22AnalysisContext context) {
|
22 | new FlexibleVarContext ctx; |
23 | ctx.set(image := context.image); |
24 | ctx.set(imageStream := context.imageStream); |
25 | ctx.set(+context); |
26 | ret parsedScript.get(ctx); |
27 | } |
28 | |
29 | O get_impl(BufferedImage image) {
|
30 | ret get_impl(createAnalysisContext(image)); |
31 | } |
32 | |
33 | O get(BufferedImage image) {
|
34 | ret get(createAnalysisContext(image)); |
35 | } |
36 | |
37 | O get(G22AnalysisContext context) {
|
38 | if (context.analyzerResults.containsKey(analyzer())) {
|
39 | O value = context.analyzerResults.get(analyzer()); |
40 | if (value == G22AnalysisContext.calculating) |
41 | fail("Recursive call to analyzer " + this);
|
42 | ret ((OKOrError) value).getMandatory(); |
43 | } |
44 | context.analyzerResults.put(analyzer(), G22AnalysisContext.calculating); |
45 | |
46 | var result = okOrError(-> {
|
47 | if (parsedScript == null) rethrow(compileError); |
48 | if (context.image == null |
49 | && context.imageStream == null) |
50 | fail("Need image or imageStream");
|
51 | |
52 | ret g22utils().evalRegisteredCode(timeout, str(G22Analyzer.this), |
53 | -> get_impl(context)); |
54 | }); |
55 | context.analyzerResults.put(analyzer(), result); |
56 | ret result.getMandatory(); |
57 | } |
58 | } |
59 | |
60 | selfType analyzer() { this; }
|
61 | |
62 | LASCompileResult newCompileResult() { ret new CompiledAnalyzer; }
|
63 | |
64 | CompiledAnalyzer compileForAutoRun() {
|
65 | ret (CompiledAnalyzer) super.compileForAutoRun(); |
66 | } |
67 | } |
Began life as a copy of #1034256
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
| Snippet ID: | #1034598 |
| Snippet name: | G22Analyzer - special left-arrow script for image analyzers |
| Eternal ID of this version: | #1034598/13 |
| Text MD5: | 83830137829080497bf5bbc0b2e8af2e |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-05-02 19:12:35 |
| Source code size: | 2289 bytes / 67 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 674 / 918 |
| Version history: | 12 change(s) |
| Referenced in: | [show references] |