Search in sources :

Example 86 with Triple

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

the class SecuredRDFListImpl method with.

@Override
public SecuredRDFList with(final RDFNode value) throws UpdateDeniedException, AddDeniedException, AuthenticationRequiredException {
    checkUpdate();
    checkCreate(new Triple(SecurityEvaluator.FUTURE, listFirst().asNode(), value.asNode()));
    return SecuredRDFListImpl.getInstance(getModel(), holder.getBaseItem().with(value));
}
Also used : Triple(org.apache.jena.graph.Triple)

Example 87 with Triple

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

the class SecuredRDFListImpl method size.

@Override
public int size() throws ReadDeniedException, AuthenticationRequiredException {
    checkRead();
    final Triple t = new Triple(Node.ANY, listFirst().asNode(), Node.ANY);
    if (canRead(t)) {
        return holder.getBaseItem().size();
    }
    final ExtendedIterator<RDFNode> iter = iterator();
    int i = 0;
    while (iter.hasNext()) {
        i++;
        iter.next();
    }
    return i;
}
Also used : Triple(org.apache.jena.graph.Triple) SecuredRDFNode(org.apache.jena.permissions.model.SecuredRDFNode)

Example 88 with Triple

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

the class PropertyFunctionGenerator method magicProperty.

// Remove all triples associated with this magic property.
// Make an instance record.
private static PropertyFunctionInstance magicProperty(Context context, Triple pfTriple, BasicPattern triples) {
    List<Triple> listTriples = new ArrayList<>();
    GNode sGNode = new GNode(triples, pfTriple.getSubject());
    GNode oGNode = new GNode(triples, pfTriple.getObject());
    List<Node> sList = null;
    List<Node> oList = null;
    if (GraphList.isListNode(sGNode)) {
        sList = GraphList.members(sGNode);
        GraphList.allTriples(sGNode, listTriples);
    }
    if (GraphList.isListNode(oGNode)) {
        oList = GraphList.members(oGNode);
        GraphList.allTriples(oGNode, listTriples);
    }
    PropFuncArg subjArgs = new PropFuncArg(sList, pfTriple.getSubject());
    PropFuncArg objArgs = new PropFuncArg(oList, pfTriple.getObject());
    // Confuses single arg with a list of one. 
    PropertyFunctionInstance pfi = new PropertyFunctionInstance(subjArgs, pfTriple.getPredicate(), objArgs);
    triples.getList().removeAll(listTriples);
    return pfi;
}
Also used : Triple(org.apache.jena.graph.Triple) GNode(org.apache.jena.sparql.util.graph.GNode) Node(org.apache.jena.graph.Node) GNode(org.apache.jena.sparql.util.graph.GNode) ArrayList(java.util.ArrayList) PropFuncArg(org.apache.jena.sparql.pfunction.PropFuncArg)

Example 89 with Triple

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

the class PropertyFunctionGenerator method makeStages.

private static Op makeStages(BasicPattern triples, Map<Triple, PropertyFunctionInstance> pfInvocations) {
    // Step 3 : Make the operation expression.
    //   For each property function, insert the implementation 
    //   For each block of non-property function triples, make a BGP.
    Op op = null;
    BasicPattern pattern = null;
    for (Triple t : triples) {
        if (pfInvocations.containsKey(t)) {
            op = flush(pattern, op);
            pattern = null;
            PropertyFunctionInstance pfi = pfInvocations.get(t);
            OpPropFunc opPF = new OpPropFunc(t.getPredicate(), pfi.getSubjectArgList(), pfi.getObjectArgList(), op);
            op = opPF;
            continue;
        }
        // Regular triples - make sure there is a basic pattern in progress. 
        if (pattern == null)
            pattern = new BasicPattern();
        pattern.add(t);
    }
    op = flush(pattern, op);
    return op;
}
Also used : Triple(org.apache.jena.graph.Triple) BasicPattern(org.apache.jena.sparql.core.BasicPattern) OpPropFunc(org.apache.jena.sparql.algebra.op.OpPropFunc)

Example 90 with Triple

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

the class AlgebraGenerator method prepareGroup.

/* Extract filters, merge adjacent BGPs, do BIND.
     * When extracting filters, BGP or PathBlocks may become adjacent
     * so merge them into one. 
     * Return a list of elements with any filters at the end. 
     */
protected Pair<List<Expr>, List<Element>> prepareGroup(ElementGroup groupElt) {
    List<Element> groupElts = new ArrayList<>();
    PathBlock currentPathBlock = null;
    List<Expr> filters = null;
    for (Element elt : groupElt.getElements()) {
        if (!fixedFilterPosition && elt instanceof ElementFilter) {
            // For fixed position filters, drop through to general element processing.
            // It's also illegal SPARQL - filters operate over the whole group.
            ElementFilter f = (ElementFilter) elt;
            if (filters == null)
                filters = new ArrayList<>();
            filters.add(f.getExpr());
            // Collect filters but do not place them yet.
            continue;
        }
        if (elt instanceof ElementTriplesBlock) {
            ElementTriplesBlock etb = (ElementTriplesBlock) elt;
            if (currentPathBlock == null) {
                ElementPathBlock etb2 = new ElementPathBlock();
                currentPathBlock = etb2.getPattern();
                groupElts.add(etb2);
            }
            for (Triple t : etb.getPattern()) currentPathBlock.add(new TriplePath(t));
            continue;
        }
        if (elt instanceof ElementPathBlock) {
            ElementPathBlock epb = (ElementPathBlock) elt;
            if (currentPathBlock == null) {
                ElementPathBlock etb2 = new ElementPathBlock();
                currentPathBlock = etb2.getPattern();
                groupElts.add(etb2);
            }
            currentPathBlock.addAll(epb.getPattern());
            continue;
        }
        // else
        // Not BGP, path or filters.
        // Clear any BGP-related triple accumulators.
        currentPathBlock = null;
        // Add this element
        groupElts.add(elt);
    }
    return Pair.create(filters, groupElts);
}
Also used : Triple(org.apache.jena.graph.Triple)

Aggregations

Triple (org.apache.jena.graph.Triple)407 Test (org.junit.Test)139 Node (org.apache.jena.graph.Node)95 BaseTest (org.apache.jena.atlas.junit.BaseTest)66 Graph (org.apache.jena.graph.Graph)54 Quad (org.apache.jena.sparql.core.Quad)25 TriplePath (org.apache.jena.sparql.core.TriplePath)22 ArrayList (java.util.ArrayList)20 StatsMatcher (org.apache.jena.sparql.engine.optimizer.StatsMatcher)19 Var (org.apache.jena.sparql.core.Var)17 TripleWritable (org.apache.jena.hadoop.rdf.types.TripleWritable)15 Model (org.apache.jena.rdf.model.Model)13 TriplePattern (org.apache.jena.reasoner.TriplePattern)13 Op (org.apache.jena.sparql.algebra.Op)13 BasicPattern (org.apache.jena.sparql.core.BasicPattern)13 TransitiveGraphCache (org.apache.jena.reasoner.transitiveReasoner.TransitiveGraphCache)11 LongWritable (org.apache.hadoop.io.LongWritable)10 InfGraph (org.apache.jena.reasoner.InfGraph)10 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)10 Resource (org.apache.jena.rdf.model.Resource)9