本文整理汇总了Java中org.eclipse.rdf4j.rio.Rio.parse方法的典型用法代码示例。如果您正苦于以下问题:Java Rio.parse方法的具体用法?Java Rio.parse怎么用?Java Rio.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.rdf4j.rio.Rio
的用法示例。
在下文中一共展示了Rio.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: RDF4JSchemaGeneratorCore
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
public RDF4JSchemaGeneratorCore(String filename, RDFFormat format) throws IOException, RDFParseException {
Path file = Paths.get(filename);
if (!Files.exists(file)) throw new FileNotFoundException(filename);
if (format == null) {
format = Rio.getParserFormatForFileName(filename).orElse(null);
log.trace("detected input format from filename {}: {}", filename, format);
}
try (final InputStream inputStream = Files.newInputStream(file)) {
log.trace("Loading input file");
model = Rio.parse(inputStream, "", format);
}
//import
Set<Resource> owlOntologies = model.filter(null, RDF.TYPE, OWL.ONTOLOGY).subjects();
if (!owlOntologies.isEmpty()) {
setPrefix(owlOntologies.iterator().next().stringValue());
}
}
示例2: mergeResourceWithPrefixes
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
public static Model mergeResourceWithPrefixes(InputStream inputStreamPrefixes,
InputStream inputStreamData) throws IOException {
final Resource mergedDataResource =
new InputStreamResource(new SequenceInputStream(inputStreamPrefixes, inputStreamData));
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
RDFWriter turtleWriter = Rio.createWriter(RDFFormat.TURTLE, byteArrayOutputStream);
RDFParser trigParser = Rio.createParser(RDFFormat.TRIG);
trigParser.setRDFHandler(turtleWriter);
trigParser.parse(mergedDataResource.getInputStream(), "");
Model result = Rio.parse(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()), "",
RDFFormat.TURTLE);
byteArrayOutputStream.close();
inputStreamData.close();
return result;
}
示例3: getFileContentAsStatements
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
/**
* Method to read the content of a turtle file
*
* @param fileName Turtle file name
* @param baseURI
* @return File content as a string
*/
public static List<Statement> getFileContentAsStatements(String fileName,
String baseURI) {
List<Statement> statements = null;
try {
String content = getFileContentAsString(fileName);
StringReader reader = new StringReader(content);
Model model;
model = Rio.parse(reader, baseURI, FILE_FORMAT);
Iterator<Statement> it = model.iterator();
statements = Lists.newArrayList(it);
} catch (IOException | RDFParseException |
UnsupportedRDFormatException ex) {
LOGGER.error("Error getting turle file",ex);
}
return statements;
}
示例4: getStatements
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
/**
* Create List<Statements> from rdf string
*
* @param rdfString RDF string
* @param baseUri Base uri
* @param format RDF format
* @return
* @throws MetadataParserException
*/
public static List<Statement> getStatements(String rdfString, IRI baseUri,
RDFFormat format) throws MetadataParserException {
String uri;
if (baseUri == null) {
uri = "http://example.com/dummyResource";
} else {
uri = baseUri.stringValue();
}
try {
Model model = Rio.parse(new StringReader(rdfString), uri , format);
Iterator<Statement> it = model.iterator();
List<Statement> statements = ImmutableList.copyOf(it);
return statements;
} catch (RDFParseException | UnsupportedRDFormatException |
IOException ex) {
String errMsg = "Error reading dataset metadata content"
+ ex.getMessage();
LOGGER.error(errMsg);
throw (new MetadataParserException(errMsg));
}
}
示例5: getFileContentAsStatements
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
/**
* Method to read the content of a turtle file
*
* @param fileName Turtle file name
* @param baseURI RDF content's base uri
* @return File content as a string
*/
public static List<Statement> getFileContentAsStatements(String fileName,
String baseURI) {
List<Statement> statements = null;
try {
String content = getFileContentAsString(fileName);
StringReader reader = new StringReader(content);
Model model;
model = Rio.parse(reader, baseURI, FILE_FORMAT);
Iterator<Statement> it = model.iterator();
statements = Lists.newArrayList(it);
} catch (IOException | RDFParseException |
UnsupportedRDFormatException ex) {
LOGGER.error("Error getting turle file",ex);
}
return statements;
}
示例6: parseQueryLog
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
@Override
public void parseQueryLog(InputStream in) throws IOException, QueryLogException {
if (handler == null)
throw new QueryLogException("No query log handler defined");
try {
model = Rio.parse(in, "", RDFFormat.NTRIPLES);
} catch (Exception e) {
throw new QueryLogException(e);
}
Model queryRecords = model.filter(null, RDF.TYPE, QFR.QUERYRECORD);
for (Resource qr : queryRecords.subjects()) {
QueryLogRecord record = parseQueryRecord(qr,model);
handler.handleQueryRecord(record);
}
}
示例7: parse
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
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);
}
}
示例8: get_GetGraphInTurtle_ThroughLdApi
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
@Test
public void get_GetGraphInTurtle_ThroughLdApi() throws IOException {
// Act
String response = getResultWithMediaType(MediaTypes.TURTLE_TYPE);
// Assert
Model model = Rio.parse(new StringReader(response), "", RDFFormat.TURTLE);
assertModel(model);
}
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:10,代码来源:GraphContentNegotiationIntegrationTest.java
示例9: get_GetGraphInTrig_ThroughLdApi
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
@Test
public void get_GetGraphInTrig_ThroughLdApi() throws IOException {
// Act
String response = getResultWithMediaType(MediaTypes.TRIG_TYPE);
// Assert
Model model = Rio.parse(new StringReader(response), "", RDFFormat.TRIG);
assertModel(model);
}
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:10,代码来源:GraphContentNegotiationIntegrationTest.java
示例10: get_GetGraphInLdJson_ThroughLdApi
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
@Test
public void get_GetGraphInLdJson_ThroughLdApi() throws IOException {
// Act
String response = getResultWithMediaType(MediaTypes.LDJSON_TYPE);
// Assert
Model model = Rio.parse(new StringReader(response), "", RDFFormat.JSONLD);
assertModel(model);
}
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:10,代码来源:GraphContentNegotiationIntegrationTest.java
示例11: get_GetGraphInPlainJson_ThroughLdApi
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
@Test
public void get_GetGraphInPlainJson_ThroughLdApi() throws IOException {
// Act
String response = getResultWithMediaType(MediaType.APPLICATION_JSON_TYPE);
// Assert
Model model = Rio.parse(new StringReader(response), "", RDFFormat.JSONLD);
assertModel(model);
}
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:10,代码来源:GraphContentNegotiationIntegrationTest.java
示例12: getModel
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
public static Model getModel(InputStream inputStream) throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
RDFWriter turtleWriter = Rio.createWriter(RDFFormat.TURTLE, byteArrayOutputStream);
RDFParser trigParser = Rio.createParser(RDFFormat.TRIG);
trigParser.setRDFHandler(turtleWriter);
trigParser.parse(inputStream, "");
org.eclipse.rdf4j.model.Model result = Rio.parse(
new ByteArrayInputStream(byteArrayOutputStream.toByteArray()), "", RDFFormat.TURTLE);
byteArrayOutputStream.close();
return result;
}
示例13: rdf4jParse
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
private void rdf4jParse(final URL url) throws Exception {
Model model;
try (InputStream in = url.openStream()) {
model = Rio.parse(in, url.toExternalForm(), RDFFormat.JSONLD);
}
try (final RDF4JGraph graph = new RDF4J().asGraph(model)) {
checkGraph(graph);
}
}
示例14: createDescriptionNode
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
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);
}
}
示例15: testStatsTarget
import org.eclipse.rdf4j.rio.Rio; //导入方法依赖的package包/类
@Test
public void testStatsTarget() throws Exception {
HBaseSail sail = new HBaseSail(HBaseServerTestInstance.getInstanceConfig(), "statsTable", true, -1, true, 0, null, null);
sail.initialize();
ValueFactory vf = SimpleValueFactory.getInstance();
for (int i = 0; i < 1000; i++) {
sail.addStatement((i % 13 == 0) ? vf.createBNode("id_"+i % 150) : vf.createIRI("http://whatever/subj" + (i % 150)), vf.createIRI("http://whatever/pred" + (i % 11)), (i % 9 == 0) ? vf.createBNode("id_"+i % 100) : vf.createLiteral("whatever value " + i), i < 200 ? null : vf.createIRI("http://whatever/graph" + (i % 2)));
sail.addStatement((i % 13 == 0) ? vf.createBNode("id_"+i % 150) : vf.createIRI("http://whatever/subj" + (i % 150)), RDF.TYPE, vf.createIRI("http://whatever/type" + i), i < 200 ? null : vf.createIRI("http://whatever/graph" + (i % 2)));
}
Resource bNode = vf.createBNode("bnodeid");
Value val = vf.createLiteral(42);
IRI iri = vf.createIRI("http://frequent/iri");
IRI graph0 = vf.createIRI("http://whatever/graph0");
IRI graph1 = vf.createIRI("http://whatever/graph1");
for (int i=0; i < 100; i++) {
IRI iri2 = vf.createIRI("http://frequent/iri"+i);
sail.addStatement(bNode, iri2, val);
sail.addStatement(bNode, iri2, iri, graph0);
sail.addStatement(iri, iri2, bNode, graph1);
}
sail.commit();
sail.close();
File root = File.createTempFile("test_stats", "");
root.delete();
root.mkdirs();
assertEquals(0, ToolRunner.run(HBaseServerTestInstance.getInstanceConfig(), new HalyardStats(),
new String[]{ "-D" + HalyardStats.SUBSET_THRESHOLD + "=100", "-s", "statsTable", "-t", root.toURI().toURL().toString() + "stats{0}.trig"}));
File f = new File(root, "stats0.trig");
assertTrue(f.isFile());
System.out.println(f.getAbsolutePath());
String content =new String(Files.readAllBytes(f.toPath()), StandardCharsets.UTF_8);
try (FileInputStream in = new FileInputStream(f)) {
final Model m = Rio.parse(in, "", RDFFormat.TRIG, new ParserConfig().set(BasicParserSettings.PRESERVE_BNODE_IDS, true), SimpleValueFactory.getInstance(), new ParseErrorLogger());
try (InputStream ref = HalyardStatsTest.class.getResourceAsStream("testStatsTarget.ttl")) {
RDFParser p = Rio.createParser(RDFFormat.TRIG);
p.setPreserveBNodeIDs(true);
p.setRDFHandler(new AbstractRDFHandler() {
@Override
public void handleStatement(Statement st) throws RDFHandlerException {
if (!m.contains(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext())) {
fail(MessageFormat.format("Expected {0} in:\n{1}\n", st, content));
}
}
}).parse(ref, "");
}
}
}