1 | sbool webs_readTripleFileAsTriples_debug; |
2 | |
3 | static L<TripleWeb> webs_readTripleFileAsTriples(File f) { |
4 | if (hasMultipleCores()) ret webs_readTripleFileAsTriples_parallel2(f); |
5 | |
6 | if (!f.exists()) ret ll(); |
7 | Iterator<S> it = linesFromFile(f); |
8 | new L<Symbol> names; |
9 | while (it.hasNext()) { |
10 | S s = trim(it.next()); |
11 | if (empty(s)) break; |
12 | names.add(symbol(unquote(s))); |
13 | } |
14 | |
15 | if (webs_readTripleFileAsTriples_debug) |
16 | print("Have " + l(names) + " names"); |
17 | |
18 | new L<TripleWeb> triples; |
19 | while (it.hasNext()) { |
20 | S s = it.next(); |
21 | pcall { |
22 | addIfNotNull(triples, webs_readTripleFileAsTriples_line(s, names)); |
23 | } |
24 | } |
25 | ret triples; |
26 | } |
27 | |
28 | static TripleWeb webs_readTripleFileAsTriples_line(S s, L<Symbol> names) { |
29 | L<S> l = javaTokC(s); |
30 | if (l(l) >= 8) { |
31 | S source = intern(unquote(l.get(5))); |
32 | O result = null; |
33 | |
34 | // result |
35 | pcall { |
36 | if (eq(get(l, 8), "(")) { |
37 | int i = indexOf(l, ")", 9); |
38 | if (i >= 0) |
39 | result = safeUnstructure(joinWithSpace(subList(l, 9, i))); |
40 | } |
41 | } |
42 | |
43 | TripleWeb t = newTripleWebWithSourceAndResult(source, result); |
44 | t.a = names.get(parseInt(l.get(0))); |
45 | t.b = names.get(parseInt(l.get(1))); |
46 | t.c = names.get(parseInt(l.get(2))); |
47 | t.globalID(unquote(l.get(3))); |
48 | // t.title = unquote(l.get(4)); // unused |
49 | t.flags = eq(l.get(6), "v") ? 0 : TripleWeb.UNVERIFIED; |
50 | t.created(parseLong(l.get(7))); |
51 | |
52 | ret t; |
53 | } else if (webs_readTripleFileAsTriples_debug) |
54 | print("Wrong number of tokens in line: " + l(l) + " - " + sfu(l)); |
55 | null; |
56 | } |
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: | 378 / 418 |
Version history: | 9 change(s) |
Referenced in: | [show references] |