Search in sources :

Example 91 with Triple

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

the class PropertyFunctionGenerator method findPropertyFunctionArgs.

private static void findPropertyFunctionArgs(Context context, BasicPattern triples, List<Triple> propertyFunctionTriples, Map<Triple, PropertyFunctionInstance> pfInvocations) {
    for (Triple pf : propertyFunctionTriples) {
        PropertyFunctionInstance pfi = magicProperty(context, pf, triples);
        pfInvocations.put(pf, pfi);
    }
}
Also used : Triple(org.apache.jena.graph.Triple)

Example 92 with Triple

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

the class PropertyFunctionGenerator method compilePattern.

private static Op compilePattern(PropertyFunctionRegistry registry, BasicPattern pattern, Context context) {
    // Split into triples and property functions.
    // 1/ Find property functions.
    //    Property functions may involve other triples (for list arguments)
    //    (but leave the property function triple in-place as a marker)
    // 2/ Find arguments for property functions
    //    (but leave the property function triple in-place as a marker)
    // 3/ For remaining triples, put into basic graph patterns,
    //    and string together the procedure calls and BGPs.
    // Property functions seen
    List<Triple> propertyFunctionTriples = new ArrayList<>();
    // A copy of all triples (later, it is mutated)
    BasicPattern triples = new BasicPattern(pattern);
    // Find the triples invoking property functions, and those not.
    findPropertyFunctions(context, pattern, registry, propertyFunctionTriples);
    if (propertyFunctionTriples.size() == 0)
        //No property functions.
        return new OpBGP(pattern);
    // Map triple => property function instance
    Map<Triple, PropertyFunctionInstance> pfInvocations = new HashMap<>();
    // Removes triples of list arguments.  This mutates 'triples'
    findPropertyFunctionArgs(context, triples, propertyFunctionTriples, pfInvocations);
    // Now make the OpSequence structure.
    Op op = makeStages(triples, pfInvocations);
    return op;
}
Also used : Triple(org.apache.jena.graph.Triple) HashMap(java.util.HashMap) OpBGP(org.apache.jena.sparql.algebra.op.OpBGP) ArrayList(java.util.ArrayList) BasicPattern(org.apache.jena.sparql.core.BasicPattern)

Example 93 with Triple

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

the class WriterStreamRDFBlocks method writePredicateObjectList.

private void writePredicateObjectList(Collection<Triple> triples) {
    // Find width
    int predicateMaxWidth = RiotLib.calcWidthTriples(pMap, baseURI, triples, MIN_PREDICATE, LONG_PREDICATE);
    boolean first = true;
    for (Triple triple : triples) {
        if (!first)
            out.println(" ;");
        else
            first = false;
        Node p = triple.getPredicate();
        outputNode(p);
        out.pad(predicateMaxWidth);
        out.print(' ', GAP_P_O);
        Node o = triple.getObject();
        outputNode(o);
    }
}
Also used : Triple(org.apache.jena.graph.Triple) Node(org.apache.jena.graph.Node)

Example 94 with Triple

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

the class GraphContainerUtils method countContainerMember.

private static int countContainerMember(Graph graph, Node container, Node containerType, Node member, boolean stopEarly) {
    if (graph == null) {
        Log.warn(GraphContainerUtils.class, "containerMember called with null graph");
        return 0;
    }
    if (container == null) {
        Log.warn(GraphContainerUtils.class, "containerMember called with null list");
        return 0;
    }
    if (member == null) {
        Log.warn(GraphContainerUtils.class, "containerMember called with null member");
        return 0;
    }
    if (!isContainer(graph, container, containerType))
        return 0;
    int count = 0;
    ExtendedIterator<Triple> iter = graph.find(container, Node.ANY, member);
    try {
        for (; iter.hasNext(); ) {
            Triple t = iter.next();
            Node p = t.getPredicate();
            String u = p.getURI();
            if (membershipPattern.matcher(u).matches()) {
                count++;
                if (stopEarly)
                    return count;
            }
        }
    } finally {
        iter.close();
    }
    return count;
}
Also used : Triple(org.apache.jena.graph.Triple) Node(org.apache.jena.graph.Node)

Example 95 with Triple

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

the class GraphContainerUtils method containerMembers.

public static Collection<Node> containerMembers(Graph graph, Node container, Node containerType) {
    if (!isContainer(graph, container, containerType))
        return null;
    ExtendedIterator<Triple> iter = graph.find(container, Node.ANY, Node.ANY);
    SortedMap<Integer, Node> triples = new TreeMap<>(order);
    try {
        for (; iter.hasNext(); ) {
            Triple t = iter.next();
            int index = getIndex(t);
            if (index == NOT_FOUND)
                continue;
            // Insert 
            triples.put(new Integer(index), t.getObject());
        }
    } finally {
        iter.close();
    }
    return triples.values();
}
Also used : Triple(org.apache.jena.graph.Triple) Node(org.apache.jena.graph.Node) TreeMap(java.util.TreeMap)

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