当前位置: 首页>>代码示例>>Java>>正文


Java Model.read方法代码示例

本文整理汇总了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);
}
 
开发者ID:IKB4Stream,项目名称:IKB4Stream,代码行数:30,代码来源:RDFParser.java

示例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;
	}
 
开发者ID:d2rq,项目名称:r2rml-kit,代码行数:23,代码来源:ProcessorTestBase.java

示例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;
}
 
开发者ID:BenzclyZhang,项目名称:BimSPARQL,代码行数:19,代码来源:BimSPARQL.java

示例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;
}
 
开发者ID:BenzclyZhang,项目名称:BimSPARQL,代码行数:27,代码来源:QueryFunctionTest.java

示例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;
}
 
开发者ID:teamdigitale,项目名称:ontonethub,代码行数:10,代码来源:JenaModelReader.java

示例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();
    }
}
 
开发者ID:lawlesst,项目名称:karma2vivo,代码行数:41,代码来源:VIVOSPARQLClient.java

示例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;
}
 
开发者ID:d2rq,项目名称:r2rml-kit,代码行数:9,代码来源:CompatibilityFileManager.java

示例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);
}
 
开发者ID:d2rq,项目名称:r2rml-kit,代码行数:10,代码来源:ProcessorTestBase.java

示例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;
}
 
开发者ID:aitoralmeida,项目名称:c4a_data_repository,代码行数:11,代码来源:MetadataCreator.java

示例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");
	}
}
 
开发者ID:aitoralmeida,项目名称:c4a_data_repository,代码行数:19,代码来源:MappingGenerator.java

示例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();
}
 
开发者ID:aitoralmeida,项目名称:c4a_data_repository,代码行数:9,代码来源:MapFixture.java

示例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;
}
 
开发者ID:BenzclyZhang,项目名称:BimSPARQL,代码行数:14,代码来源:Server.java

示例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);

      }
 
开发者ID:BenzclyZhang,项目名称:BimSPARQL,代码行数:38,代码来源:FireSeparationDistance.java

示例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;
}
 
开发者ID:BenzclyZhang,项目名称:BimSPARQL,代码行数:11,代码来源:FireSeparationDistance.java

示例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");
}
 
开发者ID:BenzclyZhang,项目名称:BimSPARQL,代码行数:15,代码来源:VocabularyExtract.java


注:本文中的com.hp.hpl.jena.rdf.model.Model.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。