// 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;
  }
Example #2
0
  private Triple resolveTriple(final Triple t, final Binding values) {
    int idx = variables.indexOf(t.getSubject());

    final Node s = idx == -1 ? t.getSubject() : values.get(Var.alloc(variables.get(idx)));

    idx = variables.indexOf(t.getPredicate());
    final Node p = idx == -1 ? t.getPredicate() : values.get(Var.alloc(variables.get(idx)));
    idx = variables.indexOf(t.getObject());
    final Node o = idx == -1 ? t.getObject() : values.get(Var.alloc(variables.get(idx)));
    return new Triple(s, p, o);
  }
Example #3
0
 protected void formatTriple(Triple tp) {
   out.print(slotToString(tp.getSubject()));
   out.print(" ");
   out.print(slotToString(tp.getPredicate()));
   out.print(" ");
   out.print(slotToString(tp.getObject()));
 }
 @Override
 public void triple(Triple triple) {
   // Find nodes.
   // log.info("Triple: "+triple) ;
   processNode(triple.getSubject());
   processNode(triple.getPredicate());
   processNode(triple.getObject());
   triples.add(triple);
   if (triples.size() >= batchSize) processBatch();
 }
  private static void convert(
      List<Triple> triples, List<Tuple<NodeId>> tuples, NodeTable nodeTable) {
    // Slightly faster.  But larger batches?
    for (Triple t : triples) {
      NodeId nid_s = nodeTable.getAllocateNodeId(t.getSubject());
      NodeId nid_p = nodeTable.getAllocateNodeId(t.getPredicate());
      NodeId nid_o = nodeTable.getAllocateNodeId(t.getObject());
      Tuple<NodeId> x = Tuple.createTuple(nid_s, nid_p, nid_o);
      tuples.add(x);
    }

    //        triples.stream().map(t->
    //                  Tuple.createTuple
    //                  (nodeTable.getAllocateNodeId(t.getSubject()),
    //                   nodeTable.getAllocateNodeId(t.getPredicate()),
    //                   nodeTable.getAllocateNodeId(t.getObject())))
    //                .collect(Collectors.toCollection(()->tuples)) ;
  }
Example #6
0
 /**
  * Register all the variables in the triple.
  *
  * @param t the triple to register.
  * @param variables The list of variables.
  * @return t for chaining
  */
 private Triple registerBGPTriple(final Triple t, final List<Node> variables) {
   registerVariables(t.getSubject(), variables);
   registerVariables(t.getPredicate(), variables);
   registerVariables(t.getObject(), variables);
   return t;
 }