@Test @Ignore public void namedGraphToModelTest() throws Exception { for (String resourceFile : RESOURCE_FILES) { InputStream is = this.getClass().getResourceAsStream(resourceFile); Dataset dataset = DatasetFactory.createGeneral(); RDFDataMgr.read(dataset, is, RDFFormat.TRIG.getLang()); is.close(); String modelName = dataset.listNames().next(); Model model1 = dataset.getNamedModel(modelName); GraphCollection gc = ModelConverter.modelToGraphCollection(modelName, dataset); LinkedList<NamedGraph> graphs = gc.getGraphs(); String graphName = null; for (NamedGraph g : graphs) { if (!g.getName().isEmpty() && g.getName().contains(modelName)) { graphName = g.getName(); break; } } Model model2 = ModelConverter.namedGraphToModel(graphName, gc); Dataset dataset2 = DatasetFactory.createGeneral(); dataset2.addNamedModel(modelName, model2); dataset2.getDefaultModel().setNsPrefixes(dataset2.getNamedModel(modelName).getNsPrefixMap()); File outFile = testFolder.newFile(); OutputStream os = new FileOutputStream(outFile); RDFDataMgr.write(os, dataset2, RDFFormat.TRIG.getLang()); os.close(); Assert.assertTrue(model1.listStatements().hasNext() && model2.listStatements().hasNext()); Assert.assertTrue(model1.isIsomorphicWith(model2)); } }
public static Model namedGraphToModel(String graphName, GraphCollection gc) throws Exception { NamedGraph graph = null; for (NamedGraph g : gc.getGraphs()) { if (g.getName().equals(graphName)) { graph = g; break; } } return namedGraphToModel(graph, gc.getPrefixes()); }
ModelConverter { public static Model namedGraphToModel(String graphName, GraphCollection gc) throws Exception { NamedGraph graph = null; for (NamedGraph g : gc.getGraphs()) { if (g.getName().equals(graphName)) { graph = g; break; } } return namedGraphToModel(graph, gc.getPrefixes()); } }
ModelConverter { public static Model namedGraphToModel(String graphName, GraphCollection gc) throws Exception { NamedGraph graph = null; for (NamedGraph g : gc.getGraphs()) { if (g.getName().equals(graphName)) { graph = g; break; } } return namedGraphToModel(graph, gc.getPrefixes()); }  }
ModelConverter { public static Model namedGraphToModel(String graphName, GraphCollection gc) throws Exception { NamedGraph graph = null; for (NamedGraph g : gc.getGraphs()) { if (g.getName().equals(graphName)) { graph = g; break; } } return namedGraphToModel(graph, gc.getPrefixes()); }  static Model namedGraphToModel(String graphName, GraphCollection gc); static GraphCollection modelToGraphCollection(String modelURI, Dataset dataset); static GraphCollection modelsToGraphCollection(Dataset dataset, String... modelURIs); static GraphCollection fromDataset(Dataset dataset); static NamedGraph fromModel(String name, Model model); }
ModelConverter { public static Model namedGraphToModel(String graphName, GraphCollection gc) throws Exception { NamedGraph graph = null; for (NamedGraph g : gc.getGraphs()) { if (g.getName().equals(graphName)) { graph = g; break; } } return namedGraphToModel(graph, gc.getPrefixes()); }  static Model namedGraphToModel(String graphName, GraphCollection gc); static GraphCollection modelToGraphCollection(String modelURI, Dataset dataset); static GraphCollection modelsToGraphCollection(Dataset dataset, String... modelURIs); static GraphCollection fromDataset(Dataset dataset); static NamedGraph fromModel(String name, Model model);  }