Ejemplo n.º 1
0
  // 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;
  }
Ejemplo n.º 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);
  }
Ejemplo n.º 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()));
 }
Ejemplo n.º 4
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();
 }
 protected void generateData(
     MapDriver<LongWritable, TripleWritable, LongWritable, QuadWritable> driver, int num) {
   for (int i = 0; i < num; i++) {
     Triple t =
         new Triple(
             NodeFactory.createURI("http://subjects/" + i),
             NodeFactory.createURI("http://predicate"),
             NodeFactory.createLiteral(Integer.toString(i), XSDDatatype.XSDinteger));
     Quad q = new Quad(t.getSubject(), t);
     driver.addInput(new LongWritable(i), new TripleWritable(t));
     driver.addOutput(new LongWritable(i), new QuadWritable(q));
   }
 }
Ejemplo n.º 6
0
  public static Map<Node, Graph> indexBySubject(Iterator<Triple> it) {
    Map<Node, Graph> result = new HashMap<Node, Graph>();
    while (it.hasNext()) {
      Triple triple = it.next();
      Node s = triple.getSubject();

      Graph graph = result.get(s);
      if (graph == null) {
        graph = GraphFactory.createGraphMem();
        result.put(s, graph);
      }
      graph.add(triple);
    }

    return result;
  }
  /**
   * Tests quads to triples conversion
   *
   * @throws IOException
   */
  @Test
  public void triples_to_quads_mapper_01() throws IOException {
    MapDriver<LongWritable, TripleWritable, LongWritable, QuadWritable> driver =
        this.getMapDriver();

    Triple t =
        new Triple(
            NodeFactory.createURI("http://s"),
            NodeFactory.createURI("http://p"),
            NodeFactory.createLiteral("test"));
    Quad q = new Quad(t.getSubject(), t);
    driver
        .withInput(
            new Pair<LongWritable, TripleWritable>(new LongWritable(1), new TripleWritable(t)))
        .withOutput(new Pair<LongWritable, QuadWritable>(new LongWritable(1), new QuadWritable(q)));
    driver.runTest();
  }
Ejemplo n.º 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)) ;
  }
Ejemplo n.º 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;
 }
 @Override
 protected Node getSubject(Triple value) {
   return value.getSubject();
 }