|
|
@ -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 {
|
|
|
|
// read the RDF/XML file
|
|
|
|
InputStream in = FileManager.get().open(filename);
|
|
|
|
tmp.read(is, null);
|
|
|
|
|
|
|
|
Log.logInfo("TRIPLESTORE", "loaded " + tmp.size() + " triples from " + fileNameOrUri);
|
|
|
|
// read the RDF/XML file
|
|
|
|
model = model.union(tmp);
|
|
|
|
tmp.read(in, null);
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
throw new IOException("cannot read " + fileNameOrUri);
|
|
|
|
finally
|
|
|
|
}
|
|
|
|
{
|
|
|
|
|
|
|
|
model = model.union(tmp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|