private static boolean isMagicProperty(PropertyFunctionRegistry registry, Triple pfTriple) {
    if (!pfTriple.getPredicate().isURI()) return false;

    if (registry.manages(pfTriple.getPredicate().getURI())) return true;

    return false;
  }
Пример #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);
  }
Пример #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()));
 }
  // 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;
  }
  private static Op makeStages(
      BasicPattern triples, Map<Triple, PropertyFunctionInstance> pfInvocations) {
    // Step 3 : Make the operation expression.
    //   For each property function, insert the implementation
    //   For each block of non-property function triples, make a BGP.

    Op op = null;
    BasicPattern pattern = null;
    for (Triple t : triples) {
      if (pfInvocations.containsKey(t)) {
        op = flush(pattern, op);
        pattern = null;
        PropertyFunctionInstance pfi = pfInvocations.get(t);
        OpPropFunc opPF =
            new OpPropFunc(t.getPredicate(), pfi.getSubjectArgList(), pfi.getObjectArgList(), op);
        op = opPF;
        continue;
      }

      // Regular triples - make sure there is a basic pattern in progress.
      if (pattern == null) pattern = new BasicPattern();
      pattern.add(t);
    }
    op = flush(pattern, op);
    return op;
  }
Пример #6
0
 @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();
 }
Пример #7
0
  public static int calcWidthTriples(
      PrefixMap prefixMap, String baseURI, Collection<Triple> triples, int minWidth, int maxWidth) {
    Node prev = null;
    int nodeMaxWidth = minWidth;

    for (Triple triple : triples) {
      Node n = triple.getPredicate();
      if (prev != null && prev.equals(n)) continue;
      int len = calcWidth(prefixMap, baseURI, n);
      if (len > maxWidth) continue;
      if (nodeMaxWidth < len) nodeMaxWidth = len;
      prev = n;
    }
    return nodeMaxWidth;
  }
Пример #8
0
  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)) ;
  }
Пример #9
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;
 }