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

80
LINES

< > BotCompany Repo | #1002886 // Download theories & make index (dev.)

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

Transpiled version (2501L) is out of date.

1  
!752
2  
3  
static PersistentMap<S, S> theories;
4  
static new Map<S, Lisp> parsedTheories;
5  
static new Index index;
6  
7  
static class Index {
8  
  new L<L<Lisp>> byArity;
9  
  
10  
  void addTheory(Lisp tree) {
11  
    for (Lisp statement : tree) {
12  
      int arity = statement.size();
13  
      while (arity >= l(byArity))
14  
        byArity.add(new L);
15  
      byArity.get(arity).add(statement);
16  
    }
17  
  }
18  
  
19  
  Lisp searchOne(S query) {
20  
    Lisp tree = nlParse(query);
21  
    int arity = tree.size();
22  
    L<Lisp> entries = get(byArity, arity);
23  
    if (entries != null)
24  
      for (Lisp statement : entries)
25  
        if (match(tree, statement))
26  
          ret statement;
27  
    ret null;
28  
  }
29  
  
30  
  static boolean match(Lisp query, Lisp statement) {
31  
    new HashMap matches;
32  
    //print("Checking: " + nlUnparse(statement));
33  
    ret nlMatch(query, statement, matches);
34  
  }
35  
}
36  
37  
p {
38  
  File theoriesFile = getProgramFile("theories-downloaded");
39  
  int n = (int) theoriesFile.length();
40  
  S url = "http://ai1.lol/1002762/raw/theoriesInc?" + makePostData("n", n);
41  
  S page = loadPage(url);
42  
  S id = firstLine(page);
43  
  page = dropFirstLine(page);
44  
  int m = parseInt(firstLine(page).trim());
45  
  page = dropFirstLine(page);
46  
  page = htmldecode(page);
47  
  //(n + l(toUtf8(page)))
48  
  appendToTextFile(theoriesFile, page);
49  
  int n2 = (int) theoriesFile.length();
50  
  if (m == n2)
51  
    print(n == n2 ? "Nothing to download (n=" + n + ")" : "Sizes ok - " + n + " -> " + n2);
52  
  else
53  
    print("Size mismatch? " + m + "/" + n2);
54  
    
55  
  theories = new PersistentMap(theoriesFile);
56  
  print(theories.size() + " theories. Parsing...");
57  
  
58  
  time {
59  
    for (S theoryName : theories.keySet()) {
60  
      S text = theories.get(theoryName);
61  
      Lisp tree = nlParseExpand(text);
62  
      parsedTheories.put(theoryName, tree);
63  
    }
64  
  }
65  
  
66  
  print("Parsed all. Making index.");
67  
  
68  
  time {
69  
    for (S theoryName : parsedTheories.keySet()) {
70  
      Lisp tree = parsedTheories.get(theoryName);
71  
      index.addTheory(tree);
72  
    }
73  
  }
74  
  
75  
  print("Made index. Trying a search");
76  
  
77  
  S query = "mrshutco lives in $x";
78  
  print(query);
79  
  print("  " + nlUnparse(index.searchOne(query)));
80  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1002886
Snippet name: Download theories & make index (dev.)
Eternal ID of this version: #1002886/2
Text MD5: 3068d782d675c8e75454c9f1397cfc1f
Author: stefan
Category: eleu / nl
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-06-23 14:45:22
Source code size: 2173 bytes / 80 lines
Pitched / IR pitched: No / No
Views / Downloads: 580 / 622
Version history: 1 change(s)
Referenced in: [show references]