Example #1
0
  public static Graph getGraph() {

    Graph g = Factory.createGraphMem();

    g.add(
        new Triple(
            NodeFactory.createURI("http://example.com/subject"),
            NodeFactory.createURI("http://example.com/predicate"),
            NodeFactory.createURI("http://example.com/object")));

    g.add(
        new Triple(
            NodeFactory.createBlankNode(BlankNodeId.create("a")),
            NodeFactory.createURI("http://example.com/p1"),
            NodeFactory.createBlankNode(BlankNodeId.create("b"))));

    g.add(
        new Triple(
            NodeFactory.createBlankNode(BlankNodeId.create("b")),
            NodeFactory.createURI("http://example.com/p2"),
            NodeFactory.createLiteral("foo")));

    g.add(
        new Triple(
            NodeFactory.createURI("http://example.com/ns/e"),
            NodeFactory.createURI("http://example.com/ns/p5"),
            NodeFactory.createLiteral("verify base works")));

    return g;
  }
  @BeforeClass
  public static void setup() {
    // Dataset for implicit join tests
    implJoin = DatasetFactory.createTxnMem();

    Node a = NodeFactory.createURI("http://a");
    Node b = NodeFactory.createURI("http://b");
    Node c = NodeFactory.createURI("http://c");
    Node p1 = NodeFactory.createURI("http://p1");
    Node p2 = NodeFactory.createURI("http://p2");
    Node pSelf = NodeFactory.createURI("http://self");
    Node o = NodeFactory.createLiteral("object");

    DatasetGraph dsg = implJoin.asDatasetGraph();
    dsg.add(Quad.defaultGraphNodeGenerated, a, p1, o);
    dsg.add(Quad.defaultGraphNodeGenerated, a, p2, o);
    dsg.add(Quad.defaultGraphNodeGenerated, b, p1, o);
    dsg.add(Quad.defaultGraphNodeGenerated, b, p2, o);
    dsg.add(Quad.defaultGraphNodeGenerated, c, p1, o);
    // dsg.add(Quad.defaultGraphNodeGenerated, a, pSelf, a);

    // Currently these optimizations are off by default
    Assert.assertFalse(ARQ.isFalse(ARQ.optFilterImplicitJoin));
    Assert.assertFalse(ARQ.isFalse(ARQ.optImplicitLeftJoin));
  }
 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));
   }
 }
  /**
   * 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();
  }