use of org.apache.rya.rdftriplestore.utils.TransitivePropertySP in project incubator-rya by apache.
the class SameAsVisitor method meet.
public void meet(StatementPattern sp) throws Exception {
if (!include) {
return;
}
if (sp instanceof FixedStatementPattern || sp instanceof TransitivePropertySP || sp instanceof DoNotExpandSP) {
// already inferred somewhere else
return;
}
final Var predVar = sp.getPredicateVar();
// do not know when things are null
if (predVar == null) {
return;
}
meetSP(sp);
}
use of org.apache.rya.rdftriplestore.utils.TransitivePropertySP in project incubator-rya by apache.
the class AbstractInferVisitor method meet.
@Override
public void meet(StatementPattern sp) throws Exception {
if (!include) {
return;
}
if (sp instanceof FixedStatementPattern || sp instanceof TransitivePropertySP || sp instanceof DoNotExpandSP) {
// already inferred somewhere else
return;
}
final Var predVar = sp.getPredicateVar();
// we do not let timeRange preds be inferred, not good
if (predVar == null || predVar.getValue() == null) // || RdfCloudTripleStoreUtils.getTtlValueConverter(conf, (URI) predVar.getValue()) != null
{
return;
}
meetSP(sp);
}
use of org.apache.rya.rdftriplestore.utils.TransitivePropertySP in project incubator-rya by apache.
the class ParallelEvaluationStrategyImpl method evaluate.
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(final StatementPattern sp, Collection<BindingSet> bindings) throws QueryEvaluationException {
final Var subjVar = sp.getSubjectVar();
final Var predVar = sp.getPredicateVar();
final Var objVar = sp.getObjectVar();
final Var cntxtVar = sp.getContextVar();
List<Map.Entry<Statement, BindingSet>> stmts = new ArrayList<Map.Entry<Statement, BindingSet>>();
Iteration<? extends Map.Entry<Statement, BindingSet>, QueryEvaluationException> iter;
if (sp instanceof FixedStatementPattern) {
Collection<Map.Entry<Statement, BindingSet>> coll = Lists.newArrayList();
for (BindingSet binding : bindings) {
Value subjValue = getVarValue(subjVar, binding);
Value predValue = getVarValue(predVar, binding);
Value objValue = getVarValue(objVar, binding);
Resource contxtValue = (Resource) getVarValue(cntxtVar, binding);
for (Statement st : ((FixedStatementPattern) sp).statements) {
if (!((subjValue != null && !subjValue.equals(st.getSubject())) || (predValue != null && !predValue.equals(st.getPredicate())) || (objValue != null && !objValue.equals(st.getObject())))) {
coll.add(new RdfCloudTripleStoreUtils.CustomEntry<Statement, BindingSet>(st, binding));
}
}
}
iter = new IteratorIteration(coll.iterator());
} else if (sp instanceof TransitivePropertySP && ((subjVar != null && subjVar.getValue() != null) || (objVar != null && objVar.getValue() != null)) && sp.getPredicateVar() != null) {
// if this is a transitive prop ref, we need to make sure that either the subj or obj is not null
// TODO: Cannot handle a open ended transitive property where subj and obj are null
// TODO: Should one day handle filling in the subj or obj with bindings and working this
// TODO: a lot of assumptions, and might be a large set returned causing an OME
Set<Statement> sts = null;
try {
sts = inferenceEngine.findTransitiveProperty((Resource) getVarValue(subjVar), (URI) getVarValue(predVar), getVarValue(objVar), (Resource) getVarValue(cntxtVar));
} catch (InferenceEngineException e) {
throw new QueryEvaluationException(e);
}
Collection<Map.Entry<Statement, BindingSet>> coll = new ArrayList();
for (BindingSet binding : bindings) {
for (Statement st : sts) {
coll.add(new RdfCloudTripleStoreUtils.CustomEntry<Statement, BindingSet>(st, binding));
}
}
iter = new IteratorIteration(coll.iterator());
} else {
for (BindingSet binding : bindings) {
Value subjValue = getVarValue(subjVar, binding);
Value predValue = getVarValue(predVar, binding);
Value objValue = getVarValue(objVar, binding);
Resource contxtValue = (Resource) getVarValue(cntxtVar, binding);
if ((subjValue != null && !(subjValue instanceof Resource)) || (predValue != null && !(predValue instanceof URI))) {
continue;
}
stmts.add(new RdfCloudTripleStoreUtils.CustomEntry<Statement, BindingSet>(new NullableStatementImpl((Resource) subjValue, (URI) predValue, objValue, contxtValue), binding));
}
if (stmts.size() == 0) {
return new EmptyIteration();
}
iter = ((RdfCloudTripleStoreConnection.StoreTripleSource) tripleSource).getStatements(stmts);
}
return new ConvertingIteration<Map.Entry<Statement, BindingSet>, BindingSet, QueryEvaluationException>(iter) {
@Override
protected BindingSet convert(Map.Entry<Statement, BindingSet> stbs) throws QueryEvaluationException {
Statement st = stbs.getKey();
BindingSet bs = stbs.getValue();
QueryBindingSet result = new QueryBindingSet(bs);
// contain a Value for that Var name
if (subjVar != null && !subjVar.isConstant() && !result.hasBinding(subjVar.getName())) {
result.addBinding(subjVar.getName(), st.getSubject());
}
if (predVar != null && !predVar.isConstant() && !result.hasBinding(predVar.getName())) {
result.addBinding(predVar.getName(), st.getPredicate());
}
if (objVar != null && !objVar.isConstant() && !result.hasBinding(objVar.getName())) {
result.addBinding(objVar.getName(), st.getObject());
}
if (cntxtVar != null && !cntxtVar.isConstant() && !result.hasBinding(cntxtVar.getName()) && st.getContext() != null) {
result.addBinding(cntxtVar.getName(), st.getContext());
}
return result;
}
};
}
use of org.apache.rya.rdftriplestore.utils.TransitivePropertySP in project incubator-rya by apache.
the class TransitivePropertyVisitor method meetSP.
@Override
protected void meetSP(final StatementPattern node) throws Exception {
final StatementPattern sp = node.clone();
final Var predVar = sp.getPredicateVar();
final URI pred = (URI) predVar.getValue();
final String predNamespace = pred.getNamespace();
final Var objVar = sp.getObjectVar();
final Var cntxtVar = sp.getContextVar();
if (objVar != null && !RDF.NAMESPACE.equals(predNamespace) && !SESAME.NAMESPACE.equals(predNamespace) && !RDFS.NAMESPACE.equals(predNamespace) && !EXPANDED.equals(cntxtVar)) {
final URI transPropUri = (URI) predVar.getValue();
if (inferenceEngine.isTransitiveProperty(transPropUri)) {
node.replaceWith(new TransitivePropertySP(sp.getSubjectVar(), sp.getPredicateVar(), sp.getObjectVar(), sp.getContextVar()));
}
}
}
Aggregations