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

47
LINES

< > BotCompany Repo | #1005508 // Parse Sentence Multi 5, using rules [WORKS]

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

Libraryless. Click here for Pure Java version (5853L/38K/126K).

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

Author comment

Began life as a copy of #1005502

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: #1005508
Snippet name: Parse Sentence Multi 5, using rules [WORKS]
Eternal ID of this version: #1005508/1
Text MD5: b887ab736f382e72cc0a7c694c1465da
Transpilation MD5: 5b59bc5e8557bb97641a458df19acc7e
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-11-24 00:26:06
Source code size: 1167 bytes / 47 lines
Pitched / IR pitched: No / No
Views / Downloads: 480 / 526
Referenced in: [show references]