Refine search
Model inModel = ModelFactory.createDefaultModel(); inModel.read( System.in, null, m_inputFormat ); FileManager.get().readModel( inModel, in, lang ); m_model.add( inModel ); m_model.setNsPrefixes( inModel );
public static void main(String[] args) throws IOException { FileManager.get().addLocatorClassLoader(ExampleAPI_04.class.getClassLoader()); InputStream in = FileManager.get().open("data/data2.ttl"); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line = null; Model all = ModelFactory.createDefaultModel(); while ( ( line = reader.readLine() ) != null ) { ByteArrayInputStream bais = new ByteArrayInputStream(line.getBytes()); Model model = ModelFactory.createDefaultModel(); model.read(bais, null, "TURTLE"); model.write(System.out, "TURTLE"); all.add(model); all.setNsPrefixes(model.getNsPrefixMap()); System.out.println("----------------"); } all.write(System.out, "TURTLE"); }
public static void main(String[] args) { FileManager fm = FileManager.get(); fm.addLocatorClassLoader(ExampleAPI_01.class.getClassLoader()); // load an RDF file using the FileManager Model model = fm.loadModel("data/data.ttl", null, "TURTLE"); model.write(System.out, "TURTLE"); }
/** Force a file handler to have the default configuration. */ public static void setStdLocators(FileManager fMgr) { fMgr.fmHandlers.clear() ; fMgr.addLocatorFile() ; fMgr.addLocatorURL() ; fMgr.addLocatorClassLoader(fMgr.getClass().getClassLoader()) ; } /** Create with the given location mapper */
Model model = FileManager.get().loadModel("/home/raven/Projects/Eclipse/24-7-platform/link-specifications/dbpedia-linkedgeodata-airport/positive.nt"); Graph graph = model.getGraph(); Set<Triple> triples = graph.find(null, null, null).toSet(); Model result = ModelFactory.createDefaultModel(); Set<Triple> ts = GeoMapSupplierUtils.geomizedToRdf(map); GraphUtil.add(result.getGraph(), ts.iterator()); result.write(System.out, "N-TRIPLES");
/** * Cycle bug in transitive reasoner */ public void testTransitiveCycleBug() { Model m = FileManager.get().loadModel( "file:testing/reasoners/bugs/unbroken.n3" ); OntModel om = ModelFactory.createOntologyModel( OntModelSpec.RDFS_MEM_TRANS_INF, m ); OntClass rootClass = om.getOntClass( RDFS.Resource.getURI() ); Resource c = m.getResource("c"); Set<OntClass> direct = rootClass.listSubClasses( true ).toSet(); assertFalse( direct.contains( c ) ); } /**
public List<String> locations() { List<String> locations = new ArrayList<>() ; if ( modAssembler.getLocation() != null ) locations.add(modAssembler.getLocation().getDirectoryPath()) ; // Extract the location from the assember file. if ( modAssembler.getAssemblerFile() != null ) { // Find and clear all locations Model m = FileManager.get().loadModel(modAssembler.getAssemblerFile()) ; Query query = QueryFactory.create("PREFIX tdb: <http://jena.hpl.hp.com/2008/tdb#> SELECT ?dir { [] tdb:location ?dir FILTER (isURI(?dir)) }") ; try(QueryExecution qExec = QueryExecutionFactory.create(query, m)) { for (ResultSet rs = qExec.execSelect() ; rs.hasNext() ; ) { String x = rs.nextSolution().getResource("dir").getURI() ; locations.add(x) ; } } } return locations ; } }
@Override public void runTest() { Model model = ModelFactory.createDefaultModel() ; RDFReader t = new TurtleReader() ; try { if ( baseIRI != null ) t.read(model, FileManager.get().open(input), baseIRI) ; else t.read(model, input) ; // "http://www.w3.org/2001/sw/DataAccess/df1/tests/rdfq-results.ttl" String syntax = FileUtils.guessLang(output, FileUtils.langNTriple) ; Model results = FileManager.get().loadModel(output, syntax); boolean b = model.isIsomorphicWith(results) ; if ( !b ) assertTrue("Models not isomorphic", b) ; } catch (TurtleParseException ex) { throw ex ; } } }
private static Model loadSchemas( Model schema, Resource R ) { StmtIterator schemas = R.listProperties( schemaURL ); if (schemas.hasNext()) { System.err.println( "WARNING: detected obsolete use of jms:schemaURL when wrapping a reasoner factory" ); System.err.println( " This will fail to work in the next release of Jena" ); } while (schemas.hasNext()) { Statement s = schemas.nextStatement(); Resource sc = s.getResource(); FileManager.get().readModel( schema, sc.getURI() ); } return schema; }
public void testMultipleExternalContent() { Assembler a = new ContentAssembler(); String sourceA = Testing + "/schema.n3"; String sourceB = Testing + "/schema2.n3"; Resource root = resourceInModel ( "x rdf:type ja:Content; x rdf:type ja:ExternalContent" + "; x ja:externalContent file:" + sourceA + "; x ja:externalContent file:" + sourceB ); Content c = (Content) a.open( root ); Model wanted = FileManager.get().loadModel( "file:" + sourceA ).add( FileManager.get().loadModel( "file:" + sourceB ) ); assertIsoModels( wanted, c.fill( model( "" ) ) ); }
public static void main(String[] args) { FileManager fm = FileManager.get(); fm.addLocatorClassLoader(ExampleTDB_04.class.getClassLoader()); InputStream in = fm.open("data/data.nt"); DatasetGraphTDB dsg = TDBInternal.getBaseDatasetGraphTDB(TDBFactory.createDatasetGraph()); GraphListener listener = new MyListener(); dsg.getDefaultGraph().getEventManager().register(listener); Iterator<Node> iter = dsg.listGraphNodes(); while ( iter.hasNext() ) { Graph graph = dsg.getGraph(iter.next()); graph.getEventManager().register(listener); } // this does not send events to the GraphListener TDBLoader.load(dsg, in, false); // this does not uses the Graph SPI dsg.add(new Quad(Quad.defaultGraphIRI, NodeFactory.createURI("x"), NodeFactory.createURI("y"), NodeFactory.createURI("z"))); // this does Graph graph = dsg.getDefaultGraph(); graph.add(new Triple(NodeFactory.createURI("x"), NodeFactory.createURI("y"), NodeFactory.createURI("z"))); // this sends events to the GraphListener Model model = ModelFactory.createModelForGraph(dsg.getDefaultGraph()) ; model.add(ResourceFactory.createProperty("foo:x1"), RDFS.label, "X1"); // this does it too in = fm.open("data/data.nt"); model.read(in, "", "N-TRIPLES"); dsg.close(); }
Model premises = FileManager.get().loadModel("file:testing/wg/someValuesFrom/premises001.rdf"); Reasoner reasoner = GenericRuleReasonerFactory.theInstance().create(configuration); InfModel conclusions = ModelFactory.createInfModel(reasoner, premises); for (StmtIterator i = premises.listStatements(); i.hasNext(); ) { System.out.println(" - " + i.next()); Resource c = conclusions.getResource("http://www.w3.org/2002/03owlt/someValuesFrom/premises001#c"); Resource r = conclusions.getResource("http://www.w3.org/2002/03owlt/someValuesFrom/premises001#r"); Resource v = (Resource)i.getRequiredProperty(p).getObject(); System.out.println("Value of i.p = " + v); System.out.println("Types of v are: ");
/** * Run the consistency check, returning a ValidityReport. */ public ValidityReport testResults() { Model t = FileManager.get().loadModel(BASE_DIR + tbox); Model a = FileManager.get().loadModel(BASE_DIR + abox); // Work around non-deterministic bug in bindSchema // Reasoner r = rf.create(null).bindSchema(t); Reasoner r = rf.create(null); a.add(t); InfModel im = ModelFactory.createInfModel(r, a); return im.validate(); }
public static void main(String[] args) { FileManager.get().addLocatorClassLoader(ExampleAPI_01.class.getClassLoader()); Model model = FileManager.get().loadModel("data/data.ttl", null, "TURTLE"); StmtIterator iter = model.listStatements(); try { while ( iter.hasNext() ) { RDFNode o = stmt.getObject(); if ( s.isURIResource() ) { System.out.print("URI"); } else if ( s.isAnon() ) { System.out.print("blank"); if ( p.isURIResource() ) System.out.print(" URI ");
/** Identify the URL that is to be read in and translated to a vocabulary file, and load the source into the source model */ protected void selectInput() { if (!m_options.hasInputOption()) { usage(); } String input = SchemagenUtils.urlCheck( m_options.getInputOption().getURI() ); String syntax = m_options.getEncodingOption(); try { FileManager.get().readModel( m_source, input, syntax ); } catch (JenaException e) { abort( "Failed to read input source " + input, e ); } }
private void execPut(StoreConfig conf, String tag, List<String> positionalArgs) { if ( positionalArgs.size() == 0 ) throw new CmdException("No file to load") ; Model model = conf.getModel(tag) ; if ( model == null ) model = ModelFactory.createDefaultModel() ; for ( String filename : positionalArgs) FileManager.get().readModel(model, filename) ; conf.setModel(tag, model) ; }
@Test(expected = NotFoundException.class) public void testFileManagerNoFile2() { FileManager fileManager = new FileManager() ; fileManager.addLocatorFile() ; fileManager.readModel(ModelFactory.createDefaultModel(), filenameNonExistent); }
@Test(expected = NotFoundException.class) public void testFileManagerNoFile3() { FileManager fileManager = new AdapterFileManager(new StreamManager(), new org.apache.jena.riot.system.stream.LocationMapper()) ; fileManager.addLocatorFile() ; fileManager.readModel(ModelFactory.createDefaultModel(), filenameNonExistent); }