Ejemplo n.º 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;
  }
Ejemplo n.º 2
0
 /** Test that the Standard reifier will expose implicit quads arising from reifyAs(). */
 public void testStandardExplode() {
   Graph g = getGraph();
   ReifierStd.reifyAs(g, node("a"), triple("p Q r"));
   Graph r = Factory.createDefaultGraph();
   graphAdd(r, "a rdf:type rdf:Statement; a rdf:subject p; a rdf:predicate Q; a rdf:object r");
   assertEquals(4, g.size());
   assertIsomorphic(r, g);
 }
 @Override
 protected void writeTuples(File f, List<Triple> tuples) throws FileNotFoundException {
   Graph g = GraphFactory.createGraphMem();
   for (Triple t : tuples) {
     g.add(t);
   }
   RDFDataMgr.write(new FileOutputStream(f), g, getLanguage());
 }
Ejemplo n.º 4
0
 public void testKevinCaseB() {
   Graph G = getGraph();
   Node X = node("x"), Y = node("y");
   Node a = node("a"), b = node("b"), c = node("c");
   G.add(Triple.create(X, RDF.Nodes.subject, Y));
   try {
     ReifierStd.reifyAs(G, X, Triple.create(a, b, c));
     fail("X already has subject Y: cannot make it a");
   } catch (CannotReifyException e) {
     pass();
   }
 }
Ejemplo n.º 5
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;
  }
Ejemplo n.º 6
0
 /** Check that the standard reifier will note, but not hide, reification quads. */
 public void testStandard() {
   Graph g = getGraph();
   assertFalse(ReifierStd.hasTriple(g, triple("s p o")));
   g.add(NodeCreateUtils.createTriple("x rdf:subject s"));
   assertEquals(1, g.size());
   g.add(NodeCreateUtils.createTriple("x rdf:predicate p"));
   assertEquals(2, g.size());
   g.add(NodeCreateUtils.createTriple("x rdf:object o"));
   assertEquals(3, g.size());
   g.add(NodeCreateUtils.createTriple("x rdf:type rdf:Statement"));
   assertEquals(4, g.size());
   assertTrue(ReifierStd.hasTriple(g, triple("s p o")));
 }
Ejemplo n.º 7
0
 /* Count the triples for the graph.find */
 public static long countTriples(Graph graph, Node s, Node p, Node o) {
   ExtendedIterator<Triple> iter = graph.find(s, p, o);
   try {
     return Iter.count(iter);
   } finally {
     iter.close();
   }
 }
Ejemplo n.º 8
0
 public static Map<Node, Graph> indexBySubject(Graph graph) {
   ExtendedIterator<Triple> it = graph.find(Node.ANY, Node.ANY, Node.ANY);
   Map<Node, Graph> result;
   try {
     result = indexBySubject(it);
   } finally {
     it.close();
   }
   return result;
 }
Ejemplo n.º 9
0
 /** Get exactly one triple or null for none or more than one. */
 public static Triple triple1(Graph graph, Node s, Node p, Node o) {
   ExtendedIterator<Triple> iter = graph.find(s, p, o);
   try {
     if (!iter.hasNext()) return null;
     Triple t = iter.next();
     if (iter.hasNext()) return null;
     return t;
   } finally {
     iter.close();
   }
 }
Ejemplo n.º 10
0
 public void testQuadRemove() {
   Graph g = getGraph();
   assertEquals(0, g.size());
   Triple s = NodeCreateUtils.createTriple("x rdf:subject s");
   Triple p = NodeCreateUtils.createTriple("x rdf:predicate p");
   Triple o = NodeCreateUtils.createTriple("x rdf:object o");
   Triple t = NodeCreateUtils.createTriple("x rdf:type rdf:Statement");
   g.add(s);
   g.add(p);
   g.add(o);
   g.add(t);
   assertEquals(4, g.size());
   g.delete(s);
   g.delete(p);
   g.delete(o);
   g.delete(t);
   assertEquals(0, g.size());
 }
