Triplestore: initalize per-user triplestores

pull/1/head
cominch 13 years ago
parent 60f92a4902
commit a95127c9af

@ -34,6 +34,7 @@ public class JenaTripleStore {
public static Model model = ModelFactory.createDefaultModel(); public static Model model = ModelFactory.createDefaultModel();
static { static {
init(); init();
} }
private final static void init() { private final static void init() {
model.setNsPrefix(YaCyMetadata.PREFIX, YaCyMetadata.NAMESPACE); model.setNsPrefix(YaCyMetadata.PREFIX, YaCyMetadata.NAMESPACE);
@ -99,8 +100,12 @@ public class JenaTripleStore {
} }
} }
public static void saveFile(String filename) {
saveFile(filename, model);
}
public static void saveFile(String filename) { public static void saveFile(String filename, Model model) {
Log.logInfo("TRIPLESTORE", "Saving triplestore with " + model.size() + " triples to " + filename); Log.logInfo("TRIPLESTORE", "Saving triplestore with " + model.size() + " triples to " + filename);
FileOutputStream fout; FileOutputStream fout;
try { try {
@ -177,9 +182,13 @@ public class JenaTripleStore {
}; };
} }
public static void initPrivateStores(Switchboard switchboard) { public static void initPrivateStores() {
Switchboard switchboard = Switchboard.getSwitchboard();
Log.logInfo("TRIPLESTORE", "Init private stores"); Log.logInfo("TRIPLESTORE", "Init private stores");
if (privatestorage == null) privatestorage = new ConcurrentHashMap<String, Model>();
if (privatestorage != null) privatestorage.clear(); if (privatestorage != null) privatestorage.clear();
@ -191,57 +200,69 @@ public class JenaTripleStore {
de.anomic.data.UserDB.Entry e = it.next(); de.anomic.data.UserDB.Entry e = it.next();
String username = e.getUserName(); String username = e.getUserName();
Log.logInfo("TRIPLESTORE", "Init " + username); File triplestore = new File(switchboard.getConfig("triplestore", new File(switchboard.getDataPath(), "DATA/TRIPLESTORE").getAbsolutePath()));
String filename = new File(switchboard.getConfig("dataRoot", ""), "DATA/TRIPLESTORE").toString()+"/"+username+"_triplestore.rdf"; File currentuserfile = new File(triplestore, "private_store_"+username+".rdf");
Model tmp = ModelFactory.createDefaultModel(); Log.logInfo("TRIPLESTORE", "Init " + username + " from "+currentuserfile.getAbsolutePath());
Log.logInfo("TRIPLESTORE", "Loading from " + filename); Model tmp = ModelFactory.createDefaultModel();
try { tmp.setNsPrefix(YaCyMetadata.PREFIX, YaCyMetadata.NAMESPACE);
InputStream in = FileManager.get().open(filename); tmp.setNsPrefix(Tagging.DEFAULT_PREFIX, Tagging.DEFAULT_NAMESPACE);
tmp.setNsPrefix(HttpHeader.PREFIX, HttpHeader.NAMESPACE);
// read the RDF/XML file tmp.setNsPrefix(Geo.PREFIX, Geo.NAMESPACE);
tmp.read(in, null); tmp.setNsPrefix("pnd", "http://dbpedia.org/ontology/individualisedPnd");
} tmp.setNsPrefix(DCTerms.PREFIX, DCTerms.NAMESPACE);
finally
{
privatestorage.put(username, tmp); if (currentuserfile.exists()) {
}
Log.logInfo("TRIPLESTORE", "Loading from " + currentuserfile.getAbsolutePath());
InputStream is = FileManager.get().open(currentuserfile.getAbsolutePath());
if (is != null) {
// read the RDF/XML file
tmp.read(is, null);
Log.logInfo("TRIPLESTORE", "loaded " + tmp.size() + " triples from " + currentuserfile.getAbsolutePath());
} else {
throw new IOException("cannot read " + currentuserfile.getAbsolutePath());
}
}
if (tmp != null) {
privatestorage.put(username, tmp);
}
} }
} }
catch (Exception anyex) { catch (Exception anyex) {
Log.logException(anyex);
} }
// create separate model
} }
public static void savePrivateStores(Switchboard switchboard) { public static void savePrivateStores(Switchboard switchboard) {
Log.logInfo("TRIPLESTORE", "Saving user triplestores");
if (privatestorage == null) return; if (privatestorage == null) return;
for (Entry<String, Model> s : privatestorage.entrySet()) { for (Entry<String, Model> s : privatestorage.entrySet()) {
File triplestore = new File(switchboard.getConfig("triplestore", new File(switchboard.getDataPath(), "DATA/TRIPLESTORE").getAbsolutePath()));
File currentuserfile = new File(triplestore, "private_store_"+s.getKey()+".rdf");
String filename = new File(switchboard.getConfig("dataRoot", ""), "DATA/TRIPLESTORE").toString()+"/"+s.getKey()+"_triplestore.rdf"; saveFile (currentuserfile.getAbsolutePath(), s.getValue());
FileOutputStream fout;
try {
fout = new FileOutputStream(filename);
s.getValue().write(fout);
} catch (Exception e) {
// TODO Auto-generated catch block
Log.logWarning("TRIPLESTORE", "Saving to " + filename+" failed");
}
} }
} }

