use of org.openrdf.model.URI in project incubator-rya by apache.
the class LocalReasoner method processIncoming.
/**
* Process a triple in which this node is the object.
*/
private void processIncoming(Fact fact) {
Resource subject = fact.getSubject();
URI predURI = fact.getPredicate();
OwlProperty prop = schema.getProperty(predURI);
// RL rule prp-rng: Apply range(s), if appropriate
for (Resource type : prop.getRange()) {
types.processType(type, OwlRule.PRP_RNG, fact);
}
// RL rules prp-inv1, prp-inv2: assert any inverse properties
for (URI inverseProp : prop.getInverseProperties()) {
collect(triple(node, inverseProp, subject, OwlRule.PRP_INV, fact));
}
// RL rule prp-symp: Assert the symmetric statement if appropriate
if (prop.isSymmetric() && !fact.hasRule(OwlRule.PRP_SYMP) && !subject.equals(node)) {
collect(triple(node, predURI, subject, OwlRule.PRP_SYMP, fact));
}
// RL rule prp-irp: (x p x) is inconsistent if p is irreflexive
if (prop.isIrreflexive() && subject.equals(node)) {
collectInconsistency(inconsistency(OwlRule.PRP_IRP, fact));
}
// with any later outgoing triples with the same property.
if (prop.isTransitive() && !subject.equals(node) && checkTransitivityIncoming(fact)) {
if (!transitiveIncoming.containsKey(predURI)) {
transitiveIncoming.put(predURI, new LinkedList<Fact>());
}
transitiveIncoming.get(predURI).add(fact);
}
// compare later outgoing edges against it. (Assume sorted input.)
if (prop.isAsymmetric()) {
if (!asymmetricIncoming.containsKey(predURI)) {
asymmetricIncoming.put(predURI, new LinkedList<Fact>());
}
asymmetricIncoming.get(predURI).add(fact);
}
for (Resource rNode : prop.getRestrictions()) {
OwlClass restriction = schema.getClass(rNode);
// RL rule cls-svf1: Check for a someValuesFrom restriction
Set<Resource> valuesFrom = restriction.someValuesFrom();
// type owl:Thing would be checked by cls-svf2
valuesFrom.remove(OWL.THING);
for (Resource commonType : valuesFrom) {
// If we learn the type, assert the other node's membership in rNode
types.onType(commonType, triple(subject, RDF.TYPE, rNode, OwlRule.CLS_SVF1, fact));
}
}
}
use of org.openrdf.model.URI in project incubator-rya by apache.
the class ConformanceTest method triviallyTrue.
/**
* Determine that a statement is trivially true for purposes of entailment
* tests, such as an implicit "[bnode] type Ontology" triple or a
* "[class] type Class" triple as long as the class exists.
*/
boolean triviallyTrue(final Statement triple, final Schema schema) {
final Resource s = triple.getSubject();
final URI p = triple.getPredicate();
final Value o = triple.getObject();
if (p.equals(RDF.TYPE)) {
if (o.equals(OWL.ONTOLOGY)) {
return true;
} else if (o.equals(OWL.CLASS)) {
return schema.hasClass(s);
} else if ((o.equals(OWL.OBJECTPROPERTY) || o.equals(OWL.DATATYPEPROPERTY)) && s instanceof URI) {
// Distinction not maintained, irrelevant to RL rules
return schema.hasProperty((URI) s);
}
}
return false;
}
use of org.openrdf.model.URI in project incubator-rya by apache.
the class LocalReasoner method processFact.
/**
* Read in a fact involving this node and make any inferences we can.
* Assumes that incoming triples are received before outgoing triples.
* Recursively call processFact on new triples until nothing else is
* derived.
* @param fact Contains a triple assumed to be relevant to this reasoner
*/
public void processFact(Fact fact) {
Resource subject = fact.getSubject();
URI pred = fact.getPredicate();
Value object = fact.getObject();
// Whether this is a recursive call on a fact that's just been inferred
boolean recursive = fact.getIteration() == currentIteration;
// Figure out what kind of edge this is with respect to this node
boolean incoming = object.equals(node);
boolean outgoing = subject.equals(node);
// Avoid some derivation chains on recursive calls to avoid cycles
boolean skipReflexive = incoming && outgoing && recursive;
// handled in the right order)
if (incoming && !skipReflexive) {
processIncoming(fact);
}
if (outgoing) {
if (pred.equals(RDF.TYPE)) {
types.processType(fact);
} else {
processOutgoing(fact);
}
}
// If newly-learned facts cause further derivations, apply them recursively
Set<Fact> resultsSoFar = getFacts();
for (Fact newFact : resultsSoFar) {
processFact(newFact);
}
newFacts.addAll(resultsSoFar);
}
use of org.openrdf.model.URI in project incubator-rya by apache.
the class GeoFunctionsIT method GeoDistance.
@Test
public void GeoDistance() throws Exception {
final String sparql = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> " + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> " + "PREFIX uom: <http://www.opengis.net/def/uom/OGC/1.0/> " + "SELECT ?cityA ?cityB " + "WHERE { " + "?cityA <urn:containedIn> ?continent. " + "?cityB <urn:containedIn> ?continent. " + "?cityA geo:asWKT ?coord1 . " + "?cityB geo:asWKT ?coord2 . " + // from brussels 173km to amsterdam
" FILTER ( 500000 > geof:distance(?coord1, ?coord2, uom:metre) ) . " + " FILTER ( !sameTerm (?cityA, ?cityB) ) " + "}";
final ValueFactory vf = new ValueFactoryImpl();
final URI wktTypeUri = vf.createURI("http://www.opengis.net/ont/geosparql#wktLiteral");
final URI asWKT = vf.createURI("http://www.opengis.net/ont/geosparql#asWKT");
final Set<Statement> statements = Sets.newHashSet(vf.createStatement(vf.createURI("tag:rya.apache.org,2017:ex#dakar"), asWKT, vf.createLiteral("Point(-17.45 14.69)", wktTypeUri)), vf.createStatement(vf.createURI("tag:rya.apache.org,2017:ex#dakar2"), asWKT, vf.createLiteral("Point(-17.45 14.69)", wktTypeUri)), vf.createStatement(vf.createURI("tag:rya.apache.org,2017:ex#canberra"), asWKT, vf.createLiteral("Point(149.12 -35.31)", wktTypeUri)), vf.createStatement(vf.createURI("tag:rya.apache.org,2017:ex#brussels"), asWKT, vf.createLiteral("Point(4.35 50.85)", wktTypeUri)), vf.createStatement(vf.createURI("tag:rya.apache.org,2017:ex#amsterdam"), asWKT, vf.createLiteral("Point(4.9 52.37)", wktTypeUri)), vf.createStatement(vf.createURI("tag:rya.apache.org,2017:ex#amsterdam"), vf.createURI("urn:containedIn"), vf.createLiteral("Europe")), vf.createStatement(vf.createURI("tag:rya.apache.org,2017:ex#dakar"), vf.createURI("urn:containedIn"), vf.createLiteral("Africa")), vf.createStatement(vf.createURI("tag:rya.apache.org,2017:ex#dakar2"), vf.createURI("urn:containedIn"), vf.createLiteral("Africa")), vf.createStatement(vf.createURI("tag:rya.apache.org,2017:ex#brussels"), vf.createURI("urn:containedIn"), vf.createLiteral("Europe")));
// The expected results of the SPARQL query once the PCJ has been computed.l
final Set<BindingSet> expectedResults = new HashSet<>();
MapBindingSet bs = new MapBindingSet();
bs.addBinding("cityA", vf.createURI("tag:rya.apache.org,2017:ex#dakar"));
bs.addBinding("cityB", vf.createURI("tag:rya.apache.org,2017:ex#dakar2"));
expectedResults.add(bs);
bs = new MapBindingSet();
bs.addBinding("cityA", vf.createURI("tag:rya.apache.org,2017:ex#dakar2"));
bs.addBinding("cityB", vf.createURI("tag:rya.apache.org,2017:ex#dakar"));
expectedResults.add(bs);
bs = new MapBindingSet();
bs.addBinding("cityA", vf.createURI("tag:rya.apache.org,2017:ex#brussels"));
bs.addBinding("cityB", vf.createURI("tag:rya.apache.org,2017:ex#amsterdam"));
expectedResults.add(bs);
bs = new MapBindingSet();
bs.addBinding("cityA", vf.createURI("tag:rya.apache.org,2017:ex#amsterdam"));
bs.addBinding("cityB", vf.createURI("tag:rya.apache.org,2017:ex#brussels"));
expectedResults.add(bs);
runTest(sparql, statements, expectedResults);
}
use of org.openrdf.model.URI in project incubator-rya by apache.
the class GeoFunctionsIT method withTemporal.
@Test
public void withTemporal() throws Exception {
// Find all stored dates.
final String sparql = "PREFIX time: <http://www.w3.org/2006/time#> " + "PREFIX xml: <http://www.w3.org/2001/XMLSchema#> " + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> " + "SELECT ?event ?time { " + "?event time:inXSDDateTime ?time . " + // after 3 seconds
"FILTER(?time > '2001-01-01T01:01:03-08:00'^^xml:dateTime) " + // 2006/12/31 include 2006, not 2007,8
"FILTER('2007-01-01T01:01:01+09:00'^^xml:dateTime > ?time ) " + "}";
// create some resources and literals to make statements out of
final ValueFactory vf = new ValueFactoryImpl();
final DatatypeFactory dtf = DatatypeFactory.newInstance();
final URI dtPredUri = vf.createURI("http://www.w3.org/2006/time#inXSDDateTime");
final URI eventz = vf.createURI("<http://eventz>");
final Set<Statement> statements = Sets.newHashSet(vf.createStatement(eventz, vf.createURI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), vf.createURI("<http://www.w3.org/2006/time#Instant>")), // 1 second
vf.createStatement(eventz, dtPredUri, vf.createLiteral(dtf.newXMLGregorianCalendar("2001-01-01T01:01:01-08:00"))), // 2 seconds
vf.createStatement(eventz, dtPredUri, vf.createLiteral(dtf.newXMLGregorianCalendar("2001-01-01T04:01:02.000-05:00"))), // 3 seconds
vf.createStatement(eventz, dtPredUri, vf.createLiteral(dtf.newXMLGregorianCalendar("2001-01-01T01:01:03-08:00"))), // 4 seconds
vf.createStatement(eventz, dtPredUri, vf.createLiteral(dtf.newXMLGregorianCalendar("2001-01-01T01:01:03.999-08:00"))), // 5 seconds
vf.createStatement(eventz, dtPredUri, vf.createLiteral(dtf.newXMLGregorianCalendar("2001-01-01T09:01:05Z"))), vf.createStatement(eventz, dtPredUri, vf.createLiteral(dtf.newXMLGregorianCalendar("2006-01-01T05:00:00.000Z"))), vf.createStatement(eventz, dtPredUri, vf.createLiteral(dtf.newXMLGregorianCalendar("2007-01-01T05:00:00.000Z"))), vf.createStatement(eventz, dtPredUri, vf.createLiteral(dtf.newXMLGregorianCalendar("2008-01-01T05:00:00.000Z"))));
final Set<BindingSet> expectedResults = new HashSet<>();
MapBindingSet bs = new MapBindingSet();
bs.addBinding("time", vf.createLiteral(dtf.newXMLGregorianCalendar("2001-01-01T09:01:05.000Z")));
bs.addBinding("event", eventz);
expectedResults.add(bs);
bs = new MapBindingSet();
bs.addBinding("time", vf.createLiteral(dtf.newXMLGregorianCalendar("2006-01-01T05:00:00.000Z")));
bs.addBinding("event", eventz);
expectedResults.add(bs);
bs = new MapBindingSet();
bs.addBinding("time", vf.createLiteral(dtf.newXMLGregorianCalendar("2001-01-01T09:01:03.999Z")));
bs.addBinding("event", eventz);
expectedResults.add(bs);
runTest(sparql, statements, expectedResults);
}
Aggregations