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

53
LINES

< > BotCompany Repo | #1013308 // ai_writeTripleFile

JavaX fragment (include)

1  
static int ai_writeTripleFile(Collection<TripleWeb> triples, OutputStream out) ctex {
2  
  print("Writing triple file");
3  
  new L<S> names;
4  
  new Map<S, Int> index;
5  
  ai_writeTripleFile_precollectNames(names, index, triples);
6  
  new ByteArrayOutputStream baos;
7  
  PrintWriter writer = utf8printWriter(baos);
8  
  int n = 0;
9  
  for (TripleWeb w : triples) {
10  
    ++n;
11  
    S title = null;
12  
    S moreInfo = quote(str(w.globalID())) + " " + quote(unnull(title)) + " " + quote(unnull(w.source())) + " " + (w.unverified() ? "u" : "v") + " " + w.created();
13  
    O result = w.result();
14  
    if (result != null)
15  
      moreInfo += " (" + sfu(result) + ")";
16  
    
17  
    writer.write(
18  
      ai_writeTripleFile_indexGet(names, index, w.a) + " " +
19  
      ai_writeTripleFile_indexGet(names, index, w.b) + " " +
20  
      ai_writeTripleFile_indexGet(names, index, w.c) + " " + moreInfo + "\n");
21  
  }
22  
  writer.flush();
23  
  //out.println(struct(names));
24  
  print("Have " + n2(names, "name") + ", " + toM(baos.size()) + "M buffered bytes");
25  
  PrintWriter writer2 = utf8printWriter(out);
26  
  for (S s : names)
27  
    writer2.println(quoteUnlessIdentifierOrInteger(s));
28  
  writer2.println();
29  
  writer2.flush();
30  
  baos.writeTo(out);
31  
  ret n;
32  
}
33  
34  
static int ai_writeTripleFile_indexGet(L<S> names, Map<S, Int> index, S s) {
35  
  Int i = index.get(s);
36  
  if (i == null) {
37  
    i = l(names);
38  
    names.add(s);
39  
    index.put(s, i);
40  
  }
41  
  ret i;
42  
}
43  
44  
static void ai_writeTripleFile_precollectNames(L<S> names, Map<S, Int> index, Collection<TripleWeb> triples) {
45  
  for (TripleWeb w : triples) {
46  
    ai_writeTripleFile_indexGet(names, index, w.a);
47  
    ai_writeTripleFile_indexGet(names, index, w.b);
48  
    ai_writeTripleFile_indexGet(names, index, w.c);
49  
  }
50  
  sortInPlaceIC(names);
51  
  index.clear();
52  
  for i over names: index.put(names.get(i), i);
53  
}

Author comment

Began life as a copy of #1011763

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: #1013308
Snippet name: ai_writeTripleFile
Eternal ID of this version: #1013308/15
Text MD5: 9cb716377c5b23c5fd3e73aca52c5787
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:38:58
Source code size: 1830 bytes / 53 lines
Pitched / IR pitched: No / No
Views / Downloads: 423 / 468
Version history: 14 change(s)
Referenced in: [show references]