protected MGraph getOntologyAsMGraph(
      OWLOntologyID ontologyId, boolean merge, IRI universalPrefix) {
    if (merge)
      throw new UnsupportedOperationException(
          "Merge not implemented yet for Clerezza triple collections.");
    /*
     * TODO manage import rewrites better once the container ID is fully configurable (i.e. instead of
     * going upOne() add "session" or "ontology" if needed). But only do this if we keep considering
     * imported ontologies as *not* managed.
     */
    // if (!merge) { // TODO
    MGraph o =
        new IndexedMGraph(ontologyProvider.getStoredOntology(ontologyId, MGraph.class, merge));

    // Now rewrite import statements

    // Scan import statements for each owl:Ontology instance (hopefully one).
    String tid = getID();
    // Bit of a hack : since ontology spaces are named like {scopeid}/{core|custom}, in that
    // particular
    // case we go back to {scopeid}, whereas for sessions we maintain their original id.
    if (backwardPathLength > 0) tid = tid.split("/")[0];

    Iterator<Triple> it;
    List<Triple> newImports = new LinkedList<Triple>();
    synchronized (o) {
      it = o.filter(null, OWL.imports, null);
      // We use this list to avoid concurrent modification exceptions.
      List<Triple> replaceUs = new LinkedList<Triple>();
      while (it.hasNext()) replaceUs.add(it.next());

      for (Triple t : replaceUs) {
        String s = ((UriRef) (t.getObject())).getUnicodeString();
        // FIXME note the different import targets in the OWLOntology and TripleColllection objects!
        // s = s.substring(s.indexOf("::") + 2, s.length());
        boolean managed = managedOntologies.contains(IRI.create(s));
        UriRef target =
            new UriRef(
                (managed
                        ? universalPrefix + "/" + tid + "/"
                        : URIUtils.upOne(universalPrefix) + "/")
                    + s);
        o.remove(t);
        newImports.add(new TripleImpl(t.getSubject(), OWL.imports, target));
      }
    }

    for (Triple t : newImports) o.add(t);

    // } // TODO else if (merge)

    return o;
  }
  private TripleCollection getMergedTc() {
    TripleCollection result = new SimpleMGraph(); // Takes less memory than the Indexed one

    for (OWLOntologyID key : listManagedOntologies()) {
      // TODO when implemented, switch to true.
      TripleCollection managed = getOntology(key, TripleCollection.class, false);
      Set<Resource> exclusions = new HashSet<Resource>();
      Iterator<Triple> it = managed.filter(null, RDF.type, OWL.Ontology);
      while (it.hasNext()) exclusions.add(it.next().getSubject());
      for (Triple t : managed) if (!exclusions.contains(t.getSubject())) result.add(t);
    }

    // TODO Purge property usage

    return result;
  }
  @Test
  public void curiesInContextTest() throws IOException, JsonLdError {
    final InputStream in =
        getClass().getClassLoader().getResourceAsStream("testfiles/curies-in-context.jsonld");
    final Object input = JSONUtils.fromInputStream(in);

    final ClerezzaTripleCallback callback = new ClerezzaTripleCallback();

    final MGraph graph = (MGraph) JsonLdProcessor.toRDF(input, callback);

    for (final Triple t : graph) {
      System.out.println(t);
      assertTrue(
          "Predicate got fully expanded", t.getPredicate().getUnicodeString().startsWith("http"));
    }
    assertEquals("Graph size", 3, graph.size());
  }