org.apache.jena.riot.SysRIOT Java Examples
The following examples show how to use
org.apache.jena.riot.SysRIOT.
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: ContextUtils.java From sparql-generate with Apache License 2.0 | 6 votes |
public static void loadGraph(Context context, String sourceURI, String baseURI, StreamRDF dest) { if(getDataset(context).containsNamedModel(sourceURI)) { final Model model = getDataset(context).getNamedModel(sourceURI); StreamRDFOps.sendGraphToStream(model.getGraph(), dest); return; } if(!isRootContext(context)) { Context parentContext = (Context) context.get(PARENT_CONTEXT); loadGraph(parentContext, sourceURI, baseURI, dest); return; } final SPARQLExtStreamManager sm = (SPARQLExtStreamManager) context.get(SysRIOT.sysStreamManager); final String acceptHeader = "text/turtle;q=1.0,application/rdf+xml;q=0.9,*/*;q=0.1"; final LookUpRequest request = new LookUpRequest(sourceURI, acceptHeader); try (TypedInputStream tin = sm.open(request);) { if(tin == null) { LOG.warn("Could not locate graph " + request); return; } Lang lang = RDFLanguages.contentTypeToLang(tin.getMediaType()); RDFParser.create().source(tin).base(baseURI).context(context).lang(lang).parse(dest); } catch (RiotException ex) { LOG.warn("Error while loading graph " + sourceURI, ex); } }
Example #2
Source File: RdflintParserRdfxml.java From rdflint with MIT License | 5 votes |
/** * Sort out the base URI for RDF/XML parsing. */ private static String baseURI_RDFXML( // SUPPRESS CHECKSTYLE AbbreviationAsWordInName String baseIRI) { // SUPPRESS CHECKSTYLE AbbreviationAsWordInName if (baseIRI == null) { return SysRIOT.chooseBaseIRI(); } else { // This normalizes the URI. return SysRIOT.chooseBaseIRI(baseIRI); } }
Example #3
Source File: SourcePlan.java From sparql-generate with Apache License 2.0 | 5 votes |
final protected Binding exec( final Binding binding, final Context context) { LOG.debug("Start " + this); Objects.nonNull(binding); // generate the source URI. final String sourceUri = getActualSource(binding); final String acceptHeader = getAcceptHeader(binding); LOG.trace("... resolved to SOURCE <" + sourceUri + "> ACCEPT " + acceptHeader + " AS " + var); final LookUpRequest request = new LookUpRequest(sourceUri, acceptHeader); final SPARQLExtStreamManager sm = (SPARQLExtStreamManager) context.get(SysRIOT.sysStreamManager); Objects.requireNonNull(sm); final TypedInputStream stream = sm.open(request); if (stream == null) { LOG.info("Exec SOURCE <" + sourceUri + "> ACCEPT " + acceptHeader + " AS " + var + " returned nothing."); return BindingFactory.binding(binding); } try (InputStream in = stream.getInputStream()) { final String literal = IOUtils.toString(in, "UTF-8"); final RDFDatatype dt; if (stream.getMediaType() != null && stream.getMediaType().getContentType() != null) { dt = tm.getSafeTypeByName("http://www.iana.org/assignments/media-types/" + stream.getMediaType().getContentType()); } else { dt = tm.getSafeTypeByName("http://www.w3.org/2001/XMLSchema#string"); } final Node n = NodeFactory.createLiteral(literal, dt); LOG.debug("Exec " + this + " returned. " + "Enable TRACE level for more."); if (LOG.isTraceEnabled()) { LOG.trace("Exec " + this + " returned\n" + LogUtils.compress(n)); } return BindingFactory.binding(binding, var, n); } catch (IOException | DatatypeFormatException ex) { LOG.warn("Exception while looking up " + sourceUri + ":", ex); return BindingFactory.binding(binding); } }
Example #4
Source File: ContextUtils.java From sparql-generate with Apache License 2.0 | 5 votes |
/** * * @param ctx * the context to fork */ private Forker(Context ctx, boolean isRoot) { context = new Context(ctx); context.set(SysRIOT.sysStreamManager, context.get(SysRIOT.sysStreamManager, SPARQLExtStreamManager.makeStreamManager())); context.set(BASE, context.get(BASE)); context.set(PREFIX_MANAGER, context.get(PREFIX_MANAGER, PrefixMapping.Standard)); context.set(SIZE, 0); if(!isRoot) { context.set(PARENT_CONTEXT, ctx); } }
Example #5
Source File: ContextUtils.java From sparql-generate with Apache License 2.0 | 5 votes |
private Builder() { this.context = new Context(ARQ.getContext()); this.commons = new Commons(); // update functionregistry FunctionRegistry registry = (FunctionRegistry) context.get(ARQConstants.registryFunctions); SPARQLExtFunctionRegistry newRegistry = new SPARQLExtFunctionRegistry(registry, context); context.set(ARQConstants.registryFunctions, newRegistry); // update iteratorregistry IteratorFunctionRegistry iteratorRegistry = (IteratorFunctionRegistry) context .get(SPARQLExt.REGISTRY_ITERATORS); IteratorFunctionRegistry newIteratorRegistry = new IteratorFunctionRegistry(iteratorRegistry, context); context.set(SPARQLExt.REGISTRY_ITERATORS, newIteratorRegistry); // default streammanager context.set(SysRIOT.sysStreamManager, SPARQLExtStreamManager.makeStreamManager()); // set variable parts context.set(DATASET, DatasetFactory.create()); // default prefix manager context.set(PREFIX_MANAGER, PrefixMapping.Standard); // default number of results and blank nodes context.set(SIZE, 0); // context.set(LIST_NODES, new HashMap<>()); context.set(COMMONS, commons); }
Example #6
Source File: RDFPatchReaderText.java From rdf-delta with Apache License 2.0 | 4 votes |
private static PatchException exception(Tokenizer tokenizer, String fmt, Object... args) { String msg = String.format(fmt, args); if ( tokenizer != null ) msg = SysRIOT.fmtMessage(msg, tokenizer.getLine(), tokenizer.getColumn()); return new PatchException(msg); }
Example #7
Source File: RDFPatchReaderText.java From rdf-delta with Apache License 2.0 | 4 votes |
private static PatchException exception(Token token, String fmt, Object... args) { String msg = String.format(fmt, args); if ( token != null ) msg = SysRIOT.fmtMessage(msg, token.getLine(), token.getColumn()); return new PatchException(msg); }
Example #8
Source File: ContextUtils.java From sparql-generate with Apache License 2.0 | 4 votes |
public static TypedInputStream openStream(Context context, String sourceUri, String acceptHeader) { final LookUpRequest request = new LookUpRequest(sourceUri, acceptHeader); final SPARQLExtStreamManager sm = (SPARQLExtStreamManager) context.get(SysRIOT.sysStreamManager); Objects.requireNonNull(sm); return sm.open(request); }
Example #9
Source File: ContextUtils.java From sparql-generate with Apache License 2.0 | 4 votes |
public Builder setStreamManager(SPARQLExtStreamManager sm) { context.set(SysRIOT.sysStreamManager, sm); return this; }