hi there again :) I was experimenting with how BigOWLIM behaves, when inferred data are manipulated through RepositoryConnection methods.. scenarious:
1. transitive property: blames
data:
dieter blames siegfried
siegfried blames manfred
---
inferred closure: dieter blames manfred
.. I've tried to remove statement [siegfried blames manfred], thus
statement [dieter blames manfred] was expected to be removed also .. this
worked!
2. transitive/symetric property: owl:sameAs
data:
dieter owl:sameAs siegfried
siegfried owl:sameAs manfred
---
inferred (should be) closures and assertions:
dieter owl:sameAs manfred, every individual should be sameAs other (having
only three individuals in the data), all property values of sameAs
individuals should be asserted to each other .. that worked .. inferred
stuff was properly asserted ..
the problem was to get and remove the statements .. I wanted to check,
that e.g. [siegfried owl:sameAs manfred] will remove all inferred
assertions .. that was the expectation .. but (for RepositoryConnection
conn):
conn.getStatement(
new URIImpl("http://test.ns/siegfried"),
new URIImpl("http://www.w3.org/2002/07/owl#sameAs"),
new URIImpl("http://test.ns/manfred"),
false,
(Resource)null)
I did not retrieve anything .. I had to set inferred flag in the method to
TRUE to get the statement ..
after calling conn.remove(st), where [st] is the retrieved statement,
nothing happend .. no data were affected .. I was running the query:
select ?a ?b where {
?a owl:sameAs ?b .
}
and for each individual I've listed all properties calling:
select ?prop ?val where {
my:individual ?prop ?val.
}
nothing was removed, nor changed ..
running BigOWLIM 3.2.a7
pls, do you have an idea why? ..
data (with schema) and source code are attached (n3 with data are expected
to be in the project resources/ folder .. didn't want to send the whole
eclipse project (7M .. with libs .. ))
thanks a lot, cheers,
Peter K.
package test.owlim;
import java.io.File;
import java.util.Iterator;
import org.openrdf.model.Resource;
import org.openrdf.model.Statement;
import org.openrdf.model.impl.URIImpl;
import org.openrdf.query.Binding;
import org.openrdf.query.QueryLanguage;
import org.openrdf.query.TupleQuery;
import org.openrdf.query.TupleQueryResult;
import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryResult;
import org.openrdf.repository.sail.SailRepository;
import org.openrdf.rio.RDFFormat;
import com.ontotext.trree.OwlimSchemaRepository;
public class SameAsTest {
SailRepository sail = null;
public void init(String storage) {
System.out.println("INITIALIZING REPO ");
OwlimSchemaRepository conf = null;
try {
// setup configuration
conf = new OwlimSchemaRepository();
conf.setDataDir(new File("owlim/"));
conf.setParameter("storage-folder", storage);
conf.setParameter("repository-type", "file-repository");
conf.setParameter("console-thread", "false");
conf.setParameter("ruleset", "owl-max");
sail = new SailRepository(conf);
sail.initialize();
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
}
public void load(String dataFile) {
RepositoryConnection conn = null;
try {
conn = sail.getConnection();
System.out.println("LOADING DATA [" + dataFile + "]: ");
conn.add(new File(dataFile), "http://test.base.uri", RDFFormat.N3,
new URIImpl("http://test.ctx"));
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
conn.close();
} catch (Exception cE) {
cE.printStackTrace();
}
}
}
public void shutdown() {
try {
sail.shutDown();
} catch (Exception e) {
e.printStackTrace();
}
}
public void query(String queryString) {
System.out.println("\n\n==== QUERY TO LAUNCH :: \n" + queryString);
RepositoryConnection conn = null;
try {
conn = sail.getConnection();
TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL,
queryString);
TupleQueryResult result = query.evaluate();
try {
while (result.hasNext()) {
System.out.println("RESULT:: ");
Iterator<Binding> i = result.next().iterator();
while (i.hasNext()) {
System.out.println("> " + i.next());
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
result.close();
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
conn.close();
} catch (Exception cE) {
cE.printStackTrace();
}
}
}
public void sameAsQuery() {
String q = "prefix test: <http://data.test/ns#> \n "
+ "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n"
+ "prefix owl: <http://www.w3.org/2002/07/owl#>"
+ "select ?a ?b \n"
+ "where { \n"
+ "?a owl:sameAs ?b. "
+ "}";
System.out.println("\n===\nGET ALL WHO [owl:sameAs]: ");
query(q);
}
public void describe(String individual) {
String q = "prefix test: <http://data.test/ns#> \n "
+ "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n"
+ "prefix owl: <http://www.w3.org/2002/07/owl#>"
+ "select ?prop ?val \n"
+ "where { \n"
+ individual + " ?prop ?val. "
+ "}";
System.out.println("===\nDESCRIBE ["+individual+"]: ");
query(q);
}
public void removeTransitiveProp() {
RepositoryConnection conn = null;
try {
conn = sail.getConnection();
RepositoryResult<Statement> st =
conn.getStatements(
new URIImpl("http://data.test/ns#siegfried"),
new URIImpl("http://www.w3.org/2002/07/owl#sameAs"),
new URIImpl("http://data.test/ns#manfred"),
true,
new URIImpl("http://test.ctx"));
System.out.println("REMOVING...");
if(st.hasNext()){
System.out.println("> done...");
conn.remove(st.next());
}
else{
System.out.println("> NOT done...???");
throw new Exception("no matching statement found?");
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
conn.close();
} catch (Exception cE) {
cE.printStackTrace();
}
}
}
public static void main(String[] args) throws Exception {
SameAsTest test = new SameAsTest();
System.out.println("\n\n=============");
System.out.println("Situation for owl:sameAs property: ");
System.out.println("-------------");
System.out.println("dieter owl:sameAs siegfried");
System.out.println("siegfried owl:sameAs manfred");
System.out.println("inferred trans. closure: dieter owl:sameAs manfred, all properties of connected individuals are shared");
System.out.println("=============");
test.init("sameAs");
test.load("resources/sameAs-test-schema-and-data.n3");
test.sameAsQuery();
test.describe("test:dieter");
test.describe("test:siegfried");
test.describe("test:manfred");
System.out.println("\n\nREMOVING RELATION: siegfried owl:sameAs manfred");
System.out.println("AFTER REMOVAL SHOULD BE ALSO REMOVED (and all related properties): dieter owl:sameAs manfred");
test.removeTransitiveProp();
test.sameAsQuery();
test.describe("test:dieter");
test.describe("test:siegfried");
test.describe("test:manfred");
test.shutdown();
}
}
sameAs-test-schema-and-data.n3
Description: Binary data
_______________________________________________ OWLIM-discussion mailing list [email protected] http://ontotext.com/mailman/listinfo/owlim-discussion
