本文整理汇总了Java中com.hp.hpl.jena.rdf.model.Model.read方法的典型用法代码示例。如果您正苦于以下问题:Java Model.read方法的具体用法?Java Model.read怎么用?Java Model.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.hp.hpl.jena.rdf.model.Model
的用法示例。
在下文中一共展示了Model.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
/**
* Parse RDF input as string
*
* @param input RDF values as String
* @return an {@link Request} object which contains information about latitude, longitude and date
* @throws IllegalStateException if RDF is not literal
* @throws NullPointerException if input is null
*/
public static Request parse(String input) {
Objects.requireNonNull(input);
Model model = ModelFactory.createDefaultModel();
model.read(new ByteArrayInputStream(input.getBytes()), null, "TURTLE");
Map<String, Object> map = new HashMap<>();
model.listStatements().forEachRemaining(statement -> {
RDFNode rdfNode = statement.getObject();
if (rdfNode.isLiteral()) {
try {
map.put(statement.getPredicate().getLocalName(), statement.getObject().asLiteral().getValue());
} catch (Exception e) {
LOGGER.error("RDF statement is not literal");
throw new IllegalStateException(e.getMessage());
}
}
});
model.close();
return getDataFromMap(map);
}
示例2: getTestListFromManifest
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
public static Collection<Object[]> getTestListFromManifest(String manifestFileURL) {
// We'd like to use FileManager.loadModel() but it doesn't work on jar: URLs
// Model m = FileManager.get().loadModel(manifestFileURL);
Model m = ModelFactory.createDefaultModel();
m.read(manifestFileURL, "TURTLE");
IRI baseIRI = D2RQTestUtil.createIRI(m.getNsPrefixURI("base"));
ResultSet rs = QueryExecutionFactory.create(TEST_CASE_LIST, m).execSelect();
List<Object[]> result = new ArrayList<Object[]>();
while (rs.hasNext()) {
QuerySolution qs = rs.next();
Resource mapping = qs.getResource("mapping");
Resource schema = qs.getResource("schema");
// if (!mapping.getLocalName().equals("constant-object.ttl")) continue;
QueryExecution qe = QueryExecutionFactory.create(TEST_CASE_TRIPLES, m);
qe.setInitialBinding(qs);
Model expectedTriples = qe.execConstruct();
result.add(new Object[]{baseIRI.relativize(mapping.getURI()).toString(), mapping.getURI(),
schema.getURI(), expectedTriples});
}
return result;
}
示例3: loadDefaultRules
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
private static Model loadDefaultRules(){
Model rules=ModelFactory.createDefaultModel();
rules.add(SPIN.getModel());
rules.add(SP.getModel());
InputStream in=BimSPARQL.class.getClassLoader().getResourceAsStream("bimsparql/schm.ttl"); //new FileInputStream("IFC2X3_Schema.rdf");
rules.read(in, null,"TTL");
InputStream in2=BimSPARQL.class.getClassLoader().getResourceAsStream("bimsparql/pset.ttl"); //new FileInputStream("IFC2X3_Schema.rdf");
rules.read(in2, null,"TTL");
InputStream in3=BimSPARQL.class.getClassLoader().getResourceAsStream("bimsparql/pdt.ttl"); //new FileInputStream("IFC2X3_Schema.rdf");
rules.read(in3, null,"TTL");
InputStream in4=BimSPARQL.class.getClassLoader().getResourceAsStream("bimsparql/qto.ttl"); //new FileInputStream("IFC2X3_Schema.rdf");
rules.read(in4, null,"TTL");
InputStream in5=BimSPARQL.class.getClassLoader().getResourceAsStream("bimsparql/geom.ttl"); //new FileInputStream("IFC2X3_Schema.rdf");
rules.read(in5, null,"TTL");
InputStream in6=BimSPARQL.class.getClassLoader().getResourceAsStream("bimsparql/spt.ttl"); //new FileInputStream("IFC2X3_Schema.rdf");
rules.read(in6, null,"TTL");
return rules;
}
示例4: loadDefaultModel
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
public static OntModel loadDefaultModel(){
InputStream in = BodyGeometryTest.class.getClassLoader()
.getResourceAsStream("Duplex_A_20110505.ttl");
Model model=ModelFactory.createDefaultModel();
model.read(in,null,"TTL");
InputStream ins = BodyGeometryTest.class.getClassLoader()
.getResourceAsStream("IFC2X3_TC1.ttl");
InputStream input = BodyGeometryTest.class.getClassLoader()
.getResourceAsStream("Duplex_A_20110505_geometry.ttl");
Model geometryModel=ModelFactory.createDefaultModel();
geometryModel.read(input,null,"TTL");
Model schema=ModelFactory.createDefaultModel();
schema.read(ins,null,"TTL");
try {
BimSPARQL.init(model,geometryModel);
} catch (ClassNotFoundException | IOException | ParserConfigurationException | SAXException
| URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OntModel ontology=ModelFactory.createOntologyModel();
ontology.add(schema);
ontology.add(model);
ontology.add(geometryModel);
return ontology;
}
示例5: readFrom
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
@Override
public Model readFrom(Class<Model> type, Type genericType, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
throws IOException, WebApplicationException {
Model model = ModelFactory.createDefaultModel();
model.read(entityStream, null);
return model;
}
示例6: getExistingNamedGraph
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
/**
* Get all existing triples in a named graph
*
* @param namedGraph String with graph name.
* @return Jena model with the existing triples.
* @throws IOException
*/
public Model getExistingNamedGraph(String namedGraph) throws IOException {
String rq = "construct {?s ?p ?o} where { GRAPH <?g> {?s ?p ?o}}";
String query = rq.replace("?g", namedGraph);
//Accepting n-triples only.
Header header = new BasicHeader(HttpHeaders.ACCEPT, "text/plain");
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
log.debug("Connecting to SPARQL query API at: " + queryApi);
log.debug("SPARQL query: " + query);
HttpPost httpPost = new HttpPost(queryApi);
httpPost.addHeader(header);
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("query", query));
nvps.add(new BasicNameValuePair("email", vivoEmail));
nvps.add(new BasicNameValuePair("password", vivoPassword));
httpPost.setEntity(new UrlEncodedFormEntity(nvps));
CloseableHttpResponse response = httpclient.execute(httpPost);
try {
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
//read response into Jena model and return
Model model = ModelFactory.createDefaultModel();
model.read(is, null, "N-TRIPLES");
return model;
} finally {
response.close();
}
} finally {
httpclient.close();
}
}
示例7: loadModel
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
public static Model loadModel(String filenameOrURL, String baseIRI, String lang) {
if (!filenameOrURL.toLowerCase().startsWith("jar:")) {
return FileManager.get().loadModel(filenameOrURL, baseIRI, lang);
}
Model result = ModelFactory.createDefaultModel();
result.read(filenameOrURL, baseIRI, lang);
return result;
}
示例8: testReadWrite
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
@Test
public void testReadWrite() {
StringWriter out = new StringWriter();
loader.getWriter().write(out);
Model parsed = ModelFactory.createDefaultModel();
parsed.read(new StringReader(out.toString()),
BASE_IRI, "TURTLE");
assertIsomorphic(loader.getMappingModel(), parsed);
}
示例9: loadMetadataTemplate
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
public static Model loadMetadataTemplate(InputStream is) {
try {
Model tplModel = ModelFactory.createDefaultModel();
tplModel.read(is, "about:prefix:", "TTL");
return tplModel;
} catch (JenaException e) {
// ignore
}
return null;
}
示例10: mappingModel
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
/**
* Returns an in-memory Jena model containing the D2RQ mapping.
*
* @param baseURI Base URI for resolving relative URIs in the mapping, e.g., map namespace
* @return In-memory Jena model containing the D2RQ mapping
*/
public Model mappingModel(String baseURI) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
writeMapping(out);
try {
String mappingAsTurtle = out.toString("UTF-8");
Model result = ModelFactory.createDefaultModel();
result.read(new StringReader(mappingAsTurtle), baseURI, "TURTLE");
return result;
} catch (UnsupportedEncodingException ex) {
throw new RuntimeException("UTF-8 is always supported");
}
}
示例11: loadPropertyBridges
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
public static Collection<TripleRelation> loadPropertyBridges(String mappingFileName) {
Model m = ModelFactory.createDefaultModel();
Resource dummyDB = m.getResource(Test.DummyDatabase.getURI());
dummyDB.addProperty(RDF.type, D2RQ.Database);
m.read(D2RQTestSuite.class.getResourceAsStream(mappingFileName), null, "TURTLE");
Mapping mapping = new MapParser(m, null).parse();
return mapping.compiledPropertyBridges();
}
示例12: getResult
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
public List<String> getResult(InputStream in, String query){
Model model=ModelFactory.createDefaultModel();
model.read(in,null,"TTL");
Query q = QueryFactory.create(query);
QueryExecution qe = QueryExecutionFactory.create(q, model);
ResultSet qresults = qe.execSelect();
List<QuerySolution> solutions=ResultSetFormatter.toList(qresults);
List<String> results=new ArrayList<String>();
for(QuerySolution qs:solutions){
results.add(qs.toString());
}
return results;
}
示例13: main
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
public static void main(String[] args)
throws ClassNotFoundException, IOException, ParserConfigurationException, SAXException, URISyntaxException {
Model model = ModelFactory.createDefaultModel();
InputStream in = FireSeparationDistance.class.getClassLoader().getResourceAsStream("lifeline_final.ttl");
model.read(in, null, "TTL");
System.out.println(model.size());
Model geometryModel = ModelFactory.createDefaultModel();
InputStream ing = FireSeparationDistance.class.getClassLoader().getResourceAsStream("lifeline_final_geometry.ttl");
geometryModel.read(ing, null, "TTL");
System.out.println(geometryModel.size());
Model schema=loadModel("IFC2X3_TC1.ttl","TTL");
BimSPARQL.init(model, geometryModel);
Model ibcspin = ModelFactory.createDefaultModel();
addMagicProperty(ibcspin, IBC+"hasFireSeparationDistance", prefixes+hasFireSeparationDistance, 1);
addMagicProperty(ibcspin, IBC+"hasProtectedOpeningArea", prefixes+hasProtectedOpeningArea, 1);
addMagicProperty(ibcspin, IBC+"hasUnprotectedOpeningArea", prefixes+hasUnprotectedOpeningArea, 1);
addMagicProperty(ibcspin, IBC+"hasAp", prefixes+hasAp, 1);
addMagicProperty(ibcspin, IBC+"hasAu", prefixes+hasAu, 1);
Model ibc=loadIbcData();
SPINModuleRegistry.get().registerAll(ibc, null);
for (Function f:SPINModuleRegistry.get().getFunctions())
{
System.out.println(f.getURI());
}
com.hp.hpl.jena.query.Query query = QueryFactory.create(prefixes + mainQuery);
OntModel union = ModelFactory.createOntologyModel();
union.add(schema);
union.add(model);
union.add(geometryModel);
union.add(ibc);
System.out.println(union.size());
QueryExecution qe = QueryExecutionFactory.create(query, union);
com.hp.hpl.jena.query.ResultSet result = qe.execSelect();
ResultSetFormatter.out(result);
}
示例14: loadModel
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
public static Model loadModel(String url,String lang){
Model model=ModelFactory.createDefaultModel();
if(lang==null){
model.read(url);
}else{
InputStream in=FireSeparationDistance.class.getClassLoader().getResourceAsStream(url);
model.read(in,null,lang);
}
return model;
}
示例15: main
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
public static void main(String[] args){
Model schm=ModelFactory.createDefaultModel();
Model pset=ModelFactory.createDefaultModel();
Model qto=ModelFactory.createDefaultModel();
InputStream in=BimSPARQL.class.getClassLoader().getResourceAsStream("bimsparql/schm.ttl"); //new FileInputStream("IFC2X3_Schema.rdf");
schm.read(in, null,"TTL");
InputStream in2=BimSPARQL.class.getClassLoader().getResourceAsStream("bimsparql/pset_1.ttl"); //new FileInputStream("IFC2X3_Schema.rdf");
pset.read(in2, null,"TTL");
InputStream in4=BimSPARQL.class.getClassLoader().getResourceAsStream("bimsparql/qto.ttl"); //new FileInputStream("IFC2X3_Schema.rdf");
qto.read(in4, null,"TTL");
extract(schm,"schm");
extract(pset,"pset");
extract(qto,"qto");
}