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

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

@ -306,9 +306,13 @@ public final class yacy {
HTTPClient.setDefaultUserAgent(ClientIdentification.getUserAgent()); HTTPClient.setDefaultUserAgent(ClientIdentification.getUserAgent());
// initial fill of the triplestore // initial fill of the triplestore
mkdirIfNeseccary (new File(sb.getConfig("triplestore", new File (dataHome, "DATA/TRIPLESTORE").toString()))); File triplestore = new File(sb.getConfig("triplestore", new File(dataHome, "DATA/TRIPLESTORE").getAbsolutePath()));
if (sb.getConfigBool("triplestore.persistent", false) == true) { mkdirIfNeseccary(triplestore);
TripleStore.Load(sb.getConfig("triplestore", new File(dataHome, "DATA/TRIPLESTORE").toString())+"/local.rdf"); 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 // start main threads
@ -430,8 +434,9 @@ public final class yacy {
} finally { } finally {
} }
if (sb.getConfigBool("triplestore.persistent", false) == true) { if (sb.getConfigBool("triplestore.persistent", false)) {
TripleStore.Save(sb.getConfig("triplestore", new File(dataHome, "DATA/TRIPLESTORE").toString())+"/local.rdf"); 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)"); Log.logConfig("SHUTDOWN", "goodbye. (this is the last line)");

Loading…
Cancel
Save