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);
}
}
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;
}
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);
}
}
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;
}
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();
}
Aggregations