Search in sources :

Example 1 with EdgeBinding

use of com.inova8.intelligentgraph.path.EdgeBinding in project com.inova8.intelligentgraph by peterjohnlawrence.

the class PredicateElement method pathPredicatePatternTupleExpr.

/**
 * Path predicate pattern tuple expr.
 *
 * @param predicatePattern the predicate pattern
 * @param intermediateSourceVariable the intermediate source variable
 * @param intermediatePredicateVariable the intermediate predicate variable
 * @param intermediateTargetVariable the intermediate target variable
 * @param customQueryOptions the custom query options
 * @return the path tuple expr
 */
private PathTupleExpr pathPredicatePatternTupleExpr(PathTupleExpr predicatePattern, Variable intermediateSourceVariable, Variable intermediatePredicateVariable, Variable intermediateTargetVariable, CustomQueryOptions customQueryOptions) {
    TupleExpr intermediatePredicatePattern;
    Variable predicateVariable;
    if (isNegated) {
        predicateVariable = new Variable(getPredicateSPARQLVariable());
        // TODO
        Variable variable = new Variable("p2", predicate);
        if (isInverseOf) {
            StatementPattern inverseOfPattern = new StatementPattern(intermediateTargetVariable, predicateVariable, intermediateSourceVariable);
            Compare filterExpression = new Compare(predicateVariable, variable, CompareOp.NE);
            intermediatePredicatePattern = new Filter(inverseOfPattern, filterExpression);
        } else {
            intermediatePredicatePattern = new StatementPattern(intermediateSourceVariable, predicateVariable, intermediateTargetVariable);
        }
    } else {
        intermediatePredicateVariable.setValue(predicate);
        // Variable(getPredicateSPARQLVariable(), predicate);
        predicateVariable = intermediatePredicateVariable;
        if (isInverseOf) {
            intermediatePredicatePattern = new StatementPattern(intermediateTargetVariable, predicateVariable, intermediateSourceVariable);
        } else {
            intermediatePredicatePattern = new StatementPattern(intermediateSourceVariable, predicateVariable, intermediateTargetVariable);
        }
    }
    if (objectFilterElement != null) {
        intermediatePredicatePattern = (TupleExpr) objectFilterElement.filterExpression(intermediateTargetVariable, intermediatePredicateVariable, null, intermediatePredicatePattern, customQueryOptions).getTupleExpr();
    }
    // EdgeBinding
    statementBinding = new StatementBinding(intermediateSourceVariable, predicateVariable, intermediateTargetVariable, getIsInverseOf());
    if (predicatePattern == null) {
        predicatePattern = new PathTupleExpr(intermediatePredicatePattern);
    // predicatePattern.setStatementBinding(statementBinding);
    } else {
        predicatePattern.setTupleExpr(new Join(predicatePattern.getTupleExpr(), intermediatePredicatePattern));
    }
    predicatePattern.setStatementBinding(statementBinding);
    predicatePattern.setBoundVariable(predicatePattern.getStatementBinding().getSourceVariable());
    predicatePattern.getPath().add(statementBinding);
    return predicatePattern;
}
Also used : StatementPattern(org.eclipse.rdf4j.query.algebra.StatementPattern) StatementBinding(com.inova8.intelligentgraph.path.StatementBinding) PathTupleExpr(com.inova8.intelligentgraph.path.PathTupleExpr) Filter(org.eclipse.rdf4j.query.algebra.Filter) Join(org.eclipse.rdf4j.query.algebra.Join) Compare(org.eclipse.rdf4j.query.algebra.Compare) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr) PathTupleExpr(com.inova8.intelligentgraph.path.PathTupleExpr)

Example 2 with EdgeBinding

use of com.inova8.intelligentgraph.path.EdgeBinding in project com.inova8.intelligentgraph by peterjohnlawrence.

the class IntelligentStatementPaths method pathToLiteral.

/**
 * Path to literal.
 *
 * @param bindingset the bindingset
 * @return the literal
 */
private Literal pathToLiteral(BindingSet bindingset) {
    ModelBuilder builder = new ModelBuilder();
    builder.setNamespace("", PATHQL.NAMESPACE);
    PathBinding thisPathBinding = pathTupleExpr.getPath();
    for (EdgeBinding edge : thisPathBinding) {
        edge.addEdgeToPathModel(builder, bindingset);
    }
    Model pathModel = builder.build();
    OutputStream pathJSON = new ByteArrayOutputStream();
    Rio.write(pathModel, pathJSON, RDFFormat.TURTLE);
    return literal(pathJSON.toString());
}
Also used : ModelBuilder(org.eclipse.rdf4j.model.util.ModelBuilder) EdgeBinding(com.inova8.intelligentgraph.path.EdgeBinding) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Model(org.eclipse.rdf4j.model.Model) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PathBinding(com.inova8.intelligentgraph.path.PathBinding)

Aggregations

EdgeBinding (com.inova8.intelligentgraph.path.EdgeBinding)1 PathBinding (com.inova8.intelligentgraph.path.PathBinding)1 PathTupleExpr (com.inova8.intelligentgraph.path.PathTupleExpr)1 StatementBinding (com.inova8.intelligentgraph.path.StatementBinding)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 Model (org.eclipse.rdf4j.model.Model)1 ModelBuilder (org.eclipse.rdf4j.model.util.ModelBuilder)1 Compare (org.eclipse.rdf4j.query.algebra.Compare)1 Filter (org.eclipse.rdf4j.query.algebra.Filter)1 Join (org.eclipse.rdf4j.query.algebra.Join)1 StatementPattern (org.eclipse.rdf4j.query.algebra.StatementPattern)1 TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)1