load all - but not the persistent local.rdf - triples from

DATA/TRIPLESTORE at startup time. The local.rdf is loaded only if the
persistent switch is on (as before).
pull/1/head
Michael Peter Christen 13 years ago
parent a9eb40c160
commit 90c6fc4b63

@ -1,11 +1,13 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.List;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.interaction.TripleStore;
import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.logging.Log;
import net.yacy.search.Switchboard;
@ -69,11 +71,12 @@ public class Triple_p {
newurl = d.getProtocol()+"://"+HTTPDemon.getAlternativeResolver().resolve(d.getHost())+d.getPath();
System.out.println (newurl);
}
TripleStore.Load(newurl);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.logException(e);
} catch (IOException e) {
Log.logException(e);
}
TripleStore.Load (newurl);
}
}

@ -4,6 +4,7 @@ package net.yacy.interaction;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringBufferInputStream;
import java.util.Iterator;
@ -27,26 +28,38 @@ public class TripleStore {
public static String file;
public static void Load (String filename) {
public static void Load(String filename) throws IOException {
if (filename.endsWith(".nt")) LoadNTriples(filename);
else LoadRDF(filename);
}
public static void LoadRDF(String fileNameOrUri) throws IOException {
Model tmp = ModelFactory.createDefaultModel();
Log.logInfo("TRIPLESTORE", "Loading from " + filename);
try {
InputStream in = FileManager.get().open(filename);
Log.logInfo("TRIPLESTORE", "Loading from " + fileNameOrUri);
InputStream is = FileManager.get().open(fileNameOrUri);
if (is != null) {
// read the RDF/XML file
tmp.read(in, null);
}
finally
{
tmp.read(is, null);
Log.logInfo("TRIPLESTORE", "loaded " + tmp.size() + " triples from " + fileNameOrUri);
model = model.union(tmp);
} else {
throw new IOException("cannot read " + fileNameOrUri);
}
}
public static void LoadNTriples(String fileNameOrUri) throws IOException {
Model tmp = ModelFactory.createDefaultModel();
Log.logInfo("TRIPLESTORE", "Loading N-Triples from " + fileNameOrUri);
InputStream is = FileManager.get().open(fileNameOrUri);
if (is != null) {
tmp.read(is, null, "N-TRIPLE");
Log.logInfo("TRIPLESTORE", "loaded " + tmp.size() + " triples from " + fileNameOrUri);
model = model.union(tmp);
//model.write(System.out, "TURTLE");
} else {
throw new IOException("cannot read " + fileNameOrUri);
}
}
public static void Add (String rdffile) {
@ -68,23 +81,16 @@ public class TripleStore {
}
public static void Save (String filename) {
Log.logInfo("TRIPLESTORE", "Saving triplestore with " + model.size() + " triples to " + filename);
FileOutputStream fout;
try {
fout = new FileOutputStream(filename);
model.write(fout);
Log.logInfo("TRIPLESTORE", "Saved triplestore with " + model.size() + " triples to " + filename);
} catch (Exception e) {
// TODO Auto-generated catch block
Log.logWarning("TRIPLESTORE", "Saving to " + filename+" failed");
}
}

@ -306,9 +306,13 @@ public final class yacy {
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");
File triplestore = new File(sb.getConfig("triplestore", new File(dataHome, "DATA/TRIPLESTORE").getAbsolutePath()));
mkdirIfNeseccary(triplestore);
for (String s: triplestore.list()) {
if ((s.endsWith(".rdf") || s.endsWith(".nt")) && !s.equals("local.rdf")) TripleStore.Load(new File(triplestore, s).getAbsolutePath());
}
if (sb.getConfigBool("triplestore.persistent", false)) {
TripleStore.Load(new File(triplestore, "local.rdf").getAbsolutePath());
}
// start main threads
@ -430,8 +434,9 @@ public final class yacy {
} finally {
}
if (sb.getConfigBool("triplestore.persistent", false) == true) {
TripleStore.Save(sb.getConfig("triplestore", new File(dataHome, "DATA/TRIPLESTORE").toString())+"/local.rdf");
if (sb.getConfigBool("triplestore.persistent", false)) {
File triplestore = new File(sb.getConfig("triplestore", new File(dataHome, "DATA/TRIPLESTORE").getAbsolutePath()));
TripleStore.Save(new File(triplestore, "local.rdf").getAbsolutePath());
}
Log.logConfig("SHUTDOWN", "goodbye. (this is the last line)");

Loading…
Cancel
Save