Java Code Examples for com.hp.hpl.jena.rdf.model.Model#write()
The following examples show how to use
com.hp.hpl.jena.rdf.model.Model#write() .
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: OntologyHandler.java From dbpedia-live-mirror with GNU General Public License v3.0 | 6 votes |
private List<String> getRemoteOntologyTriples() { List<String> triples = null; try ( final ByteArrayOutputStream os = new ByteArrayOutputStream(); ){ Model model = ModelFactory.createDefaultModel(); model.read(ontologyURI); model.write(os, "N-TRIPLE"); String ontology = os.toString("UTF8"); triples = new ArrayList<>(); for (String t : ontology.split("\n")) { triples.add(t.trim()); } Collections.sort(triples); } catch (Exception e) { logger.warn("Cannot download remote ontology", e); } finally { return triples; } }
Example 2
Source File: Mapping.java From xcurator with Apache License 2.0 | 6 votes |
public void generateRDFs(String tdbPath, Document dataDoc, String typePrefix, PrintStream out, String format, StringMetric stringMetric, double threshold) throws XPathExpressionException { Model model = JenaUtils.getTDBModel(tdbPath); for (Entity entity : entities) { String entityPath = entity.getPath(); LogUtils.debug(this.getClass(), "Creating instances of " + entity); NodeList nodeList = XMLUtils.getNodesByPath(entityPath, null, dataDoc); for (int i = 0; i < nodeList.getLength(); i++) { entity.generateRDF((Element) nodeList.item(i), dataDoc, model, typePrefix, stringMetric, threshold); } LogUtils.debug(this.getClass(), "Instances of " + entity + " are created."); } if (out != null) { model.write(out, format); } model.commit(); model.close(); }
Example 3
Source File: RdfReader.java From EventCoreference with Apache License 2.0 | 6 votes |
static void readRdfFile (String pathToRdfFile) { // create an empty model Model model = ModelFactory.createDefaultModel(); // use the FileManager to find the input file InputStream in = FileManager.get().open( pathToRdfFile ); if (in == null) { throw new IllegalArgumentException( "File: " + pathToRdfFile + " not found"); } // read the RDF/XML file model.read(in, null); // write it to standard out model.write(System.out); }
Example 4
Source File: WP2AbbreviatedWriter.java From GeoTriples with Apache License 2.0 | 5 votes |
@Override synchronized public void write(Model baseModel, Writer out, String base) { if (baseModel.getGraph().getCapabilities().findContractSafe() == false) { logger.warn("Workaround for bugs 803804 and 858163: using RDF/XML (not RDF/XML-ABBREV) writer for unsafe graph " + baseModel.getGraph().getClass()); baseModel.write(out, "RDF/XML", base); } else super.write(baseModel, out, base); }
Example 5
Source File: AssemblerExample.java From GeoTriples with Apache License 2.0 | 5 votes |
public static void main(String[] args) { // Load assembler specification from file Model assemblerSpec = FileManager.get().loadModel("doc/example/assembler.ttl"); // Get the model resource Resource modelSpec = assemblerSpec.createResource(assemblerSpec.expandPrefix(":myModel")); // Assemble a model Model m = Assembler.general.openModel(modelSpec); // Write it to System.out m.write(System.out); m.close(); }
Example 6
Source File: ToN3.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
/** * @param args .. */ public static void main(String[] args) throws FileNotFoundException { Model m = ModelFactory.createDefaultModel(); m.read(new FileInputStream(new File( "P:\\__sirdf\\rdf2go\\src\\org\\ontoware\\rdf2go\\example\\thiemann.foaf.rdf.xml")), ""); m.write(System.out, "N-TRIPLES"); }
Example 7
Source File: SystemLoaderExample.java From GeoTriples with Apache License 2.0 | 4 votes |
public static void main(String[] args) { // First, let's set up an in-memory HSQLDB database, // load a simple SQL database into it, and generate // a default mapping for this database using the // W3C Direct Mapping SystemLoader loader = new SystemLoader(); loader.setJdbcURL("jdbc:hsqldb:mem:test"); loader.setStartupSQLScript("doc/example/simple.sql"); loader.setGenerateW3CDirectMapping(true); CompiledMapping mapping = loader.getMapping(); // Print some internal stuff that shows how D2RQ maps the // database to RDF triples for (TripleRelation internal: mapping.getTripleRelations()) { System.out.println(internal); } // Write the contents of the virtual RDF model as N-Triples Model model = loader.getModelD2RQ(); model.write(System.out, "N-TRIPLES"); // Important -- close the model! model.close(); // Now let's load an example mapping file that connects to // a MySQL database loader = new SystemLoader(); loader.setMappingFileOrJdbcURL("doc/example/mapping-iswc.ttl"); loader.setFastMode(true); loader.setSystemBaseURI("http://example.com/"); // Get the virtual model and run a SPARQL query model = loader.getModelD2RQ(); ResultSet rs = QueryExecutionFactory.create( "SELECT * {?s ?p ?o} LIMIT 10", model).execSelect(); while (rs.hasNext()) { System.out.println(rs.next()); } // Important -- close the model! model.close(); }