本文整理汇总了Java中org.apache.jena.riot.RDFDataMgr.read方法的典型用法代码示例。如果您正苦于以下问题:Java RDFDataMgr.read方法的具体用法?Java RDFDataMgr.read怎么用?Java RDFDataMgr.read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.riot.RDFDataMgr
的用法示例。
在下文中一共展示了RDFDataMgr.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toRdf
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
/**
* Convert a PhenoPacket to RDF triples using the JSON-LD context
*
* @param packet
* @param base
* URI base for generated RDF; if `null` a UUID-based base will
* be used
* @return model containing RDF triples
* @throws JsonLdError
* @throws JsonProcessingException
*/
public static Model toRdf(PhenoPacket packet, String base)
throws JsonLdError, JsonProcessingException {
PhenoPacket packetWithContext;
if (packet.getContext() == null) {
packetWithContext = PhenoPacket.newBuilder(packet)
.context(ContextUtil.defaultContextURI)
.build();
} else {
packetWithContext = packet;
}
Model rdfModel = ModelFactory.createDefaultModel();
StringReader reader = new StringReader(
JsonGenerator.render(packetWithContext));
String baseToUse;
if (base != null) {
baseToUse = base;
} else {
String uuid = UUID.randomUUID().toString();
baseToUse = "http://phenopackets.org/local/" + uuid + "/";
}
RDFDataMgr.read(rdfModel, reader, baseToUse, Lang.JSONLD);
return rdfModel;
}
示例2: createModel
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
private Model createModel(Logger logger) throws IOException {
LoggingUtils.configureSilentLog4J();
Model model = ModelFactory.createDefaultModel();
model.setNsPrefixes(PrefixMapping.Standard);
model.setNsPrefix("xsd", "http://www.w3.org/2001/XMLSchema#");
model.setNsPrefix("skos", "http://www.w3.org/2004/02/skos/core#");
model.setNsPrefix("oboInOwl", "http://www.geneontology.org/formats/oboInOwl#");
model.setNsPrefixes(prefixes);
for (InputStream is : Iterators.loop(source.getInputStreams())) {
logger.info("loading model from: " + source.getStreamName(is));
// System.err.println("is = " + is);
// model.read(is, null, Lang.RDFXML.toString());
RDFDataMgr.read(model, is, Lang.RDFXML);
}
return model;
}
示例3: DBpediaGenderDictionary
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
public DBpediaGenderDictionary() {
Model model = ModelFactory.createDefaultModel();
Literal maleLit = model.createLiteral(VALUE_MALE, "en");
Literal femaleLit = model.createLiteral(VALUE_FEMALE, "en");
RDFDataMgr.read(model, getClass().getClassLoader().getResourceAsStream(GENDER_FILE_LOCATION), Lang.TURTLE);
StmtIterator iter = model.listStatements(null, model.createProperty(GENDER_PROPERTY), (RDFNode) null);
while(iter.hasNext()) {
Statement st = iter.next();
Literal lit = st.getObject().asLiteral();
if(lit.equals(maleLit)) {
male.add(st.getSubject().getURI());
} else if(lit.equals(femaleLit)){
female.add(st.getSubject().getURI());
}
}
}
示例4: DBpediaGenderDictionary
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
public DBpediaGenderDictionary() {
Model model = ModelFactory.createDefaultModel();
Literal maleLit = model.createLiteral(VALUE_MALE, "en");
Literal femaleLit = model.createLiteral(VALUE_FEMALE, "en");
RDFDataMgr.read(model, getClass().getClassLoader().getResourceAsStream(GENDER_FILE_LOCATION), Lang.TURTLE);
StmtIterator iter = model.listStatements(null, model.createProperty(GENDER_PROPERTY), (RDFNode) null);
while (iter.hasNext()) {
Statement st = iter.next();
Literal lit = st.getObject().asLiteral();
if (lit.equals(maleLit)) {
male.add(st.getSubject().getURI());
} else if (lit.equals(femaleLit)) {
female.add(st.getSubject().getURI());
}
}
}
示例5: readRDF
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
private static Model readRDF(String s) {
Model model = ModelFactory.createDefaultModel();
if (isPath(s)) {
// System.out.println("Parsing file " + s);
model.read(s);
} else {
try {
// System.out.println("Parsing RDF string " + s);
RDFDataMgr.read(model, new ByteArrayInputStream(s.getBytes("UTF-8")), Lang.TTL);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
return model;
}
示例6: loadData
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
/**
* Import the data into the data set. When a new data set is imported the old data is deleted.
* @param dataset
* @param file
*/
public void loadData(Dataset dataset, String file){
log.info("Start loading") ;
long startTime = System.nanoTime() ;
dataset.begin(ReadWrite.WRITE) ;
try {
Model m = dataset.getDefaultModel() ;
log.info("Number of triples before loading: " + m.size());
RDFDataMgr.read(m, file) ;
log.info("Number of triples after loading: " + m.size());
dataset.commit() ;
}
finally {
dataset.end() ;
}
long finishTime = System.nanoTime() ;
double time = (finishTime-startTime)/1.0e6 ;
log.info(String.format("Finish loading - %.2fms", time)) ;
}
示例7: testSetDefaultGraph_admin
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
@Test
public void testSetDefaultGraph_admin() {
String file = datasource + "relative1.nt";
// Read triples into dataset
RDFDataMgr.read(markLogicDatasetGraphWriter, file);
markLogicDatasetGraphWriter.sync();
Graph g1 = markLogicDatasetGraphWriter.getDefaultGraph();
assertTrue("did not match Triples", g1.toString().contains("#electricVehicle2"));
// Create New graph and add triples from defaultgraph to new graph
Triple triple = new Triple(NodeFactory.createURI("s5"), NodeFactory.createURI("p5"), NodeFactory.createURI("o5"));
Quad quad = new Quad(NodeFactory.createURI("new-graph-fordefault"), triple);
Node n1 = NodeFactory.createURI("new-graph-fordefault");
markLogicDatasetGraphWriter.add(quad);
markLogicDatasetGraphWriter.sync();
Graph g2 = markLogicDatasetGraphWriter.getGraph(n1);
assertTrue("did not match Triples", g2.contains(triple));
// Set DefaultGraph to be NamedGraph
markLogicDatasetGraphWriter.setDefaultGraph(g2);
Graph defaultG = markLogicDatasetGraphWriter.getDefaultGraph();
assertTrue("did not match Triples", defaultG.contains(triple));
}
示例8: readSemanticModelFiles
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
/**
* Read the RDF model from files.
*/
public static void readSemanticModelFiles() {
logger.debug("Reading the model from a file");
// Read the model to an existing model
String dataDir = UQasarUtil.getDataDirPath();
String modelPath = "file:///" + dataDir + ONTOLOGYFILE;
// String modelPath = "file:///C:/nyrhinen/Programme/jboss-as-7.1.1.Final/standalone/data/uq-ontology-model.rdf";
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
RDFDataMgr.read(model, modelPath);
// Test output to standard output
// RDFDataMgr.write(System.out, uqModel, RDFFormat.RDFXML_PRETTY);
logger.debug("Model read from file " +modelPath);
UQasarUtil.setUqModel(model);
System.out.println("Reading done.");
}
示例9: testStringAskQuery
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
@Test
public void testStringAskQuery() {
String file = datasource + "tigers.ttl";
// Read triples into dataset
RDFDataMgr.read(markLogicDatasetGraph, file);
markLogicDatasetGraph.sync();
dataSet = DatasetFactory.create(markLogicDatasetGraph);
String query1 = "PREFIX bb: <http://marklogic.com/baseball/players#>" + " ASK " + " WHERE" + " {" + " ?id bb:lastname ?name ."
+ " FILTER EXISTS { ?id bb:country ?countryname }" + " }";
QueryExecution queryExec = QueryExecutionFactory.create(query1, dataSet);
Boolean result = queryExec.execAsk();
assertFalse(result);
String query2 = "PREFIX bb: <http://marklogic.com/baseball/players#>" + "PREFIX r: <http://marklogic.com/baseball/rules#>"
+ " ASK WHERE" + " {" + " ?id bb:team r:Tigers." + " ?id bb:position \"pitcher\"." + " }";
queryExec = QueryExecutionFactory.create(query2, dataSet);
assertTrue(queryExec.execAsk());
markLogicDatasetGraph.close();
markLogicDatasetGraph = MarkLogicDatasetGraphFactory.createDatasetGraph(writerClient);
}
示例10: testStringAskQuery2
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
@Test
public void testStringAskQuery2() {
String file = datasource + "tigers.ttl";
// Read triples into dataset
RDFDataMgr.read(markLogicDatasetGraph, file);
markLogicDatasetGraph.sync();
Graph g = markLogicDatasetGraph.getDefaultGraph();
Node newgraph = NodeFactory.createURI("http://marklogic.com/Graph1");
markLogicDatasetGraph.addGraph(newgraph, g);
dataSet = DatasetFactory.create(markLogicDatasetGraph);
String query1 = "ASK FROM <http://marklogic.com/Graph1>" + " WHERE" + " {" + " ?player ?team <#Tigers>." + " }";
QueryExecution queryExec = QueryExecutionFactory.create(query1, dataSet);
Boolean result = queryExec.execAsk();
assertFalse(result);
String query2 = "PREFIX bb: <http://marklogic.com/baseball/players#>" + "PREFIX r: <http://marklogic.com/baseball/rules#>"
+ " ASK WHERE" + " {" + " ?id bb:team r:Tigers." + " ?id bb:position \"pitcher\"." + " }";
queryExec = QueryExecutionFactory.create(query2, dataSet);
assertTrue(queryExec.execAsk());
}
示例11: testNTriplesSerializer
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
@Test
public void testNTriplesSerializer() {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
service3.write(getTriples(), out, NTRIPLES);
final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
final org.apache.jena.graph.Graph graph = createDefaultGraph();
RDFDataMgr.read(graph, in, Lang.NTRIPLES);
validateGraph(rdf.asGraph(graph));
}
示例12: testBufferedSerializer
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
@Test
public void testBufferedSerializer() {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
service.write(getTriples(), out, RDFXML);
final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
final org.apache.jena.graph.Graph graph = createDefaultGraph();
RDFDataMgr.read(graph, in, Lang.RDFXML);
validateGraph(rdf.asGraph(graph));
}
示例13: testTurtleSerializer
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
@Test
public void testTurtleSerializer() {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
service.write(getTriples(), out, TURTLE);
final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
final org.apache.jena.graph.Graph graph = createDefaultGraph();
RDFDataMgr.read(graph, in, Lang.TURTLE);
validateGraph(rdf.asGraph(graph));
}
示例14: loadOntology
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
/**
* Loads an ontology to the triple store, in the
* default graph.
* @param fileName File name with the ontology context.
*/
public static void loadOntology(InputStream fileName) {
List<String> ont = new ArrayList<>();
// Check if the ontology is already there
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
String prefix = StrUtils.strjoinNL
( "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
, "PREFIX owl: <http://www.w3.org/2002/07/owl#>");
String query = prefix + "SELECT ?s WHERE {?s rdf:type owl:Ontology}";
try (QueryExecution qexec = QueryExecutionFactory.create(query, dataset)) {
ResultSet result = qexec.execSelect();
while (result.hasNext()) {
ont.add(result.next().get("s").toString());
}
}
} finally {
dataset.end();
}
// Load QUDT ontology
if (ont.isEmpty()) {
dataset = ThingDirectory.get().dataset;
dataset.begin( ReadWrite.WRITE );
try {
Model m = dataset.getDefaultModel();
//RDFDataMgr.read(m, fileName);
RDFDataMgr.read(m, fileName, Lang.TURTLE);
dataset.commit();
} finally {
dataset.end();
}
}
}
示例15: serialize
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
@Override
public void serialize() {
for(Writer writer : fileWriter) {
try {
writer.flush();
} catch (IOException e) {
throw new RuntimeException(e);
}
String str = writer.toString();
RDFDataMgr.read(model, new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8)), Lang.NTRIPLES);
}
super.serialize();
}