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

42
LINES

< > BotCompany Repo | #1028737 // nla_parse

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4885L/30K).

1  
static NLABlock nla_parse(S text) {
2  
  ret nla_parse(new NLABlock(text));
3  
}
4  
  
5  
// fills and returns original object
6  
static NLABlock nla_parse(NLABlock nla) {
7  
  // parse into lines (or sentences, both is OK)
8  
  
9  
  if (nla.lines == null)
10  
    nla.lines = sentencesOrLines(nla.text);
11  
    
12  
  // parse lines into fragments & define entities
13  
  
14  
  if (nla.parsedLines == null) {
15  
    new Matches m;
16  
    nla.entities = linkedHashSet();
17  
    nla.parsedLines = new L;
18  
    MapSO wordTree = wordTree();
19  
    
20  
    for (int i = 0; i < l(nla.lines); i++) {
21  
      S s = nla.lines.get(i);
22  
      NLABlock.Line line = nla.new Line;
23  
      line.text = s;
24  
      line.proposition = parseToFragmentsUsingWordTree(s, wordTree);
25  
      
26  
      // define entity & extend word tree
27  
      
28  
      if "There is...|there are..." {
29  
        S name = m.rest();
30  
        NLABlock.Entity e = new(name, line);
31  
        if (matchX2("a...|an...", name, m))
32  
          e.addSynonym("the " + m.rest());
33  
        nla.entities.add(e);
34  
        addToWordTree_multi(wordTree, e.synonyms, e);
35  
      }
36  
      
37  
      nla.parsedLines.add(line);
38  
    }
39  
  }
40  
    
41  
  ret nla;
42  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1028737
Snippet name: nla_parse
Eternal ID of this version: #1028737/23
Text MD5: ecba98d9c289aa2c3b08e7c92e795e85
Transpilation MD5: 3d164be759a445c9c490b1b9230f07d5
Author: stefan
Category: javax / natural language assembly
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-10 17:54:11
Source code size: 1149 bytes / 42 lines
Pitched / IR pitched: No / No
Views / Downloads: 258 / 437
Version history: 22 change(s)
Referenced in: [show references]