Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

Allow TripleStore to be persistent after reboot

cominch282c1620d6e5
diff --git a/source/net/yacy/interaction/TripleStore.java b/source/net/yacy/interaction/TripleStore.java
new file mode 100644
index 000000000..9c7d68cf8
--- /dev/null
+++ b/source/net/yacy/interaction/TripleStore.java
@@ -0,0 +1,78 @@
+// Author: DL
+
+package net.yacy.interaction;
+
+import com.hp.hpl.jena.rdf.model.*;
+import com.hp.hpl.jena.util.FileManager;
+
+import java.io.*;
+
+import net.yacy.kelondro.logging.Log;
+
+
+public class TripleStore {
+
+ public static Model model = ModelFactory.createDefaultModel();
+
+ public static String file;
+
+
+ public static void Load (String filename) {
+
+ Model tmp = ModelFactory.createDefaultModel();
+
+ Log.logInfo("TRIPLESTORE", "Loading from " + filename);
+
+ try {
+ InputStream in = FileManager.get().open(filename);
+
+ // read the RDF/XML file
+ tmp.read(in, null);
+ }
+ finally
+ {
+ model = model.union(tmp);
+ }
+
+ }
+
+
+ public static void Add (String rdffile) {
+
+ Model tmp = ModelFactory.createDefaultModel();
+
+
+ try {
+ @SuppressWarnings("deprecation")
+ InputStream in = new StringBufferInputStream(rdffile);
+
+ // read the RDF/XML file
+ tmp.read(in, null);
+ }
+ finally
+ {
+ model = model.union(tmp);
+ }
+
+ }
+
+ public static void Save (String filename) {
+
+
+ FileOutputStream fout;
+ try {
+
+
+ fout = new FileOutputStream(filename);
+
+ model.write(fout);
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ Log.logWarning("TRIPLESTORE", "Saving to " + filename+" failed");
+ }
+
+
+ }
+
+}
diff --git a/source/net/yacy/yacy.java b/source/net/yacy/yacy.java
index 5c75b74f1..fc64d8a06 100644
--- a/source/net/yacy/yacy.java
+++ b/source/net/yacy/yacy.java
@@ -59,6 +59,7 @@ import net.yacy.cora.sorting.OrderedScoreMap;
import net.yacy.cora.sorting.ScoreMap;
import net.yacy.gui.YaCyApp;
import net.yacy.gui.framework.Browser;
+import net.yacy.interaction.TripleStore;
import net.yacy.kelondro.blob.MapDataMining;
import net.yacy.kelondro.data.meta.URIMetadataRow;
import net.yacy.kelondro.data.word.Word;
@@ -301,6 +302,12 @@ public final class yacy {
// set user-agent
HTTPClient.setDefaultUserAgent(ClientIdentification.getUserAgent());
+
+ // initial fill of the triplestore
+ mkdirIfNeseccary (new File(sb.getConfig("triplestore", new File (dataHome, "DATA/TRIPLESTORE").toString())));
+ if (sb.getConfigBool("triplestore.persistent", false) == true) {
+ TripleStore.Load(sb.getConfig("triplestore", new File(dataHome, "DATA/TRIPLESTORE").toString())+"/local.rdf");
+ }
// start main threads
final String port = sb.getConfig("port", "8090");
@@ -420,6 +427,11 @@ public final class yacy {
Log.logSevere("STARTUP", "FATAL ERROR: " + ee.getMessage(),ee);
} finally {
}
+
+ if (sb.getConfigBool("triplestore.persistent", false) == true) {
+ TripleStore.Save(sb.getConfig("triplestore", new File(dataHome, "DATA/TRIPLESTORE").toString())+"/local.rdf");
+ }
+
Log.logConfig("SHUTDOWN", "goodbye. (this is the last line)");
Log.shutdown();
shutdownSemaphore.release(1000);