Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

60
LINES

< > BotCompany Repo | #1005487 // Parse Sentence Multi 3, unrollOptions [works]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (5792L/37K/125K).

1  
!752
2  
3  
concepts.
4  
5  
concept Imperative {
6  
  new Ref v; // verb
7  
  new Ref o; // object
8  
  
9  
  sS _fieldOrder = "v o";
10  
}
11  
12  
concept Measurement {
13  
  new Ref x; // e.g. "all"
14  
  new Ref y; // e.g. "programs"
15  
}
16  
17  
concept Addition {
18  
  new Ref x; // e.g. "programs"
19  
  new Ref prep; // preposition, e.g. "with"
20  
  new Ref z; // e.g. "a large number of files"
21  
  
22  
  sS _fieldOrder = "x prep z";
23  
}
24  
25  
p {
26  
  testParse([[Find all programs with a file called "concepts.structure"]]);
27  
}
28  
29  
sbool properSentence(Concept c) {
30  
  if (!c << Imperative || neq(c/Imperative.v, cstr("find"))) false;
31  
  c = c/Imperative.o!;
32  
  ret matchCstr("all programs with a file called *", c);
33  
  //if (!c << Measurement || neq(c/Measurement.x, cstr("all"))) false;
34  
  //c = c/Measurement.y;
35  
}
36  
37  
!include #1005497 // testParse + parseToOptions using unrollOptions
38  
39  
static void parse(S s, Collector<Concept> out) {
40  
  new Matches m;
41  
  
42  
  if (flexMatchStartIC(ll("find"), s, m))
43  
    ret if out.add(cnew(Imperative,
44  
      v := cstr($1),
45  
      o := parseToOptions($2)));
46  
47  
  if (flexMatchStartIC(ll("all", "a"), s, m))
48  
    ret if out.add(cnew(Measurement,
49  
      x := cstr($1),
50  
      y := parseToOptions($2)));
51  
52  
  for (S prep : ll("called", "with"))
53  
    if (flexMatchIC("* \*prep*/ *", s, m))
54  
      ret if out.add(cnew(Addition,
55  
        x := parseToOptions($1),
56  
        prep : = cstr(prep),
57  
        z := parseToOptions($2)));
58  
59  
  out.add(cstr(s)); // default
60  
}

Author comment

Began life as a copy of #1005485

Possible shortening:

"(find) *"  => Imperative
"(all|a) *" => Measurement
"* (called|with) *" => Addition

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1005487
Snippet name: Parse Sentence Multi 3, unrollOptions [works]
Eternal ID of this version: #1005487/1
Text MD5: f9a20dabb2ee9ca0d8267be1b7e2141f
Transpilation MD5: 04cb194aabbeecbc73d472fb9e634acf
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-11-23 22:42:47
Source code size: 1456 bytes / 60 lines
Pitched / IR pitched: No / No
Views / Downloads: 420 / 456
Referenced in: [show references]