some questions

12 views
Skip to first unread message

jako

unread,
Dec 27, 2009, 10:52:25 AM12/27/09
to OpenAnzo
Hi,
I'm a newbie of OpenAnzo, I would like to integrate it into my
application that use Pellet and Jena.
I have some questions to ask you. First, my application is structured
in a very simple way: some ontologies models (Sioc,doap,foaf) are
maintained in Anzo as a NamedGraph. Individuals, read from an owl
file, are also mantained in NamedGraph but they are then imported as
Jena models.
After inference in Pellet (waiting for reasoning mechanism integrated
in the platform :) ), I want to add the inferred statements in Anzo
as a NamedGraph, updating the individuals graphs. Since the models
don't change but the instances do it, I would to get once the models
and keep it in persistent way, and implement a change listener for
individuals graph. This graph should be update both from source (owl
file) and inference from pellet,
but I want to persist change only after several cycles of inference.
So, I was wondering if the follow step are right:

// create a NamedGraph for foaf instances from file read.

URI foafUri = Constants.valueFactory.createURI("http://xmlns.com/foaf/
0.1/");
INamedGraph foafNG = new NamedGraph(foafUri);
URL foafURL = new URL ("file:src/foaf.rdf"); //foaf
Reader foafIn = new InputStreamReader(foafURL.openStream());
ReadWriteUtils.loadGraph(foafNG, foafIn,RDFFormat.RDFXML ,
foafUri.toString());

//create a sever Dataset with all the NamedGraph

anzoClient.createServerDataset(true, datasetUri, null, setUris, new
INamedGraphInitializer[0]);

//get a revisioned NamedGraph to import in jena only individuals and
rules

IAnzoGraph foafInstancesGraph=anzoClient.getServerGraph
(foafInstNamedGraph,
AnzoClient.GRAPH_MUST_EXIST,AnzoClient.REVISIONED_NAMED_GRAPH);

//after inference, update the indivuals graph
ReadWriteUtils.loadGraph(inferredGraph, new StringReader
(inferred.toString()), RDFFormat.RDFXML, "http://www.myOnt.it/
test.owl#");
foafInstancesGraph.add(inferredGraph.getStatements());
RealtimeUpdateManager manager=anzoClient.getRealtimeUpdates();
manager.addTracker(defaultDatasetGraph, null,null, null, new
IStatementListener<ITracker>()
{
@Override
public void statementsAdded(ITracker arg0,
org.openanzo.rdf.Statement... statements) {
// TODO Auto-generated method stub
System.err.println("Statement Added: " + statements[0]);
}

@Override
public void statementsRemoved(ITracker arg0,
org.openanzo.rdf.Statement... statements) {
// TODO Auto-generated method stub
System.err.println("Statement Removed: " + statements[0]);
}

});
anzoClient.updateRepository();

My questions are:
are these the right steps to do what I'm trying to do?
any change to the instances file doesn't appears in the NamedGraph.
Only the first time is read the file?
with updaterepository(), changes to IAnzoGraph are applied to
serverGraph or only to the local copy of graph?

I apologize for unstructured information and for my english...thank
you

Jako

Jordi Albornoz Mulligan

unread,
Dec 28, 2009, 2:35:58 PM12/28/09
to open...@googlegroups.com
jako wrote:
> Hi,
> I'm a newbie of OpenAnzo, I would like to integrate it into my
> application that use Pellet and Jena.
> I have some questions to ask you. First, my application is structured
> in a very simple way: some ontologies models (Sioc,doap,foaf) are
> maintained in Anzo as a NamedGraph. Individuals, read from an owl
> file, are also mantained in NamedGraph but they are then imported as
> Jena models.
> After inference in Pellet (waiting for reasoning mechanism integrated
> in the platform :) ), I want to add the inferred statements in Anzo
> as a NamedGraph, updating the individuals graphs. Since the models
> don't change but the instances do it, I would to get once the models
> and keep it in persistent way, and implement a change listener for
> individuals graph. This graph should be update both from source (owl
> file) and inference from pellet,
> but I want to persist change only after several cycles of inference.

Let me try to rephrase your desired task to make sure I understand it.

You want to load some ontologies (like Sioc, foaf, doap, etc.) into an
Open Anzo server from files. You want to keep the ontologies in their
own graph. You call this the "ontology models graph".

You also want to load some other RDF data, which contains some
individuals of the classes defined in those ontologies, into the Open
Anzo server from a file. You want this RDF data to be placed into its
own single graph. You call this graph the "individuals graph".

Then you are going to run some inference on the data using Pellet. You
want to load results of the inference (that is, the newly inferred RDF
statements) into Open Anzo in its own graph. You call this graph the
"inferred graph".

Next, you want to copy the newly inferred statements from the "inferred
graph" to the "individuals graph".

While performing the above steps, you'd like to be notified of any
changes to the "individuals graph", including the initial load of
statements from a file as well as the subsequent addition of inferred
statements.

You want all of that RDF data to be persisted to the Open Anzo server.

> So, I was wondering if the follow step are right:

If my description of your task above is correct, then I believe you are
close but I can suggest some changes to help you.

First, I suggest using replica graphs instead of the NamedGraph and
server graphs that you ware using in your code example. A NamedGraph is
an in-memory graph that is not persisted. A replica graph is a graph
that is persisted as well as having an in-memory cache. A server graph
is a persisted graph that lacks an in-memory cache. Typically a replica
graph is what you want for most purposes. You should use a server graph
if your graph is so big that keeping an in-memory cache would be
impractical or if you are doing mostly writing to the graph and very
little reading. In your case, I believe replica graphs are what you want.

To use replica graphs in your code, change the places where you
construct a NamedGraph class instead to something like this:

ClientGraph foafNG = anzoClient.getReplicaGraph(foafUri);

You can still use the same operations on that graph as you are using
with the NamedGraph class. For example, you can still use the
ReadWriteUtils.loadGraph method.

Similarly, change the places you call anzoClient.getServerGraph to
instead call anzoClient.getReplicaGraph.

> [snip]


>
> //create a sever Dataset with all the NamedGraph
>
> anzoClient.createServerDataset(true, datasetUri, null, setUris, new
> INamedGraphInitializer[0]);

I'm not sure why you are creating a dataset. What URIs are in setUris?
If my description is correct above, then I don't see a need for a dataset.

> [snip]


>
> RealtimeUpdateManager manager=anzoClient.getRealtimeUpdates();
> manager.addTracker(defaultDatasetGraph, null,null, null, new

> [snip]

You don't need to use the RealtimeUpdateManager to get the notifications
that you want. I suggest that you simply use the replica graph's
registerListener method. For example:

foafInstancesGraph.registerListener(
new IStatementListener<INamedGraph>() { ... });

> My questions are:
> are these the right steps to do what I'm trying to do?

Change to replica graphs and use the listeners on the graphs themselves
instead of the RealtimeUpdateManager and I think you are there.

> any change to the instances file doesn't appears in the NamedGraph.
> Only the first time is read the file?

Changes to the file after it's been loaded are not reflected in the
graphs, no. The Open Anzo API does not have any built-in mechanism to
monitor RDF files on disk for changes.

> with updaterepository(), changes to IAnzoGraph are applied to
> serverGraph or only to the local copy of graph?

Calling updateRepository() causes all of the changes made to persisted
graphs to be written out to the server. By "persisted graphs" I mean
either replica graphs or server graphs. Before calling
updateRepository() any changes made to persisted graphs are kept in an
in-memory queue of changes. They are sent in bulk to be written to the
server when you call updateRepository().

--
Jordi Albornoz Mulligan
Founding Engineer - Cambridge Semantics
jo...@cambridgesemantics.com
(617) 401-7321

Reply all
Reply to author
Forward
0 new messages