Ejemplo n.º 11
0
 public void testEmpty() {
   Graph g = getGraph();
   assertTrue(g.isEmpty());
   graphAdd(g, "x rdf:type rdf:Statement");
   assertFalse(g.isEmpty());
   graphAdd(g, "x rdf:subject Deconstruction");
   assertFalse(g.isEmpty());
   graphAdd(g, "x rdf:predicate rdfs:subTypeOf");
   assertFalse(g.isEmpty());
   graphAdd(g, "x rdf:object LiteraryCriticism");
   assertFalse(g.isEmpty());
 }
Ejemplo n.º 12
0
 @Override
 public GraphStatisticsHandler getStatisticsHandler() {
   return base.getStatisticsHandler();
 }
Ejemplo n.º 13
0
 @Override
 public TransactionHandler getTransactionHandler() {
   return base.getTransactionHandler();
 }
Ejemplo n.º 14
0
 @Override
 public boolean dependsOn(Graph other) {
   return base.dependsOn(other);
 }
Ejemplo n.º 15
0
 @Override
 public void performDelete(Triple t) {
   base.delete(t);
 }
Ejemplo n.º 16
0
 @Override
 public boolean isIsomorphicWith(Graph g) {
   return base.isIsomorphicWith(g);
 }
Ejemplo n.º 17
0
 @Override
 public ExtendedIterator<Triple> find(Triple m) {
   return SimpleEventManager.notifyingRemove(this, base.find(m));
 }
Ejemplo n.º 18
0
 @Override
 public void clear() {
   base.clear();
   getEventManager().notifyEvent(this, GraphEvents.removeAll);
 }
Ejemplo n.º 19
0
 @Override
 public void add(Triple t) {
   base.add(t);
   getEventManager().notifyAddTriple(this, t);
 }
Ejemplo n.º 20
0
 @Override
 public Capabilities getCapabilities() {
   return base.getCapabilities();
 }
Ejemplo n.º 21
0
 @Override
 public PrefixMapping getPrefixMapping() {
   return base.getPrefixMapping();
 }
Ejemplo n.º 22
0
 @Override
 public void close() {
   base.close();
 }
Ejemplo n.º 23
0
 @Override
 public void delete(Triple t) {
   base.delete(t);
   getEventManager().notifyDeleteTriple(this, t);
 }
Ejemplo n.º 24
0
 @Override
 public boolean isClosed() {
   return base.isClosed();
 }
Ejemplo n.º 25
0
 @Override
 public void remove(Node s, Node p, Node o) {
   base.remove(s, p, o);
   getEventManager().notifyEvent(this, GraphEvents.remove(s, p, o));
 }
Ejemplo n.º 26
0
 @Override
 public boolean isEmpty() {
   return base.isEmpty();
 }
Ejemplo n.º 27
0
 @Override
 public ExtendedIterator<Triple> find(Node s, Node p, Node o) {
   return SimpleEventManager.notifyingRemove(this, base.find(s, p, o));
 }
Ejemplo n.º 28
0
 @Override
 public int size() {
   return base.size();
 }
