Search in sources :

Example 6 with PathBinding

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

the class PathPatternPathTests method test_4.

/**
 * Test 4.
 *
 * @throws RecognitionException the recognition exception
 * @throws PathPatternException the path pattern exception
 */
@Test
@Order(4)
void test_4() throws RecognitionException, PathPatternException {
    PathElement element = PathParser.parsePathPattern(repositoryContext, ":Location@:appearsOn[ eq [ rdfs:label \"Calc2Graph1\"] ]#/^:lat/:long/^:left/:right");
    PathBinding pathBinding = new PathBinding();
    pathBinding = element.visitPathBinding(pathBinding, 0);
    assertEquals("[n0,r1:<http://default/Location>@http://default/appearsOn,r1,DIRECT,true]\r\n" + "[r1,http://default/lat,n2,INVERSE]\r\n" + "[n2,http://default/long,n3,DIRECT]\r\n" + "[n3,http://default/left,n4,INVERSE]\r\n" + "[n4,http://default/right,n5,DIRECT]\r\n" + "", pathBinding.toString());
}
Also used : PathElement(com.inova8.pathql.element.PathElement) PathBinding(com.inova8.intelligentgraph.path.PathBinding) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 7 with PathBinding

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

the class PathPatternPathTests method test_2.

/**
 * Test 2.
 *
 * @throws RecognitionException the recognition exception
 * @throws PathPatternException the path pattern exception
 */
@Test
@Order(2)
void test_2() throws RecognitionException, PathPatternException {
    PathElement element = PathParser.parsePathPattern(repositoryContext, ":parent1[:gender :female]/^:child2[:gender :male; :birthplace [rdfs:label 'Maidstone']]/:parent3");
    PathBinding pathBinding = new PathBinding();
    pathBinding = element.visitPathBinding(pathBinding, 0);
    assertEquals("[n0,http://default/parent1,n1,DIRECT]\r\n" + "[n1,http://default/child2,n2,INVERSE]\r\n" + "[n2,http://default/parent3,n3,DIRECT]\r\n" + "", pathBinding.toString());
}
Also used : PathElement(com.inova8.pathql.element.PathElement) PathBinding(com.inova8.intelligentgraph.path.PathBinding) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 8 with PathBinding

use of com.inova8.intelligentgraph.path.PathBinding 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)

Example 9 with PathBinding

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

the class FactResults method nextResource.

/**
 * Next resource.
 *
 * @return the resource
 * @throws QueryEvaluationException the query evaluation exception
 */
@Override
public Resource nextResource() throws QueryEvaluationException {
    BindingSet next = getResourceSet().next();
    PathBinding path = new PathBinding();
    path = pathElement.visitPathBinding(path, 0);
    // for(Edge edge:path) {
    // TODO
    // Value sourceValue = next.getBinding(edge.getSourceVariable().getName()).getValue();
    // Value predicateValue = next.getBinding(edge.getPredicateVariable().getName()).getValue();
    // Value reificationValue = edge.getReification();
    // Value targetValue = next.getBinding(edge.getTargetVariable().getName()).getValue();
    // Boolean direction = edge.isInverse();
    // Boolean isDereified = edge.getIsDereified();
    // Fact edgeFact = new Fact(sourceValue, predicateValue, targetValue);
    // }
    Resource objectValue = calculateValue(next);
    return new Fact(next.getBinding(getPathElement().getTargetSubject().getName()).getValue(), next.getBinding(getPathElement().getTargetPredicate().getName()).getValue(), objectValue.getValue());
}
Also used : BindingSet(org.eclipse.rdf4j.query.BindingSet) Resource(com.inova8.intelligentgraph.model.Resource) PathBinding(com.inova8.intelligentgraph.path.PathBinding) Fact(com.inova8.intelligentgraph.model.Fact)

Aggregations

PathBinding (com.inova8.intelligentgraph.path.PathBinding)7 PathElement (com.inova8.pathql.element.PathElement)5 Order (org.junit.jupiter.api.Order)5 Test (org.junit.jupiter.api.Test)5 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)5 StatementBinding (com.inova8.intelligentgraph.path.StatementBinding)2 Fact (com.inova8.intelligentgraph.model.Fact)1 Resource (com.inova8.intelligentgraph.model.Resource)1 EdgeBinding (com.inova8.intelligentgraph.path.EdgeBinding)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 BindingSet (org.eclipse.rdf4j.query.BindingSet)1