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

74
LINES

< > BotCompany Repo | #1012438 // Load & parse triples.gz from GitHub (a once-only 9 MB download)

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Libraryless. Click here for Pure Java version (1559L/11K).

1  
!7
2  
3  
set flag NoComputerID.
4  
set flag LeanMode.
5  
6  
sS url = "https://github.com/stefan-reich/smartbot/releases/download/1/triples.gz";
7  
8  
sclass InfoTriple {
9  
  S a, b, c;     // noun, verb, noun
10  
  S globalID;    // 16 character global ID
11  
  bool verified; // is it reliable information?
12  
  long created;  // unix timestamp
13  
  S source;      // further source info
14  
  
15  
  toString {
16  
    ret "[" + globalID + "] " + ai_renderTriple(a, b, c);
17  
  }
18  
}
19  
20  
static new L<InfoTriple> triples;
21  
22  
p {
23  
  programID = #1012438;
24  
  File file = getProgramFile("triples-1.gz");
25  
  if (fileSize(file) == 0) {
26  
    print("Downloading triples (9 MB).");
27  
    loadBinaryPageToFile(url, file);
28  
  } else
29  
    print("Triples already downloaded.");
30  
  print("Parsing.");
31  
  time {
32  
    // Read names
33  
    
34  
    Iterator<S> it = linesFromFile(file);
35  
    new L<S> names;
36  
    while (it.hasNext()) {
37  
      S s = trim(it.next());
38  
      if (empty(s)) break;
39  
      names.add(unquote(s));
40  
    }
41  
    
42  
    // Read triples
43  
    
44  
    triples = new L;
45  
    while (it.hasNext()) {
46  
      S s = it.next();
47  
      pcall {
48  
        addIfNotNull(triples, readTriple(s, names));
49  
      }
50  
    }
51  
  }
52  
  
53  
  print("Have " + l(triples) + " triples");
54  
  print("Some random triples:");
55  
  print();
56  
  pnl(selectRandom(triples, 10));
57  
}
58  
59  
static InfoTriple readTriple(S s, L<S> names) {
60  
  L<S> l = javaTokC(s);
61  
  if (l(l) == 8) {
62  
    new InfoTriple t;
63  
    t.a = javaIntern(names.get(parseInt(l.get(0))));
64  
    t.b = javaIntern(names.get(parseInt(l.get(1))));
65  
    t.c = javaIntern(names.get(parseInt(l.get(2))));
66  
    t.globalID = unquote(l.get(3));
67  
    // t.title = unquote(l.get(4)); // unused
68  
    t.source = javaIntern(unquote(l.get(5)));
69  
    t.verified = eq(l.get(6), "v");
70  
    t.created = parseLong(l.get(7));
71  
    ret t;
72  
  }
73  
  null;
74  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1012438
Snippet name: Load & parse triples.gz from GitHub (a once-only 9 MB download)
Eternal ID of this version: #1012438/18
Text MD5: b9071021a710f81d1d1963cd3c372534
Transpilation MD5: 518607f84ca2ce4f8ed63364d1158115
Author: stefan
Category: javax / a.i.
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-12-05 13:55:00
Source code size: 1821 bytes / 74 lines
Pitched / IR pitched: No / No
Views / Downloads: 448 / 1281
Version history: 17 change(s)
Referenced in: [show references]