當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。