public RDFReaderRIOT(Lang hintlang) { this.hintlang = hintlang ; this.basename = (hintlang==null) ? "org.apache.jena.riot.reader.generic" : "org.apache.jena.riot.reader." + hintlang.getLabel().toLowerCase(Locale.ROOT) ; }
public RDFReaderRIOT(Lang hintlang) { this.hintlang = hintlang ; this.basename = (hintlang==null) ? "org.apache.jena.riot.reader.generic" : "org.apache.jena.riot.reader." + hintlang.getLabel().toLowerCase(Locale.ROOT) ; }
public static boolean isRegistered(Lang lang) { if ( lang == null ) throw new IllegalArgumentException("null for language") ; String label = canonicalKey(lang.getLabel()) ; Lang lang2 = mapLabelToLang.get(label) ; if ( lang2 == null ) return false ; checkRegistration(lang) ; return true ; }
private void loadTemplateModel() { logger.info("loading need templateModel model from resource " + this.template); Lang lang = RDFLanguages.filenameToLang(this.template.getFilename()); try { this.templateModel = RdfUtils.readRdfSnippet(template.getInputStream(), Lang.TTL.getLabel()); } catch (IOException e) { throw new IllegalArgumentException("Could not read data from resource " + template); } if (this.templateModel == null){ logger.warn("reading RDF data from template {} resulted in a null or empty model. Wrapped models will not be modified", this.template); } }
@Override protected RecordReader<LongWritable, TripleWritable> selectRecordReader(Lang lang) throws IOException { if (!RDFLanguages.isTriples(lang)) throw new IOException( lang.getLabel() + " is not a RDF triples format, perhaps you wanted QuadsInputFormat or TriplesOrQuadsInputFormat instead?"); // This will throw an appropriate error if the language does not support // triples return HadoopRdfIORegistry.createTripleReader(lang); }
@Override protected RecordReader<LongWritable, QuadWritable> selectRecordReader(Lang lang) throws IOException { if (!RDFLanguages.isQuads(lang)) throw new IOException( lang.getLabel() + " is not a RDF quads format, perhaps you wanted TriplesInputFormat or TriplesOrQuadsInputFormat instead?"); // This will throw an appropriate error if the language does not support // triples return HadoopRdfIORegistry.createQuadReader(lang); }
public static boolean isRegistered(Lang lang) { if ( lang == null ) throw new IllegalArgumentException("null for language") ; String label = canonicalKey(lang.getLabel()) ; Lang lang2 = mapLabelToLang.get(label) ; if ( lang2 == null ) return false ; checkRegistration(lang) ; return true ; }
@Override protected RecordReader<LongWritable, TripleWritable> selectRecordReader(Lang lang) throws IOException { if (!RDFLanguages.isTriples(lang)) throw new IOException( lang.getLabel() + " is not a RDF triples format, perhaps you wanted QuadsInputFormat or TriplesOrQuadsInputFormat instead?"); // This will throw an appropriate error if the language does not support // triples return HadoopRdfIORegistry.createTripleReader(lang); }
@Override protected RecordReader<LongWritable, QuadWritable> selectRecordReader(Lang lang) throws IOException { if (!RDFLanguages.isQuads(lang)) throw new IOException( lang.getLabel() + " is not a RDF quads format, perhaps you wanted TriplesInputFormat or TriplesOrQuadsInputFormat instead?"); // This will throw an appropriate error if the language does not support // triples return HadoopRdfIORegistry.createQuadReader(lang); }
private static void printRegistered(PrintStream out) { out.println("Streaming languages:") ; Set<Lang> seen = new HashSet<>() ; for ( RDFFormat fmt : StreamRDFWriter.registered()) { Lang lang = fmt.getLang() ; if ( hiddenLanguages.contains(lang)) continue ; if ( seen.contains(lang) ) continue ; seen.add(lang) ; out.println(" "+lang.getLabel()) ; } System.err.println("Non-streaming languages:") ; for ( RDFFormat fmt : RDFWriterRegistry.registered() ) { Lang lang = fmt.getLang() ; if ( hiddenLanguages.contains(lang)) continue ; if ( seen.contains(lang) ) continue ; seen.add(lang) ; out.println(" "+lang.getLabel()) ; } }
private static void printRegistered(PrintStream out) { out.println("Streaming languages:") ; Set<Lang> seen = new HashSet<>() ; for ( RDFFormat fmt : StreamRDFWriter.registered()) { Lang lang = fmt.getLang() ; if ( hiddenLanguages.contains(lang)) continue ; if ( seen.contains(lang) ) continue ; seen.add(lang) ; out.println(" "+lang.getLabel()) ; } System.err.println("Non-streaming languages:") ; for ( RDFFormat fmt : RDFWriterRegistry.registered() ) { Lang lang = fmt.getLang() ; if ( hiddenLanguages.contains(lang)) continue ; if ( seen.contains(lang) ) continue ; seen.add(lang) ; out.println(" "+lang.getLabel()) ; } }
/** Remove a registration of a language - this also removes all recorded mapping * of content types and file extensions. */ public static void unregister(Lang lang) { if ( lang == null ) throw new IllegalArgumentException("null for language") ; checkRegistration(lang) ; mapLabelToLang.remove(canonicalKey(lang.getLabel())) ; mapContentTypeToLang.remove(canonicalKey(lang.getContentType().getContentType())) ; for ( String ct : lang.getAltContentTypes() ) mapContentTypeToLang.remove(canonicalKey(ct)) ; for ( String ext : lang.getFileExtensions() ) mapFileExtToLang.remove(canonicalKey(ext)) ; }
/** Remove a regsitration of a language - this also removes all recorded mapping * of content types and file extensions. */ public static void unregister(Lang lang) { if ( lang == null ) throw new IllegalArgumentException("null for language") ; checkRegistration(lang) ; mapLabelToLang.remove(canonicalKey(lang.getLabel())) ; mapContentTypeToLang.remove(canonicalKey(lang.getContentType().getContentType())) ; for ( String ct : lang.getAltContentTypes() ) mapContentTypeToLang.remove(canonicalKey(ct)) ; for ( String ext : lang.getFileExtensions() ) mapFileExtToLang.remove(canonicalKey(ext)) ; }
@Override protected RecordReader<LongWritable, QuadWritable> selectRecordReader(Lang lang) throws IOException { if (!RDFLanguages.isQuads(lang) && !RDFLanguages.isTriples(lang)) throw new IOException(lang.getLabel() + " is not a RDF triples/quads format"); if (HadoopRdfIORegistry.hasQuadReader(lang)) { // Supports quads directly return HadoopRdfIORegistry.createQuadReader(lang); } else { // Try to create a triples reader and wrap upwards into quads // This will throw an error if a triple reader is not available return new TriplesToQuadsReader(HadoopRdfIORegistry.createTripleReader(lang)); } }
/** Register a language. * To create a {@link Lang} object use {@link LangBuilder}. * See also * {@link RDFParserRegistry#registerLang} * for registering a language and it's RDF parser factory. * * @see RDFParserRegistry */ public static void register(Lang lang) { if ( lang == null ) throw new IllegalArgumentException("null for language") ; checkRegistration(lang) ; mapLabelToLang.put(canonicalKey(lang.getLabel()), lang) ; for (String altName : lang.getAltNames() ) mapLabelToLang.put(canonicalKey(altName), lang) ; mapContentTypeToLang.put(canonicalKey(lang.getContentType().getContentType()), lang) ; for ( String ct : lang.getAltContentTypes() ) mapContentTypeToLang.put(canonicalKey(ct), lang) ; for ( String ext : lang.getFileExtensions() ) { if ( ext.startsWith(".") ) ext = ext.substring(1) ; mapFileExtToLang.put(canonicalKey(ext), lang) ; } }
private static void checkRegistration(Lang lang) { if ( lang == null ) return ; String label = canonicalKey(lang.getLabel()) ; Lang lang2 = mapLabelToLang.get(label) ; if ( lang2 == null ) return ; if ( lang.equals(lang2) ) return ; // Content type. if ( mapContentTypeToLang.containsKey(lang.getContentType().getContentType())) { String k = lang.getContentType().getContentType() ; error("Language overlap: " +lang+" and "+mapContentTypeToLang.get(k)+" on content type "+k) ; } for (String altName : lang.getAltNames() ) if ( mapLabelToLang.containsKey(altName) ) error("Language overlap: " +lang+" and "+mapLabelToLang.get(altName)+" on name "+altName) ; for (String ct : lang.getAltContentTypes() ) if ( mapContentTypeToLang.containsKey(ct) ) error("Language overlap: " +lang+" and "+mapContentTypeToLang.get(ct)+" on content type "+ct) ; for (String ext : lang.getFileExtensions() ) if ( mapFileExtToLang.containsKey(ext) ) error("Language overlap: " +lang+" and "+mapFileExtToLang.get(ext)+" on file extension type "+ext) ; }
@Override protected RecordReader<LongWritable, QuadWritable> selectRecordReader(Lang lang) throws IOException { if (!RDFLanguages.isQuads(lang) && !RDFLanguages.isTriples(lang)) throw new IOException(lang.getLabel() + " is not a RDF triples/quads format"); if (HadoopRdfIORegistry.hasQuadReader(lang)) { // Supports quads directly return HadoopRdfIORegistry.createQuadReader(lang); } else { // Try to create a triples reader and wrap upwards into quads // This will throw an error if a triple reader is not available return new TriplesToQuadsReader(HadoopRdfIORegistry.createTripleReader(lang)); } }
@Test public void treeGenerationTest() throws Exception { QueryTreeFactory factory = new QueryTreeFactoryBase(); OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); model.read(new FileInputStream("../examples/carcinogenesis/carcinogenesis.owl"), null, Lang.RDFXML.getLabel()); ExtendedIterator<Individual> it = model.listIndividuals(); while(it.hasNext()) { Individual ind = it.next(); // RDFResourceTree tree = factory.getQueryTree(ind.getURI(), model); // // String treeString = tree.getStringRepresentation(Rendering.BRACES); } }