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

64
LINES

< > BotCompany Repo | #1013307 // ai_compactLiveDB - just store all triples from memory, no attempts at cleaning up the DB

JavaX fragment (include)

1  
static void ai_compactLiveDB(bool withPhase2) {
2  
  new ai_compactLiveDB_Class c;
3  
  c.phase1();
4  
  if (!withPhase2) ret;
5  
  print("PHASE 2 in 5 SECONDS");
6  
  sleepSeconds(5);
7  
  c.phase2();
8  
}
9  
10  
sclass ai_compactLiveDB_Class {
11  
  File mainLog, fTriples, file, file2;
12  
13  
  void phase1() ctex {
14  
    // First, rotate webs-made.txt
15  
    
16  
    mainLog = programFile(#1010745, "webs-made.txt");
17  
    rotateLogFile(mainLog);
18  
    
19  
    File tripelizedDir = programDir(#1010745, "tripelized");
20  
    fTriples = programFile(#1010745, "triples.gz");
21  
  
22  
    // Save triples
23  
    
24  
    file = new File(tripelizedDir, "triples.new.gz");
25  
    OutputStream out = newGZIPOutputStream(file);
26  
    int n = ai_writeTripleFile(ai_allTriples(), out);
27  
    out.close();
28  
29  
    // Save non-triples (don't have any)
30  
    
31  
    file2 = new File(tripelizedDir, "webs-made.new.gz");
32  
    deleteFile(file2);
33  
34  
    print("Stored " + nTriple(n) + " in " + f2s(file) + ", nothing in " + f2s(file2));
35  
  }
36  
 
37  
  void phase2 {
38  
    print("PHASE 2.");
39  
    
40  
    // Move data to backups
41  
    
42  
    File fBackups = programFile(#1010745, "backups");
43  
    for (File f : earlierPartsOfLogFile(mainLog)) {
44  
      int n = 1;
45  
      File p;
46  
      while ((p = newFile(fBackups, dropSuffix(".gz", f.getName()) + ".part" + n + ".gz")).exists()) ++n;
47  
      renameFile_assertTrue(f, p);
48  
    }
49  
    
50  
    // Backup triples.gz
51  
    
52  
    int n = 1;
53  
    File p;
54  
    while ((p = newFile(fBackups, dropSuffix(".gz", fTriples.getName()) + ".part" + n + ".gz")).exists()) ++n;
55  
    renameFile_assertTrue(fTriples, p);
56  
    
57  
    // Rename main files
58  
    renameFile_assertTrue(file, fTriples);
59  
    if (file2.exists())
60  
      renameFile_assertTrue(file2, programFile(#1010745, "webs-made.txt.part1.gz"));
61  
    
62  
    print("DONE.");
63  
  }
64  
}

Author comment

Began life as a copy of #1011778

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: #1013307
Snippet name: ai_compactLiveDB - just store all triples from memory, no attempts at cleaning up the DB
Eternal ID of this version: #1013307/9
Text MD5: 743dd532dd44f3de97a65e7b3872cdeb
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-12-31 20:42:49
Source code size: 1795 bytes / 64 lines
Pitched / IR pitched: No / No
Views / Downloads: 427 / 463
Version history: 8 change(s)
Referenced in: [show references]