private static GNode previous(GNode gnode) { // reverse Node n = getNodeReverse(gnode, CDR) ; if ( n == null ) return null ; return new GNode(gnode, n) ; }
private static GNode next(GNode gnode) { return new GNode(gnode, cdr(gnode)) ; }
private static Set<GNode> findCellsWithMember(GNode gnode) { Set<GNode> x = new HashSet<>() ; Iterator<Triple> iter = gnode.findable.find(Node.ANY, CAR, gnode.node) ; for ( ; iter.hasNext() ; ) { Triple t = iter.next() ; x.add(new GNode(gnode, t.getSubject())) ; } NiceIterator.close(iter) ; return x ; }
@Override protected QueryIterator execObjectBound(Binding binding, Var listVar, Node predicate, Node object, ExecutionContext execCxt) { // Given a concrete node, find lists it's in GNode gnode = new GNode(execCxt.getActiveGraph(), object) ; List<Node> lists = GraphList.listFromMember(gnode) ; return new QueryIterExtendByVar(binding, listVar, lists.iterator(), execCxt) ; }
private QueryIterator members(Binding binding, Node listNode, Var itemVar, ExecutionContext execCxt) { List<Node> members = GraphList.members(new GNode(execCxt.getActiveGraph(), listNode)) ; return new QueryIterExtendByVar(binding, itemVar, members.iterator(), execCxt) ; }
private QueryIterator verify(Binding binding, Node listNode, Node member, ExecutionContext execCxt) { int count = GraphList.occurs(new GNode(execCxt.getActiveGraph(), listNode), member) ; return new QueryIterYieldN(count, binding) ; }
private static QueryIterator findIndexMember(Graph graph, Binding binding, Node listNode, Var varIndex, Var varMember, ExecutionContext execCxt) { // Iterate over list List<Node> members = GraphList.members(new GNode(graph, listNode)) ; List<Binding> bindings = new ArrayList<>() ; for ( int i = 0 ; i < members.size() ; i++ ) { Node idx = NodeFactoryExtra.intToNode(i) ; Node member = members.get(i) ; BindingMap b = BindingFactory.create(binding) ; b.add(varIndex, idx) ; b.add(varMember, member) ; bindings.add(b) ; } return new QueryIterPlainWrapper(bindings.iterator(), execCxt) ; } }
private static GNode gnode(Node n) { return new GNode(Factory.createDefaultGraph(), n) ; }
private QueryIterator verify(Binding binding, Graph graph, Node listNode, Node length, ExecutionContext execCxt) { int x = GraphList.length(new GNode(graph, listNode)) ; int len = NodeFactoryExtra.nodeToInt(length) ; if ( x == len ) return IterLib.result(binding, execCxt) ; return IterLib.noResults(execCxt) ; }
private static QueryIterator findIndex(Graph graph, Binding binding, Node listNode, Var var, Node member, ExecutionContext execCxt) { // Find index of member. int i = GraphList.index(new GNode(graph, listNode), member) ; if ( i < 0 ) return IterLib.noResults(execCxt) ; Node idx = NodeFactoryExtra.intToNode(i) ; return IterLib.oneResult(binding, var, idx, execCxt) ; }
private QueryIterator length(Binding binding, Graph graph, Node listNode, Var varLength, ExecutionContext execCxt) { int x = GraphList.length(new GNode(graph, listNode)) ; if ( x < 0 ) return IterLib.noResults(execCxt) ; Node n = NodeFactoryExtra.intToNode(x) ; return IterLib.oneResult(binding, varLength, n, execCxt) ; }
private static QueryIterator getByIndex(Graph graph, Binding binding, Node listNode, Node indexNode, Var varMember, ExecutionContext execCxt) { int i = NodeFactoryExtra.nodeToInt(indexNode) ; if ( i < 0 ) return IterLib.noResults(execCxt) ; Node n = GraphList.get(new GNode(graph, listNode), i) ; if ( n == null ) return IterLib.noResults(execCxt) ; return IterLib.oneResult(binding, varMember, n, execCxt) ; }
@Override protected QueryIterator execObjectList(Binding binding, Var listVar, Node predicate, List<Node> objectArgs, ExecutionContext execCxt) { // subject a variable. 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) ; final Collection<Node> x ; if ( ! Var.isVar(memberNode) ) // If memberNode is defined, find lists containing it. x = GraphList.listFromMember(new GNode(execCxt.getActiveGraph(), memberNode)) ; else // Hard. Subject unbound, no fixed member. Find every list and use BFI. x = GraphList.findAllLists(execCxt.getActiveGraph()) ; return super.allLists(binding, x, listVar, predicate, new PropFuncArg(objectArgs, null), execCxt) ; }
private static QueryIterator testSlotValue(Graph graph, Binding binding, Node listNode, Node indexNode, Node memberNode, ExecutionContext execCxt) { int i = NodeFactoryExtra.nodeToInt(indexNode) ; if ( i < 0 ) return IterLib.noResults(execCxt) ; Node n = GraphList.get(new GNode(graph, listNode), i) ; if ( n == null ) return IterLib.noResults(execCxt) ; if ( n.equals(memberNode) ) return IterLib.result(binding, execCxt) ; else return IterLib.noResults(execCxt) ; }
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 ; }
/** Calculate ?s list:member ?o as if it were a graph.find */ public static Iterator<Triple> listMember(Graph graph, final Node s, Node o) { if ( isAny(s) ) { Set<Node> x = findAllLists(graph) ; IteratorConcat<Triple> iterConcat = new IteratorConcat<>() ; for ( Node s2 : x ) { Iterator<Triple> iter = listMember(graph, s2, o) ; if ( iter.hasNext() ) iterConcat.add(iter); } return iterConcat ; } GNode gn = new GNode(graph, s) ; if ( ! isAny(o) ) { if ( contains(gn, o) ) return Iter.singleton(Triple.create(s, ListPFunction.nListMember, o)) ; else return Iter.nullIterator() ; } List<Node> x = members(gn) ; return Iter.map(x.iterator(), t -> Triple.create(s, ListPFunction.nListMember, t)) ; }
private static GNode parse(String str) { Model m = ModelFactory.createDefaultModel() ; m.read(new StringReader(str), null, "TTL") ; Graph graph = m.getGraph() ; Triple t = graph.find(r, p, Node.ANY).next() ; return new GNode(graph, t.getObject()) ; }
GNode entry = new GNode(root.getModel().getGraph(), n.asNode()); if ( GraphList.isListNode(entry) ) {