public static List<Triple> allTriples(GNode gnode) { List<Triple> x = new ArrayList<>() ; allTriples(gnode, x) ; return x ; }
/** 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)) ; }
public static boolean contains(GNode gnode, Node item) { return index(gnode, item) >= 0 ; }
public static void allTriples(GNode gnode, Collection<Triple> acc) { if ( ! isListNode(gnode) ) return ; while( ! listEnd(gnode) ) { triples(gnode, acc) ; gnode = next(gnode) ; } }
public static int length(GNode gnode) { if ( ! isListNode(gnode) ) return -1 ; int len = 0 ; while ( ! listEnd(gnode) ) { len++ ; gnode = next(gnode) ; } return len ; }
public static void members(GNode gnode, final Collection<Node> acc) { if ( ! isListNode(gnode) ) return ; while( ! listEnd(gnode) ) { Node n = car(gnode) ; if ( n != null ) acc.add(n) ; gnode = next(gnode) ; } }
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 ; }
public static int occurs(GNode gnode, Node item) { return indexes(gnode, item).size() ; }
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) ; }
@Test public void testListContains_2() { assertFalse(GraphList.contains(emptyList, node1)) ; }
public static List<Node> members(GNode gnode) { List<Node> x = new ArrayList<>() ; members(gnode, x) ; return x ; }
private /*static*/ Iterator<Triple> graphFind(Graph graph, Node s, Node p, Node o, Context context) { // This is the only place this is called. // It means we can add property functions here. // Fast-path common cases. if ( doingRDFSmember && RDFSmember.equals(p) ) return GraphContainerUtils.rdfsMember(graph, s, o) ; if ( doingListMember && ListMember.equals(p) ) return GraphList.listMember(graph, s, o) ; // Potentially just allow the cases above. //return graph.find(s, p, o) ; return graphFind2(graph, s, p, o, context) ; }
private Node processPropFuncArg(PropFuncArg args) { if ( args.isNode() ) return args.getArg() ; // List ... List<Node> list = args.getArgList() ; if ( list.size() == 0 ) return RDF.Nodes.nil ; BasicPattern bgp = new BasicPattern() ; Node head = GraphList.listToTriples(list, bgp) ; currentGroup().addElement(process(bgp)) ; return head ; }
if ( GraphList.isListNode(entry) ) {
public static Node get(GNode gnode, int idx) { // if ( idx == 0 ) // return car(gnode) ; // Node n = next(gnode) ; // return get(graph, n, idx-1) ; if ( ! isListNode(gnode) ) return null ; while ( ! listEnd(gnode) ) { if ( idx == 0 ) return car(gnode) ; gnode = next(gnode) ; idx -- ; } return null ; }
@Test public void testListIndexes_2() { List<Integer> x = GraphList.indexes(list4, node0) ; assertEquals(0, x.size()) ; }
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) ; }
@Test public void testListContains_3() { assertTrue(GraphList.contains(list4, node1)) ; }