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

56
LINES

< > BotCompany Repo | #1012446 // webs_readTripleFileAsTriples

JavaX fragment (include)

sbool webs_readTripleFileAsTriples_debug;

static L<TripleWeb> webs_readTripleFileAsTriples(File f) {
  if (hasMultipleCores()) ret webs_readTripleFileAsTriples_parallel2(f);
   
  if (!f.exists()) ret ll();
  Iterator<S> it = linesFromFile(f);
  new L<Symbol> names;
  while (it.hasNext()) {
    S s = trim(it.next());
    if (empty(s)) break;
    names.add(symbol(unquote(s)));
  }
  
  if (webs_readTripleFileAsTriples_debug)
    print("Have " + l(names) + " names");
  
  new L<TripleWeb> triples;
  while (it.hasNext()) {
    S s = it.next();
    pcall {
      addIfNotNull(triples, webs_readTripleFileAsTriples_line(s, names));
    }
  }
  ret triples;
}

static TripleWeb webs_readTripleFileAsTriples_line(S s, L<Symbol> names) {
  L<S> l = javaTokC(s);
  if (l(l) >= 8) {
    S source = intern(unquote(l.get(5)));
    O result = null;
    
    // result
    pcall {
      if (eq(get(l, 8), "(")) {
        int i = indexOf(l, ")", 9);
        if (i >= 0)
          result = safeUnstructure(joinWithSpace(subList(l, 9, i)));
      }
    }
    
    TripleWeb t = newTripleWebWithSourceAndResult(source, result);
    t.a = names.get(parseInt(l.get(0)));
    t.b = names.get(parseInt(l.get(1)));
    t.c = names.get(parseInt(l.get(2)));
    t.globalID(unquote(l.get(3)));
    // t.title = unquote(l.get(4)); // unused
    t.flags = eq(l.get(6), "v") ? 0 : TripleWeb.UNVERIFIED;
    t.created(parseLong(l.get(7)));
    
    ret t;
  } else if (webs_readTripleFileAsTriples_debug)
    print("Wrong number of tokens in line: " + l(l) + " - " + sfu(l));
  null;
}

Author comment

Began life as a copy of #1011762

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1012446
Snippet name: webs_readTripleFileAsTriples
Eternal ID of this version: #1012446/10
Text MD5: 6a3d0bb74557ea51a280da83d92dde83
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-01-01 05:42:00
Source code size: 1617 bytes / 56 lines
Pitched / IR pitched: No / No
Views / Downloads: 303 / 338
Version history: 9 change(s)
Referenced in: [show references]