本文整理了Java中org.eclipse.rdf4j.rio.Rio.parse
方法的一些代码示例,展示了Rio.parse
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Rio.parse
方法的具体详情如下:
包路径:org.eclipse.rdf4j.rio.Rio
类名称:Rio
方法名:parse
[英]Adds RDF data from an InputStream to a Model, optionally to one or more named contexts.
[中]将输入流中的RDF数据添加到模型中,可以选择添加到一个或多个命名上下文中。
代码示例来源:origin: carml/carml
public static Model parse(InputStream inputStream, RDFFormat format) {
try (InputStream is = inputStream) {
return Rio.parse(is, "http://none.com/", format);
}
catch (IOException e) {
throw new RuntimeException("failed to parse input stream [" + inputStream + "] as [" + format + "]", e);
}
}
}
代码示例来源:origin: carml/carml
public static Model parse(String resource, RDFFormat format) {
try (InputStream input = IoUtils.class.getClassLoader().getResourceAsStream(resource)) {
return Rio.parse(input, "http://none.com/", format);
}
catch (IOException e) {
throw new RuntimeException("failed to parse resource [" + resource + "] as [" + format + "]", e);
}
}
代码示例来源:origin: HuygensING/timbuctoo
public static void main(String[] args) throws Exception {
InputStream resourceAsStream = new FileInputStream(args[0]);
Model model = Rio.parse(resourceAsStream, "", RDFFormat.NQUADS);
Rio.write(model, new FileOutputStream(args[1]), RDFFormat.TURTLE);
}
}
代码示例来源:origin: org.streampipes/streampipes-measurement-units
protected static void read(Model repos, String ontology)
throws RDFParseException, IOException {
String filename = "onto/" + ontology;
InputStream ins = OntoReader.class.getClassLoader()
.getResourceAsStream(filename);
if(filename.endsWith(".ttl")) {
repos.addAll(Rio.parse(ins, "",RDFFormat.TURTLE));
} else {
repos.addAll(Rio.parse(ins, "",RDFFormat.RDFXML));
}
}
}
代码示例来源:origin: streampipes/streampipes-ce
protected static void read(Model repos, String ontology)
throws RDFParseException, IOException {
String filename = "onto/" + ontology;
InputStream ins = OntoReader.class.getClassLoader()
.getResourceAsStream(filename);
if(filename.endsWith(".ttl")) {
repos.addAll(Rio.parse(ins, "",RDFFormat.TURTLE));
} else {
repos.addAll(Rio.parse(ins, "",RDFFormat.RDFXML));
}
}
}
代码示例来源:origin: HuygensING/timbuctoo
public RdfDescriptionSaver(File descriptionFile, String baseUri, ImportStatus importStatus) throws IOException,
ParserConfigurationException, SAXException {
this.baseUri = baseUri;
descriptionFile.createNewFile();
this.descriptionFile = descriptionFile;
inputStream = new FileInputStream(descriptionFile);
if (inputStream.available() > 0) {
model = Rio.parse(inputStream, baseUri, RDFFormat.RDFXML);
} else {
model = new TreeModel();
}
this.importStatus = importStatus;
}
代码示例来源:origin: eclipse/rdf4j
private RepositoryConfig getSystemConfig() {
URL ttl = this.getClass().getClassLoader().getResource(CONFIG_SYSTEM_TTL);
if (ttl == null) {
return null;
}
try (InputStream in = ttl.openStream()) {
Model model = Rio.parse(in, ttl.toString(), RDFFormat.TURTLE);
return RepositoryConfigUtil.getRepositoryConfig(model, ID);
}
catch (IOException e) {
throw new RepositoryConfigException(e);
}
}
代码示例来源:origin: org.eclipse.rdf4j/rdf4j-client
private RepositoryConfig getSystemConfig() {
URL ttl = this.getClass().getClassLoader().getResource(CONFIG_SYSTEM_TTL);
if (ttl == null) {
return null;
}
try (InputStream in = ttl.openStream()) {
Model model = Rio.parse(in, ttl.toString(), RDFFormat.TURTLE);
return RepositoryConfigUtil.getRepositoryConfig(model, ID);
}
catch (IOException e) {
throw new RepositoryConfigException(e);
}
}
代码示例来源:origin: org.streampipes/streampipes-pipeline-management
public static Model extractStatements(String graphData) throws SepaParseException
{
try {
return Rio.parse(getGraphDataAsStream(graphData), "", RDFFormat.JSONLD);
} catch (RDFParseException | UnsupportedRDFormatException | IOException e) {
throw new SepaParseException();
}
}
代码示例来源:origin: streampipes/streampipes-ce
@Override
public <T> T fromJsonLd(String json, Class<T> destination) throws RDFParseException, UnsupportedRDFormatException, IOException, RepositoryException {
InputStream stream = new ByteArrayInputStream(
json.getBytes(StandardCharsets.UTF_8));
Model statements;
statements = Rio.parse(stream, "", RDFFormat.JSONLD);
return makeRdfMapper()
.readValue(statements, destination, getResource(statements));
}
代码示例来源:origin: streampipes/streampipes-ce
public static Model extractStatements(String graphData) throws SepaParseException
{
try {
return Rio.parse(getGraphDataAsStream(graphData), "", RDFFormat.JSONLD);
} catch (RDFParseException | UnsupportedRDFormatException | IOException e) {
throw new SepaParseException();
}
}
代码示例来源:origin: HuygensING/timbuctoo
private void createDescriptionNode(Description description, RDFFormat parseFormat, Interpreter interpreter) {
try {
Model model = Rio.parse(IOUtils.toInputStream(description.getRawContent()), "", parseFormat);
ByteArrayOutputStream out = new ByteArrayOutputStream();
Rio.write(model, out, RDFFormat.JSONLD);
ObjectMapper mapper = new ObjectMapper();
content = mapper.readTree(out.toString());
} catch (Exception e) { // catch all e.g. org.xml.sax.SAXParseException
rawContent = description.getRawContent();
error = new ErrorView(e, interpreter);
}
}
}
代码示例来源:origin: org.eclipse.rdf4j/rdf4j-client
File configFile = new File(dataDir, CFG_FILE);
try (InputStream input = new FileInputStream(configFile)) {
Model model = Rio.parse(input, configFile.toURI().toString(), CONFIG_FORMAT);
Set<String> repositoryIDs = RepositoryConfigUtil.getRepositoryIDs(model);
if (repositoryIDs.isEmpty()) {
代码示例来源:origin: org.eclipse.rdf4j/rdf4j-client
/**
* Adds RDF data from an {@link InputStream} to a {@link Model}, optionally to one or more named contexts.
*
* @param in
* An InputStream from which RDF data can be read.
* @param baseURI
* The base URI to resolve any relative URIs that are in the data against.
* @param dataFormat
* The serialization format of the data.
* @param contexts
* The contexts to add the data to. If one or more contexts are supplied the method ignores
* contextual information in the actual data. If no contexts are supplied the contextual
* information in the input stream is used, if no context information is available the data is
* added without any context.
* @return A {@link Model} containing the parsed statements.
* @throws IOException
* If an I/O error occurred while reading from the input stream.
* @throws UnsupportedRDFormatException
* If no {@link RDFParser} is available for the specified RDF format.
* @throws RDFParseException
* If an error was found while parsing the RDF data.
*/
public static Model parse(InputStream in, String baseURI, RDFFormat dataFormat, Resource... contexts)
throws IOException, RDFParseException, UnsupportedRDFormatException
{
return parse(in, baseURI, dataFormat, new ParserConfig(), SimpleValueFactory.getInstance(),
new ParseErrorLogger(), contexts);
}
代码示例来源:origin: org.eclipse.rdf4j/rdf4j-client
/**
* Adds RDF data from a {@link Reader} to a {@link Model}, optionally to one or more named contexts.
* <b>Note: using a Reader to upload byte-based data means that you have to be careful not to destroy the
* data's character encoding by enforcing a default character encoding upon the bytes. If possible, adding
* such data using an InputStream is to be preferred.</b>
*
* @param reader
* A Reader from which RDF data can be read.
* @param baseURI
* The base URI to resolve any relative URIs that are in the data against.
* @param dataFormat
* The serialization format of the data.
* @param contexts
* The contexts to add the data to. If one or more contexts are specified the data is added to
* these contexts, ignoring any context information in the data itself.
* @return A {@link Model} containing the parsed statements.
* @throws IOException
* If an I/O error occurred while reading from the reader.
* @throws UnsupportedRDFormatException
* If no {@link RDFParser} is available for the specified RDF format.
* @throws RDFParseException
* If an error was found while parsing the RDF data.
*/
public static Model parse(Reader reader, String baseURI, RDFFormat dataFormat, Resource... contexts)
throws IOException, RDFParseException, UnsupportedRDFormatException
{
return parse(reader, baseURI, dataFormat, new ParserConfig(), SimpleValueFactory.getInstance(),
new ParseErrorLogger(), contexts);
}
代码示例来源:origin: eclipse/rdf4j
/**
* Adds RDF data from a {@link Reader} to a {@link Model}, optionally to one or more named contexts.
* <b>Note: using a Reader to upload byte-based data means that you have to be careful not to destroy the
* data's character encoding by enforcing a default character encoding upon the bytes. If possible, adding
* such data using an InputStream is to be preferred.</b>
*
* @param reader
* A Reader from which RDF data can be read.
* @param baseURI
* The base URI to resolve any relative URIs that are in the data against.
* @param dataFormat
* The serialization format of the data.
* @param contexts
* The contexts to add the data to. If one or more contexts are specified the data is added to
* these contexts, ignoring any context information in the data itself.
* @return A {@link Model} containing the parsed statements.
* @throws IOException
* If an I/O error occurred while reading from the reader.
* @throws UnsupportedRDFormatException
* If no {@link RDFParser} is available for the specified RDF format.
* @throws RDFParseException
* If an error was found while parsing the RDF data.
*/
public static Model parse(Reader reader, String baseURI, RDFFormat dataFormat, Resource... contexts)
throws IOException, RDFParseException, UnsupportedRDFormatException
{
return parse(reader, baseURI, dataFormat, new ParserConfig(), SimpleValueFactory.getInstance(),
new ParseErrorLogger(), contexts);
}
代码示例来源:origin: org.eclipse.rdf4j/rdf4j-rio-api
/**
* Adds RDF data from an {@link InputStream} to a {@link Model}, optionally to one or more named contexts.
*
* @param in
* An InputStream from which RDF data can be read.
* @param baseURI
* The base URI to resolve any relative URIs that are in the data against.
* @param dataFormat
* The serialization format of the data.
* @param contexts
* The contexts to add the data to. If one or more contexts are supplied the method ignores
* contextual information in the actual data. If no contexts are supplied the contextual
* information in the input stream is used, if no context information is available the data is
* added without any context.
* @return A {@link Model} containing the parsed statements.
* @throws IOException
* If an I/O error occurred while reading from the input stream.
* @throws UnsupportedRDFormatException
* If no {@link RDFParser} is available for the specified RDF format.
* @throws RDFParseException
* If an error was found while parsing the RDF data.
*/
public static Model parse(InputStream in, String baseURI, RDFFormat dataFormat, Resource... contexts)
throws IOException, RDFParseException, UnsupportedRDFormatException
{
return parse(in, baseURI, dataFormat, new ParserConfig(), SimpleValueFactory.getInstance(),
new ParseErrorLogger(), contexts);
}
代码示例来源:origin: eclipse/rdf4j
/**
* Adds RDF data from an {@link InputStream} to a {@link Model}, optionally to one or more named contexts.
*
* @param in
* An InputStream from which RDF data can be read.
* @param baseURI
* The base URI to resolve any relative URIs that are in the data against.
* @param dataFormat
* The serialization format of the data.
* @param contexts
* The contexts to add the data to. If one or more contexts are supplied the method ignores
* contextual information in the actual data. If no contexts are supplied the contextual
* information in the input stream is used, if no context information is available the data is
* added without any context.
* @return A {@link Model} containing the parsed statements.
* @throws IOException
* If an I/O error occurred while reading from the input stream.
* @throws UnsupportedRDFormatException
* If no {@link RDFParser} is available for the specified RDF format.
* @throws RDFParseException
* If an error was found while parsing the RDF data.
*/
public static Model parse(InputStream in, String baseURI, RDFFormat dataFormat, Resource... contexts)
throws IOException, RDFParseException, UnsupportedRDFormatException
{
return parse(in, baseURI, dataFormat, new ParserConfig(), SimpleValueFactory.getInstance(),
new ParseErrorLogger(), contexts);
}
代码示例来源:origin: org.eclipse.rdf4j/rdf4j-rio-api
/**
* Adds RDF data from a {@link Reader} to a {@link Model}, optionally to one or more named contexts.
* <b>Note: using a Reader to upload byte-based data means that you have to be careful not to destroy the
* data's character encoding by enforcing a default character encoding upon the bytes. If possible, adding
* such data using an InputStream is to be preferred.</b>
*
* @param reader
* A Reader from which RDF data can be read.
* @param baseURI
* The base URI to resolve any relative URIs that are in the data against.
* @param dataFormat
* The serialization format of the data.
* @param contexts
* The contexts to add the data to. If one or more contexts are specified the data is added to
* these contexts, ignoring any context information in the data itself.
* @return A {@link Model} containing the parsed statements.
* @throws IOException
* If an I/O error occurred while reading from the reader.
* @throws UnsupportedRDFormatException
* If no {@link RDFParser} is available for the specified RDF format.
* @throws RDFParseException
* If an error was found while parsing the RDF data.
*/
public static Model parse(Reader reader, String baseURI, RDFFormat dataFormat, Resource... contexts)
throws IOException, RDFParseException, UnsupportedRDFormatException
{
return parse(reader, baseURI, dataFormat, new ParserConfig(), SimpleValueFactory.getInstance(),
new ParseErrorLogger(), contexts);
}
代码示例来源:origin: franzinc/agraph-java-client
public static void assertRDFFilesIsomorphic(File expected, File actual, RDFFormat format) throws Exception {
final RDFFormat expectedFormat;
final RDFFormat actualFormat;
if (format == null) {
final RDFParserRegistry registry = RDFParserRegistry.getInstance();
expectedFormat =
registry.getFileFormatForFileName(expected.getName()).orElse(null);
actualFormat =
registry.getFileFormatForFileName(actual.getName()).orElse(null);
assertNotNull("Can't guess the expected file format", expectedFormat);
assertNotNull("Can't guess the actual file format", actualFormat);
} else {
expectedFormat = format;
actualFormat = format;
}
final Model expectedModel;
final Model actualModel;
try (final InputStream expectedStream = new FileInputStream(expected);
final InputStream actualStream = new FileInputStream(actual)) {
expectedModel = Rio.parse(expectedStream, "base://", expectedFormat);
actualModel = Rio.parse(actualStream, "base://", actualFormat);
}
assertTrue("RDF files are not isomorphic",
Models.isomorphic(expectedModel, actualModel));
}
内容来源于网络,如有侵权,请联系作者删除!