Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for persistent storage with TDB? #2

Open
joelkuiper opened this issue Aug 14, 2018 · 4 comments
Open

Support for persistent storage with TDB? #2

joelkuiper opened this issue Aug 14, 2018 · 4 comments

Comments

@joelkuiper
Copy link

Just wondering if it would be possible to use a TDB model somewhere to persist results?

@levand
Copy link
Contributor

levand commented Aug 20, 2018

Absolutely, shouldn't be hard at all. Aristotle uses the org.apache.jena.graph.Graph interface, though, so you'd need to figure out how best to interface that with the Model API that TDB uses. You might need to build some additional helper functions to avoid doing lots of java interop if you need to interact with the Model API extensively for what you're trying to do.

Keep in mind that for smaller datasets, it's probably easier just to serialize the graph.

@simongray
Copy link
Contributor

simongray commented Jun 21, 2021

Yup, not hard at all when using TDB 1, e.g.

(let [dataset (TDBFactory/createDataset ^String tdb-path)
      model   (.getDefaultModel dataset)
      graph   (.getGraph model)]
  {:dataset dataset
   :model   model
   :graph   graph})

I think this will basically get you a working persistence layer using TDB 1 where tdb-path is a string path to the directory containing the TDB files. Calling (TDBFactory/createDataset ^String tdb-path) on a path with an existing database will load this database rather than create a new one.

You can add to the graph object as per usual (the functions in Aristotle taking a graph all take this object). The TDB graph will be an instance of org.apache.jena.tdb.store.GraphTxnTDB while the in-memory graph that Aristotle defaults to is a org.apache.jena.mem.GraphMem.

TDB 2, however, I couldn't get working very easily. Every single method call accessing any method on the relevant Java objects has to be wrapped in a transaction to get any output whatsoever.

@simongray
Copy link
Contributor

simongray commented Jun 21, 2021

One issue with implementing support for TDB in Aristotle is that as-of-now the lower-level Graph object is used throughout.

I suppose one could create a representation similar to the map I define above (perhaps wrapped in a record) using that as a replacement for the graph in Aristotle. In most cases, its internal graph would be the object's that being accessed, but in certain cases you would want to access the model or the dataset too.

@simongray
Copy link
Contributor

It turns out that a similar issue also exists with TDB 1, but you only run into it if have performed at least one transaction, in which case all further attempts to access TDB content is locked behind transactions. I've tried to make a macro which wraps the Aristotle query run function and this seems to work, although perhaps a little buggy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants