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

90
LINES

< > BotCompany Repo | #1005038 // Parse Some Text [dev.]

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

Libraryless. Click here for Pure Java version (4020L/26K/89K).

1  
!752
2  
3  
concepts.
4  
5  
// a named concept
6  
concept NConcept {
7  
  S name;
8  
  
9  
  *() {}
10  
  *(S *name) { change(); }
11  
}
12  
13  
concept HasA {
14  
  new Ref<NConcept> a;
15  
  new Ref<NConcept> b;
16  
  
17  
  *() {}
18  
  *(NConcept a, NConcept b) {
19  
    this.a.set(a);
20  
    this.b.set(b);
21  
  }
22  
}
23  
24  
concept IsA {
25  
  new Ref<NConcept> a;
26  
  new Ref<NConcept> b;
27  
  
28  
  *() {}
29  
  *(NConcept a, NConcept b) {
30  
    this.a.set(a);
31  
    this.b.set(b);
32  
  }
33  
}
34  
35  
concept IsCollectionOf {
36  
  new Ref<NConcept> a;
37  
  new Ref<NConcept> b;
38  
  
39  
  *() {}
40  
  *(NConcept a, NConcept b) {
41  
    this.a.set(a);
42  
    this.b.set(b);
43  
  }
44  
}
45  
46  
concept SizeOfCollection extends IsCollectionOf {
47  
  int n;
48  
  
49  
  *() {}
50  
  *(NConcept a, int n, NConcept b) {
51  
    super(a, b);
52  
    this.n = n;
53  
    change();
54  
  }
55  
}
56  
57  
sS text = [[
58  
  What is a FUNCTION?
59  
  A function has a NAME.
60  
  A name is a STRING.
61  
  A STRING is a COLLECTION of CHARACTERS.
62  
  "The ALPHABET" is a COLLECTION of CHARACTERS.
63  
  "The ALPHABET" contains 26 CHARACTERS.
64  
  "The DIGITS" is a COLLECTION of CHARACTERS.
65  
  "The DIGITS" contains 26 CHARACTERS.
66  
  "SPACE" is a CHARACTER.
67  
]];
68  
69  
p {
70  
  loadAndAutoSaveConcepts();
71  
  new Matches m;
72  
  for (S s : toLinesFullTrim(text)) {
73  
    if "What is a *" getConcept(m, 0);
74  
    if "A * has a *" hasA(getConcept(m, 0), getConcept(m, 1));
75  
    if "A * is a collection of *" isCollectionOf(getConcept(m, 0), getConcept(m, 1));
76  
    if (match("A * contains * *", s, m) && isInteger(m.unq(1)))
77  
      sizeOfCollection(getConcept(m, 0), m.psi(1), getConcept(m, 2));
78  
    if "* is a *" isA(getConcept(m, 0), getConcept(m, 1));
79  
  }
80  
}
81  
82  
static NConcept getConcept(Matches m, int i) {
83  
  S conceptName = singular(toLowerCase(m.unq(0)));
84  
  ret uniqueConcept(NConcept.class, "name", conceptName);
85  
}
86  
87  
svoid hasA(NConcept a, NConcept b) { uniqueConcept(HasA.class, "a", a, "b", b); }
88  
svoid isCollectionOf(NConcept a, NConcept b) { uniqueConcept(IsCollectionOf.class, "a", a, "b", b); }
89  
svoid sizeOfCollection(NConcept a, int n, NConcept b) { uniqueConcept(SizeOfCollection.class, "a", a, "n", n, "b", b); }
90  
svoid isA(NConcept a, NConcept b) { uniqueConcept(IsA.class, "a", a, "b", b); }

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: #1005038
Snippet name: Parse Some Text [dev.]
Eternal ID of this version: #1005038/1
Text MD5: dea7a5e8b77cc90aa8ce35cab3a38fc6
Transpilation MD5: 7fac6a87548dd82b9ebf2510ce24294b
Author: stefan
Category: javax / a.i.
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-09-29 23:04:17
Source code size: 2159 bytes / 90 lines
Pitched / IR pitched: No / No
Views / Downloads: 517 / 567
Referenced in: [show references]