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

44
LINES

< > BotCompany Repo | #1025615 - smartParser1 [Include]

JavaX fragment (include)

void smartParser1(S program) {
  // split into paragraphs and unindent

  LS paragraphs = map autoUnindent(map rtrim(/*XXX*/ tok_splitAtEmptyLines(program)));
  print("Got " + n2(paragraphs, "parapraph"));

  // print the parapraphs
  print(joinWithEmptyLines(map(s -> indentx("> ", s), paragraphs)));

  // throw away comment-only and quoted paragraphs (assume it's a title)
  LS paragraphs2 = antiFilter(paragraphs, s -> 
    isSingleLine(trim(s)) && isQuoted(trim(s)) || countJavaTokens(s) == 0
    || endsWith(rtrim(s), "----"));
  print("Got " + n2(paragraphs2, "filtered paragraph"));
  print(joinWithEmptyLines(map(s -> indentx("> ", s), paragraphs2)));

  // find fact paragraphs
  
  print(map allLinesAreUnindented(paragraphs2));
  Pair<LS> p1 = filterAntiFilter(s ->
    !isSingleLine(trim(s)) && allLinesAreUnindented(s), paragraphs2);
  LS multiFactParagraphs = p1.a, paragraphs3 = p1.b;

  for (S para : multiFactParagraphs)
    for (S s : tlft(para))
      addFact(s);

  // find logic rules

  new LS paragraphs4;
  for (S para : paragraphs3) {
    PairS p = splitAtDoubleArrow_pair(para);
    if (p == null) continue with paragraphs4.add(para);
    addLogicRule(new LogicRule(splitAtAmpersand2(p.a), splitAtAmpersand2(p.b)));
  }

  pnlStruct("Unparsed - assuming facts", paragraphs4);

  // assume the unparsed stuff consists of facts
  for (S para : paragraphs4)
    addFact(para);
  
  originalFacts = cloneCISet(facts);
}

download  show line numbers  debug dex   

Travelled to 2 computer(s): mqqgnosmbjvj, tvejysmllsmz

No comments. add comment

Snippet ID: #1025615
Snippet name: smartParser1 [Include]
Eternal ID of this version: #1025615/3
Text MD5: b0f0491e88e2b00e73877e7e0eb4ca2b
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-10-09 12:42:36
Source code size: 1485 bytes / 44 lines
Pitched / IR pitched: No / No
Views / Downloads: 13 / 99
Version history: 2 change(s)
Referenced in: [show references]