use of com.inova8.intelligentgraph.model.Predicate in project com.inova8.intelligentgraph by peterjohnlawrence.
the class FactFilterElement method filterExpression.
/**
* Filter expression.
*
* @param sourceVariable the source variable
* @param predicateVariable the predicate variable
* @param targetVariable the target variable
* @param filterExpression the filter expression
* @param customQueryOptions the custom query options
* @return the path tuple expr
*/
public PathTupleExpr filterExpression(Variable sourceVariable, Variable predicateVariable, Variable targetVariable, TupleExpr filterExpression, CustomQueryOptions customQueryOptions) {
// QueryModelNode filterExpression = null;
if (propertyListNotEmpty != null) {
int verbObjectListCount = 0;
for (VerbObjectList verbObjectList : propertyListNotEmpty) {
verbObjectListCount++;
Variable verbObjectListTargetVariable = null;
if (targetVariable != null)
verbObjectListTargetVariable = new Variable(targetVariable.getName() + verbObjectListCount);
QueryModelNode verbObjectListExpression = verbObjectList.filterExpression(sourceVariable, predicateVariable, verbObjectListTargetVariable, customQueryOptions);
if (filterExpression == null)
filterExpression = (TupleExpr) verbObjectListExpression;
else if (verbObjectListExpression == null) {
// Ignore it for some unknown reason
} else {
if (filterExpression.getClass().getName().equals("org.eclipse.rdf4j.query.algebra.Compare"))
if (verbObjectListExpression.getClass().getName().equals("org.eclipse.rdf4j.query.algebra.Compare"))
filterExpression = (TupleExpr) new And((ValueExpr) filterExpression, (ValueExpr) verbObjectListExpression);
else
filterExpression = new Filter((TupleExpr) verbObjectListExpression, (ValueExpr) filterExpression);
else if (verbObjectListExpression.getClass().getName().equals("org.eclipse.rdf4j.query.algebra.StatementPattern"))
filterExpression = new Join((TupleExpr) filterExpression, (TupleExpr) verbObjectListExpression);
else if (verbObjectListExpression.getClass().getName().equals("org.eclipse.rdf4j.query.algebra.Join"))
filterExpression = new Join((TupleExpr) filterExpression, (TupleExpr) verbObjectListExpression);
else if (verbObjectListExpression.getClass().getName().equals("org.eclipse.rdf4j.query.algebra.Compare"))
filterExpression = new Filter(filterExpression, (ValueExpr) verbObjectListExpression);
else if (verbObjectListExpression.getClass().getName().equals("org.eclipse.rdf4j.query.algebra.Filter")) {
TupleExpr arg = ((Filter) verbObjectListExpression).getArg();
filterExpression = new Filter(new Join(filterExpression, arg), ((Filter) verbObjectListExpression).getCondition());
} else
filterExpression = new Filter((TupleExpr) filterExpression, (ValueExpr) verbObjectListExpression);
}
}
}
return new PathTupleExpr(filterExpression);
}
use of com.inova8.intelligentgraph.model.Predicate in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphConnection method addStatement.
/**
* Adds the statement.
*
* @param subject the subject
* @param predicate the predicate
* @param object the object
* @param contexts the contexts
* @throws SailException the sail exception
*/
@Override
public void addStatement(Resource subject, IRI predicate, Value object, Resource... contexts) throws SailException {
try {
String[] predicateParts;
if (predicate != null) {
// predicateParts= predicate.stringValue().split(IntelligentGraphConstants.PATH_QL_REGEX);
predicateParts = decodePredicate(predicate);
switch(predicateParts[0]) {
case PATHQL.addFact:
addFact(subject, predicateParts[1], object, contexts);
break;
default:
super.addStatement(subject, predicate, object, contexts);
checkReificationsChanged(predicate);
}
} else
super.addStatement(subject, predicate, object, contexts);
this.intelligentGraphSail.clearCache();
} catch (Exception e) {
throw new SailException(e);
}
}
use of com.inova8.intelligentgraph.model.Predicate in project com.inova8.intelligentgraph by peterjohnlawrence.
the class IntelligentGraphRepository method getFacts.
public ResourceResults getFacts(String boundPredicatePattern, CustomQueryOptions customQueryOptions) {
logger.debug("getFacts{}\n", boundPredicatePattern);
// this.getEvaluationContext().getTracer().traceFacts(this, queryPattern);
SimpleDataset dataset = getDataset(customQueryOptions);
// dataset.addDefaultGraph(this.graphName);
org.eclipse.rdf4j.model.Resource[] contextArray = dataset.getDefaultGraphs().toArray(new org.eclipse.rdf4j.model.Resource[0]);
ResourceStatementResults results = null;
IRI predicate = preparePredicate(PATHQL.getFacts, boundPredicatePattern);
if (this.getRepository() == null) {
CloseableIteration<? extends Statement, QueryEvaluationException> localStatementIterator = this.getTripleSource().getStatements(null, predicate, null);
results = new ResourceStatementResults(localStatementIterator, this, null, customQueryOptions);
} else {
CloseableIteration<Statement, RepositoryException> statementIterator = this.getRepository().getConnection().getStatements(null, predicate, null, contextArray);
results = new ResourceStatementResults(statementIterator, this, null, customQueryOptions);
}
return results;
}
use of com.inova8.intelligentgraph.model.Predicate in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Thing method getFact.
// public Resource getFact(IRI predicate, SimpleLiteral scriptString, CustomQueryOptions customQueryOptions, org.eclipse.rdf4j.model.Resource ... contexts) throws HandledException {
// Resource fact = processFactObjectValue(predicate,scriptString, customQueryOptions ,contexts);
// return fact;
/**
* Gets the fact.
*
* @param predicatePattern the predicate pattern
* @param customQueryOptions the custom query options
* @param bindValues the bind values
* @return the fact
*/
// }
public Resource getFact(String predicatePattern, CustomQueryOptions customQueryOptions, Value... bindValues) {
logger.debug("getFact{}\n", predicatePattern);
ResourceResults factValues = getFacts(predicatePattern, customQueryOptions, bindValues);
if (factValues == null) {
throw new NullValueReturnedException(String.format("No values found for pattern %s with subject %s, customQueryOptions %s, and bind variables %s", predicatePattern, this, customQueryOptions, bindValues));
} else if (factValues.hasNext()) {
return factValues.next();
} else {
factValues.close();
throw new NullValueReturnedException(String.format("No values found for pattern %s with subject %s, customQueryOptions %s, and bind variables %s", predicatePattern, this, customQueryOptions, bindValues));
}
}
use of com.inova8.intelligentgraph.model.Predicate in project com.inova8.intelligentgraph by peterjohnlawrence.
the class Thing method getPath.
/**
* Gets the path.
*
* @param predicatePattern the predicate pattern
* @return the path
*/
public Path getPath(String predicatePattern) {
logger.debug("getPath{}\n", predicatePattern);
PathResults pathValues = getPaths(predicatePattern, null);
if (pathValues == null) {
this.getEvaluationContext().getTracer().tracePathReturnNull(this, predicatePattern);
return new NullPath();
} else if (pathValues.hasNext()) {
Path path = (Path) pathValues.next();
this.getEvaluationContext().getTracer().tracePathReturn(this, predicatePattern, path);
return path;
} else {
this.getEvaluationContext().getTracer().tracePathEmpty(this, predicatePattern);
pathValues.close();
return new NullPath();
}
}
Aggregations