Search in sources :

Example 36 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class container method execEvaluatedConcrete.

// Ask directly.
private QueryIterator execEvaluatedConcrete(Binding binding, Node containerNode, Node predicate, Node member, ExecutionContext execCxt) {
    QueryIterator input = QueryIterSingleton.create(binding, execCxt);
    Graph graph = execCxt.getActiveGraph();
    QueryIterator qIter = new QueryIterTriplePattern(input, new Triple(containerNode, predicate, member), execCxt);
    return qIter;
}
Also used : Triple(org.apache.jena.graph.Triple) Graph(org.apache.jena.graph.Graph) QueryIterator(org.apache.jena.sparql.engine.QueryIterator)

Example 37 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class container method execEvaluatedCalc.

// Ask by finding all the rdf:_N + rdf:type  
private QueryIterator execEvaluatedCalc(Binding binding, Node containerNode, Node predicate, Node member, ExecutionContext execCxt) {
    Graph graph = execCxt.getActiveGraph();
    if (!containerNode.isVariable()) {
        // Container a ground term.
        if (!GraphContainerUtils.isContainer(execCxt.getActiveGraph(), containerNode, typeNode))
            return IterLib.noResults(execCxt);
        return oneContainer(binding, containerNode, member, execCxt);
    }
    // Container a variable. 
    Collection<Node> c = null;
    if (member.isVariable())
        c = findContainers(graph, typeNode);
    else
        c = findContainingContainers(graph, typeNode, member);
    QueryIterConcat cIter = new QueryIterConcat(execCxt);
    Var cVar = Var.alloc(containerNode);
    for (Node cn : c) {
        //Binding the container node. 
        Binding b = BindingFactory.binding(binding, cVar, cn);
        Node m = member;
        // Special case of ?x rdfs:member ?x
        if (Var.isVar(member) && member.equals(cVar)) {
            m = cn;
        }
        cIter.add(oneContainer(b, cn, m, execCxt));
    }
    return cIter;
//throw new QueryFatalException(Utils.className(this)+": Arg 1 is too hard : "+containerNode) ;
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Graph(org.apache.jena.graph.Graph) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node)

Example 38 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class listIndex method execOneList.

@Override
protected QueryIterator execOneList(Binding binding, Node listNode, Node predicate, List<Node> objectArgs, ExecutionContext execCxt) {
    if (Var.isVar(listNode))
        throw new ExprEvalException("ListIndex : subject not a list or variable bound to a list");
    if (objectArgs.size() != 2)
        throw new ExprEvalException("ListIndex : object not a list of length 2");
    Node indexNode = objectArgs.get(0);
    Node memberNode = objectArgs.get(1);
    Graph graph = execCxt.getActiveGraph();
    if (Var.isVar(indexNode) && !Var.isVar(memberNode))
        return findIndex(graph, binding, listNode, Var.alloc(indexNode), memberNode, execCxt);
    if (!Var.isVar(indexNode) && Var.isVar(memberNode))
        return getByIndex(graph, binding, listNode, indexNode, Var.alloc(memberNode), execCxt);
    if (!Var.isVar(indexNode) && !Var.isVar(memberNode))
        return testSlotValue(graph, binding, listNode, indexNode, memberNode, execCxt);
    return findIndexMember(graph, binding, listNode, Var.alloc(indexNode), Var.alloc(memberNode), execCxt);
}
Also used : Graph(org.apache.jena.graph.Graph) Node(org.apache.jena.graph.Node) GNode(org.apache.jena.sparql.util.graph.GNode) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Example 39 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class TestLangTurtle method parseOneTriple.

private static Triple parseOneTriple(String... strings) {
    Graph graph = parse(strings);
    assertEquals(1, graph.size());
    return graph.find(null, null, null).next();
}
Also used : Graph(org.apache.jena.graph.Graph)

Example 40 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class TestGraphUnionRead method gr_union_05.

@Test
public void gr_union_05() {
    List<Node> gnodes = list();
    Graph g = new GraphUnionRead(dsg, gnodes);
    long x = Iter.count(g.find(null, null, null));
    assertEquals(0, x);
}
Also used : GraphUnionRead(org.apache.jena.sparql.graph.GraphUnionRead) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) BuilderGraph(org.apache.jena.sparql.sse.builders.BuilderGraph) Graph(org.apache.jena.graph.Graph) Node(org.apache.jena.graph.Node) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Aggregations

Graph (org.apache.jena.graph.Graph)247 Test (org.junit.Test)90 BaseTest (org.apache.jena.atlas.junit.BaseTest)56 Triple (org.apache.jena.graph.Triple)56 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)54 Node (org.apache.jena.graph.Node)46 AbstractTestGraph (org.apache.jena.graph.test.AbstractTestGraph)16 InfGraph (org.apache.jena.reasoner.InfGraph)16 ContractTest (org.xenei.junit.contract.ContractTest)16 Model (org.apache.jena.rdf.model.Model)14 MultiUnion (org.apache.jena.graph.compose.MultiUnion)9 Delta (org.apache.jena.graph.compose.Delta)8 BuilderGraph (org.apache.jena.sparql.sse.builders.BuilderGraph)8 StreamRDF (org.apache.jena.riot.system.StreamRDF)7 PrefixMapping (org.apache.jena.shared.PrefixMapping)7 GraphUnionRead (org.apache.jena.sparql.graph.GraphUnionRead)7 IOException (java.io.IOException)6 Dataset (org.apache.jena.query.Dataset)6 Rule (org.apache.jena.reasoner.rulesys.Rule)6 ConfigTest (org.apache.jena.tdb.ConfigTest)6