@ -83,6 +83,7 @@ import net.yacy.cora.document.RSSFeed;
import net.yacy.cora.document.RSSMessage; import net.yacy.cora.document.RSSMessage;
import net.yacy.cora.document.RSSReader; import net.yacy.cora.document.RSSReader;
import net.yacy.cora.document.UTF8; import net.yacy.cora.document.UTF8;
import net.yacy.cora.lod.JenaTripleStore;
import net.yacy.cora.protocol.ClientIdentification; import net.yacy.cora.protocol.ClientIdentification;
import net.yacy.cora.protocol.ConnectionInfo; import net.yacy.cora.protocol.ConnectionInfo;
import net.yacy.cora.protocol.Domains; import net.yacy.cora.protocol.Domains;
@ -631,6 +632,9 @@ public final class Switchboard extends serverSwitch
+ " entries" + " entries"
+ ", " + ", "
+ ppRamString(userDbFile.length() / 1024)); + ppRamString(userDbFile.length() / 1024));
// init user triplestores
JenaTripleStore.initPrivateStores();
// init html parser evaluation scheme // init html parser evaluation scheme
File parserPropertiesPath = new File("defaults/"); File parserPropertiesPath = new File("defaults/");
@ -660,7 +664,7 @@ public final class Switchboard extends serverSwitch
} }
} }
}.start(); }.start();
// define a realtime parsable mimetype list // define a realtime parsable mimetype list
this.log.logConfig("Parser: Initializing Mime Type deny list"); this.log.logConfig("Parser: Initializing Mime Type deny list");
TextParser.setDenyMime(getConfig(SwitchboardConstants.PARSER_MIME_DENY, "")); TextParser.setDenyMime(getConfig(SwitchboardConstants.PARSER_MIME_DENY, ""));

@ -310,12 +310,13 @@ public final class yacy {
File triplestore = new File(sb.getConfig("triplestore", new File(dataHome, "DATA/TRIPLESTORE").getAbsolutePath())); File triplestore = new File(sb.getConfig("triplestore", new File(dataHome, "DATA/TRIPLESTORE").getAbsolutePath()));
mkdirIfNeseccary(triplestore); mkdirIfNeseccary(triplestore);
for (String s: triplestore.list()) { for (String s: triplestore.list()) {
if ((s.endsWith(".rdf") || s.endsWith(".nt")) && !s.equals("local.rdf") && !s.endsWith("_triplestore.rdf")) JenaTripleStore.load(new File(triplestore, s).getAbsolutePath()); if ((s.endsWith(".rdf") || s.endsWith(".nt")) && !s.equals("local.rdf") && !s.endsWith("_triplestore.rdf") && !s.startsWith("private_store_")) JenaTripleStore.load(new File(triplestore, s).getAbsolutePath());
} }
if (sb.getConfigBool("triplestore.persistent", false)) { if (sb.getConfigBool("triplestore.persistent", false)) {
File local = new File(triplestore, "local.rdf"); File local = new File(triplestore, "local.rdf");
if (local.exists()) JenaTripleStore.load(local.getAbsolutePath()); if (local.exists()) JenaTripleStore.load(local.getAbsolutePath());
} }
} catch (IOException e) { } catch (IOException e) {
Log.logException(e); Log.logException(e);
} }
@ -442,6 +443,8 @@ public final class yacy {
if (sb.getConfigBool("triplestore.persistent", false)) { if (sb.getConfigBool("triplestore.persistent", false)) {
File triplestore = new File(sb.getConfig("triplestore", new File(dataHome, "DATA/TRIPLESTORE").getAbsolutePath())); File triplestore = new File(sb.getConfig("triplestore", new File(dataHome, "DATA/TRIPLESTORE").getAbsolutePath()));
JenaTripleStore.saveFile(new File(triplestore, "local.rdf").getAbsolutePath()); JenaTripleStore.saveFile(new File(triplestore, "local.rdf").getAbsolutePath());
JenaTripleStore.savePrivateStores(sb);
} }
Log.logConfig("SHUTDOWN", "goodbye. (this is the last line)"); Log.logConfig("SHUTDOWN", "goodbye. (this is the last line)");

Loading…
Cancel
Save