Java Code Examples for org.apache.jena.riot.RDFDataMgr#read()
The following examples show how to use
org.apache.jena.riot.RDFDataMgr#read() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExRIOT_1.java From xcurator with Apache License 2.0 | 6 votes |
public static void main(String...argv) { Model m = ModelFactory.createDefaultModel() ; // read into the model. m.read("data.ttl") ; // Alternatively, use the RDFDataMgr, which reads from the web, // with content negotiation. Plain names are assumed to be // local files where file extension indicates the syntax. Model m2 = RDFDataMgr.loadModel("data.ttl") ; // read in more data, the remote server serves up the data // with the right MIME type. RDFDataMgr.read(m2, "http://host/some-published-data") ; // Read some data but also give a hint for the synatx if it is not // discovered by inspectying the file or by HTTP content negotiation. RDFDataMgr.read(m2, "some-more-data.out", RDFLanguages.TURTLE) ; }
Example 2
Source File: ExRIOT_3.java From xcurator with Apache License 2.0 | 6 votes |
public static void main(String...argv) { Dataset ds = null ; // Read a TriG file into quad storage in-memory. ds = RDFDataMgr.loadDataset("data.trig") ; // read some (more) data into a dataset graph. RDFDataMgr.read(ds, "data2.trig") ; // Create a dataset, Dataset ds2 = DatasetFactory.createTxnMem() ; // read in data, indicating the syntax in case the remote end does not // correctly provide the HTTP content type. RDFDataMgr.read(ds2, "http://host/data2.unknown", TRIG) ; }
Example 3
Source File: SparqlDataSourceTest.java From Server.Java with MIT License | 6 votes |
/** * * @throws Exception */ @BeforeClass public static void setUpClass() throws Exception { final String typeName = "SparqlSourceType"; if ( ! DataSourceTypesRegistry.isRegistered(typeName) ) { DataSourceTypesRegistry.register( typeName, new SparqlDataSourceType() ); } String tmpdir = System.getProperty("java.io.tmpdir"); jena = new File(tmpdir, "ldf-sparql-test"); jena.mkdir(); dataset = TDBFactory.createDataset(jena.getAbsolutePath()); Model model = dataset.getDefaultModel(); InputStream in = ClassLoader.getSystemResourceAsStream("demo.nt"); RDFDataMgr.read(model, in, Lang.NTRIPLES); // Dynamically-generated port comes from pom.xml configuration: build-helper-maven-plugin int fusekiPort = Integer.parseInt(System.getProperty("fuseki.port")); // Create Fuseki, loaded with the test dataset fuseki = FusekiServer.create().setPort(fusekiPort).add("/ds", dataset).build(); fuseki.start(); // Everything is in place, now create the LDF datasource JsonObject config = createConfig("sparql test", "sparql test", typeName); JsonObject settings = new JsonObject(); settings.addProperty("endpoint", "http://localhost:" + fusekiPort + "/ds"); config.add("settings", settings); setDatasource(DataSourceFactory.create(config)); }
Example 4
Source File: RDFToManifest.java From incubator-taverna-language with Apache License 2.0 | 6 votes |
protected static Model jsonLdAsJenaModel(InputStream jsonIn, URI base) throws IOException, RiotException { Model model = ModelFactory.createDefaultModel(); ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); try { // TAVERNA-971: set context classloader so jarcache.json is consulted // even through OSGi Thread.currentThread().setContextClassLoader(RDFToManifest.class.getClassLoader()); // Now we can parse the JSON-LD without network access RDFDataMgr.read(model, jsonIn, base.toASCIIString(), Lang.JSONLD); } finally { // Restore old context class loader (if any) Thread.currentThread().setContextClassLoader(oldCl); } return model; }
Example 5
Source File: ProcessEventObjectsStream.java From EventCoreference with Apache License 2.0 | 6 votes |
private static void readTrigFromStream(Dataset ds, Dataset dsnew) { InputStream is = null; try { is = System.in; if (is==null){ throw new IllegalArgumentException( "No stream input!"); } ByteArrayOutputStream b = cloneInputStream(is); InputStream is1 = new ByteArrayInputStream(b.toByteArray()); InputStream is2 = new ByteArrayInputStream(b.toByteArray()); RDFDataMgr.read(ds, is1, RDFLanguages.TRIG); RDFDataMgr.read(dsnew, is2, RDFLanguages.TRIG); } finally { // close the streams using close method } }
Example 6
Source File: RdfStreamReader.java From RDFUnit with Apache License 2.0 | 5 votes |
@Override public void readDataset(Dataset dataset) throws RdfReaderException { try { RDFDataMgr.read(dataset, inputStream, null, RDFLanguages.nameToLang(format)); } catch (Exception e) { throw new RdfReaderException(e.getMessage(), e); } }
Example 7
Source File: JenaTDBDataSourceTest.java From Server.Java with MIT License | 5 votes |
/** * * @throws Exception */ @BeforeClass public static void setUpClass() throws Exception { final String typeName = "JenaSourceType"; if ( ! DataSourceTypesRegistry.isRegistered(typeName) ) { DataSourceTypesRegistry.register( typeName, new JenaTDBDataSourceType() ); } String tmpdir = System.getProperty("java.io.tmpdir"); jena = new File(tmpdir, "ldf-jena-test"); jena.mkdir(); dataset = TDBFactory.createDataset(jena.getAbsolutePath()); Model model = dataset.getDefaultModel(); InputStream in = ClassLoader.getSystemResourceAsStream("demo.nt"); RDFDataMgr.read(model, in, Lang.NTRIPLES); // Everything is in place, now create the LDF datasource JsonObject config = createConfig("jena tdb test", "jena tdb test", typeName); JsonObject settings = new JsonObject(); settings.addProperty("directory", jena.getAbsolutePath()); config.add("settings", settings); setDatasource(DataSourceFactory.create(config)); }
Example 8
Source File: Validator.java From aliada-tool with GNU General Public License v3.0 | 5 votes |
/** * Builds a new {@link Validator} with the given rule for determining the sample size. */ public Validator() { schema = ModelFactory.createDefaultModel(); RDFDataMgr.read(schema, getClass().getResourceAsStream("/aliada-ontology.owl"), Lang.RDFXML); RDFDataMgr.read(schema, getClass().getResourceAsStream("/efrbroo.owl"), Lang.RDFXML); RDFDataMgr.read(schema, getClass().getResourceAsStream("/current.owl"), Lang.RDFXML); RDFDataMgr.read(schema, getClass().getResourceAsStream("/wgs84_pos.owl"), Lang.RDFXML); RDFDataMgr.read(schema, getClass().getResourceAsStream("/time.owl"), Lang.RDFXML); RDFDataMgr.read(schema, getClass().getResourceAsStream("/skos-xl.owl"), Lang.RDFXML); RDFDataMgr.read(schema, getClass().getResourceAsStream("/0.1.owl"), Lang.RDFXML); reasoner = ReasonerRegistry.getOWLMicroReasoner().bindSchema(schema); }
Example 9
Source File: ModelSetImplJena.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void readFrom(InputStream in, Syntax syntax, String baseURI) throws IOException, ModelRuntimeException, SyntaxNotSupportedException { RDFDataMgr.read(this.dataset.asDatasetGraph(), in, baseURI, getJenaLang(syntax)); }
Example 10
Source File: QueryExecutionTest.java From RDFstarTools with Apache License 2.0 | 5 votes |
protected Model loadModel( String filename ) { final String fullFilename = getClass().getResource("/TurtleStar/"+filename).getFile(); final Graph g = new GraphWrapperStar( GraphFactory.createDefaultGraph() ); final Model m = ModelFactory.createModelForGraph(g); RDFDataMgr.read(m, fullFilename); return m; }
Example 11
Source File: QueryOperation.java From robot with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Load an ontology into a DatasetGraph. The ontology is not changed. * * @deprecated use {@link #loadOntologyAsDataset(OWLOntology)} instead. * @param ontology The ontology to load into the graph * @return A new DatasetGraph with the ontology loaded into the default graph * @throws OWLOntologyStorageException rarely */ @Deprecated public static DatasetGraph loadOntology(OWLOntology ontology) throws OWLOntologyStorageException { ByteArrayOutputStream os = new ByteArrayOutputStream(); ontology.getOWLOntologyManager().saveOntology(ontology, new TurtleDocumentFormat(), os); DatasetGraph dsg = DatasetGraphFactory.create(); RDFDataMgr.read(dsg.getDefaultGraph(), new ByteArrayInputStream(os.toByteArray()), Lang.TURTLE); return dsg; }
Example 12
Source File: JenaIOServiceTest.java From trellis with Apache License 2.0 | 5 votes |
@Test void testNullHtmlSerializer() { final ByteArrayOutputStream out = new ByteArrayOutputStream(); service.write(getTriples(), out, RDFA, identifier); final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); final org.apache.jena.graph.Graph graph = createDefaultGraph(); RDFDataMgr.read(graph, in, Lang.TURTLE); assertTrue(validateGraph(fromJena(graph)), "null HTML serialization didn't default to Turtle!"); }
Example 13
Source File: JenaIOServiceTest.java From trellis with Apache License 2.0 | 5 votes |
@Test void testTurtleSerializer() { final ByteArrayOutputStream out = new ByteArrayOutputStream(); service.write(getTriples(), out, TURTLE, identifier); final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); final org.apache.jena.graph.Graph graph = createDefaultGraph(); RDFDataMgr.read(graph, in, Lang.TURTLE); assertTrue(validateGraph(fromJena(graph)), "Failed round-trip for Turtle!"); }
Example 14
Source File: JenaIOServiceTest.java From trellis with Apache License 2.0 | 5 votes |
@Test void testBufferedSerializer() { final ByteArrayOutputStream out = new ByteArrayOutputStream(); service.write(getTriples(), out, RDFXML, identifier); final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); final org.apache.jena.graph.Graph graph = createDefaultGraph(); RDFDataMgr.read(graph, in, Lang.RDFXML); assertTrue(validateGraph(fromJena(graph)), "Failed round-trip for RDFXML!"); }
Example 15
Source File: JenaIOServiceTest.java From trellis with Apache License 2.0 | 5 votes |
@Test void testNTriplesSerializer() { final ByteArrayOutputStream out = new ByteArrayOutputStream(); service3.write(getTriples(), out, NTRIPLES, identifier); final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); final org.apache.jena.graph.Graph graph = createDefaultGraph(); RDFDataMgr.read(graph, in, Lang.NTRIPLES); assertTrue(validateGraph(fromJena(graph)), "Failed round-trip for N-Triples!"); }
Example 16
Source File: RdfStreamReader.java From RDFUnit with Apache License 2.0 | 5 votes |
@Override public void read(Model model) throws RdfReaderException { try { RDFDataMgr.read(model, inputStream, null, RDFLanguages.nameToLang(format)); } catch (Exception e) { throw new RdfReaderException(e.getMessage(), e); } }
Example 17
Source File: ModelImplJena.java From semweb4j with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void readFrom(Reader reader, Syntax syntax, String baseURI) { assertModel(); RDFDataMgr.read(this.jenaModel, reader, baseURI, getJenaLang(syntax)); }
Example 18
Source File: WorkflowBundleParser.java From incubator-taverna-language with Apache License 2.0 | 4 votes |
/** * Workaround for TAVERNA-71 to find annotations in WorkflowBundle * <p> * FIXME: The annotation links should instead be stored in the * {@link Manifest} using taverna-robundle - see TAVERNA-71 * * @param wb * @throws IOException */ private void parseAnnotations(final WorkflowBundle wb) throws IOException { if (! wb.getAnnotations().isEmpty()) { // Assume already parsed return; } URITools uriTools = new URITools(); for (ResourceEntry resource : wb.getResources().listResources("annotation").values()) { Lang lang = RDFLanguages.contentTypeToLang(resource.getMediaType()); if (lang == null) { // Not a semantic annotation continue; } //System.out.println(resource.getPath()); //System.out.println(resource.getMediaType()); Annotation ann = new Annotation(); // Hackish way to generate a name from the annotation filename // as these typically are UUIDs String name = resource.getPath().replace("annotation/", "").replaceAll("\\..*", ""); // strip extension ann.setName(name); ann.setParent(wb); String path = resource.getPath(); ann.setBody(URI.create("/" + path)); URI base = wb.getGlobalBaseURI().resolve(path); Model model = ModelFactory.createDefaultModel(); InputStream inputStream = resource.getUcfPackage().getResourceAsInputStream(path); if (inputStream == null) { // Not found! continue; } RDFDataMgr.read(model, inputStream, base.toASCIIString(), lang); ResIterator subjs = model.listSubjects(); while (subjs.hasNext()) { Resource r = subjs.next(); //System.out.println(r); WorkflowBean b = uriTools.resolveUri(URI.create(r.getURI()), wb); //System.out.println(b); if (b != null) { ann.setTarget(b); } break; } } }
Example 19
Source File: JenaUtils.java From RDFUnit with Apache License 2.0 | 4 votes |
public static Model readModel(URI uri) { Model model = RdfUnitModelFactory.createDefaultModel(); RDFDataMgr.read(model, uri.toString()); return model; }
Example 20
Source File: GraphColoringHashingFamily.java From quetzal with Eclipse Public License 2.0 | 3 votes |
/** * Load dataset from CLOB field in database * * @param store * @param schema * @return */ public static DatasetGraph loadDataset(InputStream inputStream) { // Read the dataset from CLOB DatasetGraph dsg = DatasetGraphFactory.createMem(); RDFDataMgr.read(dsg,inputStream, Lang.NQUADS); return dsg; }