Ejemplo n.º 29
0
  /**
   * Instantiates a new sparql construct function.
   *
   * @param conf the graph with dataflow definition
   * @param confRoot the specific node in the graph representing the producer configuration
   * @param map the map to access the other defined producers
   * @see RDFProducer
   */
  public SparqlConstructFunction(Graph conf, Node confRoot, final ProducerMap map) {
    URI baseURI = URI.create(confRoot.getURI());

    Node inputNode = GraphUtils.getSingleValueOptProperty(conf, confRoot, DF.input.asNode());
    inputProducer =
        (inputNode != null) ? map.getProducer(inputNode) : EmptyGraphProducer.getInstance();

    Node queryAsInputNode = NodeFactory.createURI(baseURI.resolve("#query").toString());

    Node queryNode = GraphUtils.getSingleValueOptProperty(conf, confRoot, DF.configTxt.asNode());
    String queryTxt = (queryNode != null) ? queryNode.getLiteralLexicalForm() : null;

    Node configNode = GraphUtils.getSingleValueOptProperty(conf, confRoot, DF.config.asNode());
    RDFProducer configProducer = (configNode != null) ? map.getProducer(configNode) : null;

    Node configRootNode =
        GraphUtils.getSingleValueOptProperty(conf, confRoot, DF.configRoot.asNode());
    if (configRootNode == null) configRootNode = configNode;
    if (configRootNode == null && inputNode != null) {
      Iterator<Node> namedInputNodes =
          GraphUtils.getPropertyValues(conf, inputNode, DF.namedInput.asNode());
      while (namedInputNodes.hasNext()) {
        Node namedInputNode = namedInputNodes.next();
        if (conf.contains(namedInputNode, DF.id.asNode(), queryAsInputNode)) {
          configRootNode =
              GraphUtils.getSingleValueProperty(conf, namedInputNode, DF.input.asNode());
          break;
        }
      }
    }

    //		String configRootURI = (configRootNode != null && configRootNode.isURI()) ?
    // configRootNode.getURI() : null;

    queryProducer =
        new CoalesceQueryProducer(
            new GraphQueryProducer(
                new CoalesceGraphProducer(
                    configProducer, new SelectGraphProducer(inputProducer, queryAsInputNode)),
                configRootNode /*NodeFactory.createURI(baseURI.resolve("").toString())*/),
            new StringQueryProducer(queryTxt, baseURI.toString()));
    //		final Model confModel = ModelFactory.createModelForGraph(conf);
    //		Resource constructResource =
    //			confModel
    //					.getRDFNode(confRoot)
    //					.asResource()
    //					.getPropertyResourceValue(SPINX.config);
    //		Iterator<Producer> fromGraphProds =
    //			confModel
    //					.getRDFNode(confRoot)
    //					.asResource()
    //					.listProperties(SPINX.from)
    //					.mapWith(new Map1<Statement, Producer>() {
    //						@Override
    //						public Producer map1(Statement stmt) {
    //							return map.getProducer(stmt.getObject().asNode());
    //						}
    //					});
    // defaultProd = null;
    //		if (!fromGraphProds.hasNext()) {
    //			defaultProd = EmptyGraphProducer.getInstance();
    //		} else {
    //			defaultProd = fromGraphProds.next();
    //			if (fromGraphProds.hasNext()) {
    //				defaultProd =
    //					new UnionFunction(
    //							new ConcatenatedIterator<Producer>(
    //									new SingletonIterator<Producer>(defaultProd),
    //									fromGraphProds));
    //			}
    //		}
    //		Iterator<Node> fromNamedGraphNames =
    //			confModel
    //					.getRDFNode(confRoot)
    //					.asResource()
    //					.listProperties(SPINX.fromNamed)
    //					.mapWith(new Map1<Statement, Node>() {
    //						@Override
    //						public Node map1(Statement stmt) {
    //							return stmt.getObject().asNode();
    //						}
    //					});
    //		while (fromNamedGraphNames.hasNext()) {
    //			Node graphNames = fromNamedGraphNames.next();
    //			prodMap.put(graphNames, map.getProducer(graphNames));
    //		}

    //		query = QueryFactory.toQuery(conf, constructResource.asNode());
    //		if (query == null)
    //			throw new RuntimeException("Parsing Error");

    /*
    // debug
    Graph revEnginedGraph = SpinxFactory.fromQuery(query);
    System.out.println();
    System.out.println("**********************************");
    System.out.println("*** Reverse Engine query graph ***");
    System.out.println("**********************************");
    ModelFactory.createModelForGraph(revEnginedGraph).write(System.out,"N3");
    System.out.println("**********************************");
    System.out.println();
    */

    /*
    SPINFactory.asExpression(constructResource);
    query = ARQFactory.get().createQuery(SPINFactory.asQuery(constructResource));
    */
    /*
    Iterator<String> graphUris =
    	new ConcatenatedIterator<String>(
    			query.getGraphURIs().iterator(),
    			query.getNamedGraphURIs().iterator());
    while (graphUris.hasNext()) {
    	Node node = confModel.getResource(graphUris.next()).asNode();
    	prodMap.put(node, (GraphProducer) map.getProducer(node));
    }
    */
  }
Ejemplo n.º 30
0
 @Override
 public void performAdd(Triple t) {
   base.add(t);
 }