Пример #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;
  }
Пример #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());
 }
Пример #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();
   }
 }
Пример #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;
  }
Пример #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")));
 }
Пример #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();
   }
 }
Пример #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;
 }
Пример #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();
   }
 }
Пример #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());
 }
Пример #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());
 }
Пример #12
0
 @Override
 public GraphStatisticsHandler getStatisticsHandler() {
   return base.getStatisticsHandler();
 }
Пример #13
0
 @Override
 public TransactionHandler getTransactionHandler() {
   return base.getTransactionHandler();
 }
Пример #14
0
 @Override
 public boolean dependsOn(Graph other) {
   return base.dependsOn(other);
 }
Пример #15
0
 @Override
 public void performDelete(Triple t) {
   base.delete(t);
 }
Пример #16
0
 @Override
 public boolean isIsomorphicWith(Graph g) {
   return base.isIsomorphicWith(g);
 }
Пример #17
0
 @Override
 public ExtendedIterator<Triple> find(Triple m) {
   return SimpleEventManager.notifyingRemove(this, base.find(m));
 }
Пример #18
0
 @Override
 public void clear() {
   base.clear();
   getEventManager().notifyEvent(this, GraphEvents.removeAll);
 }
Пример #19
0
 @Override
 public void add(Triple t) {
   base.add(t);
   getEventManager().notifyAddTriple(this, t);
 }
Пример #20
0
 @Override
 public Capabilities getCapabilities() {
   return base.getCapabilities();
 }
Пример #21
0
 @Override
 public PrefixMapping getPrefixMapping() {
   return base.getPrefixMapping();
 }
Пример #22
0
 @Override
 public void close() {
   base.close();
 }
Пример #23
0
 @Override
 public void delete(Triple t) {
   base.delete(t);
   getEventManager().notifyDeleteTriple(this, t);
 }
Пример #24
0
 @Override
 public boolean isClosed() {
   return base.isClosed();
 }
Пример #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));
 }
Пример #26
0
 @Override
 public boolean isEmpty() {
   return base.isEmpty();
 }
Пример #27
0
 @Override
 public ExtendedIterator<Triple> find(Node s, Node p, Node o) {
   return SimpleEventManager.notifyingRemove(this, base.find(s, p, o));
 }
Пример #28
0
 @Override
 public int size() {
   return base.size();
 }
Пример #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));
    }
    */
  }
Пример #30
0
 @Override
 public void performAdd(Triple t) {
   base.add(t);
 }