當前位置: 首頁>>代碼示例>>Java>>正文


Java ModelFactory.createDefaultModel方法代碼示例

本文整理匯總了Java中com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel方法的典型用法代碼示例。如果您正苦於以下問題:Java ModelFactory.createDefaultModel方法的具體用法?Java ModelFactory.createDefaultModel怎麽用?Java ModelFactory.createDefaultModel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.hp.hpl.jena.rdf.model.ModelFactory的用法示例。


在下文中一共展示了ModelFactory.createDefaultModel方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parse

import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的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: setUp

import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的package包/類
public void setUp() {
	this.model = ModelFactory.createDefaultModel();
	this.mapping = new Mapping();
	this.database = new Database(this.model.createResource());
	this.mapping.addDatabase(this.database);
	
	concept = createClassMap("http://example.com/concept#@@[email protected]@");
	conceptTypeBridge = createPropertyBridge(concept, RDF.type.getURI());
	conceptTypeBridge.setConstantValue(model.createResource("http://www.w3.org/2004/02/skos/core#Concept"));
	
	collection = createConstantClassMap("http://example.com/collection#MyConceptCollection");
	collectionTypeBridge = createPropertyBridge(collection, RDF.type.getURI());
	collectionTypeBridge.setConstantValue(model.createResource("http://www.w3.org/2004/02/skos/core#Collection"));

	memberBridge = createPropertyBridge(collection, "http://www.w3.org/2004/02/skos/core#member");
	memberBridge.setRefersToClassMap(concept);
	memberBridge.addCondition("c.foo = 1");
}
 
開發者ID:aitoralmeida,項目名稱:c4a_data_repository,代碼行數:19,代碼來源:ConstantValueClassMapTest.java

示例3: getTestListFromManifest

import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的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

示例4: loadModel

import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的package包/類
public static boolean loadModel(Model m, String url)
{
	String sContent = getRDF(url);
	if ( sContent == null ) { return false; }

	Model mTemp = ModelFactory.createDefaultModel();
	try {
		mTemp.read(new StringReader(sContent), url, "RDF/XML");
	}
	catch (Exception e) {
		System.err.println("error parsing: " + url + ", error: " + e.getMessage());
		return false;
	}

	m.add(mTemp);

	return true;
}
 
開發者ID:hugomanguinhas,項目名稱:europeana,代碼行數:19,代碼來源:VocsUtils.java

示例5: importModelFromSingleFile

import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的package包/類
private void importModelFromSingleFile(File file, String lang) {
	Model m = ModelFactory.createDefaultModel();
	
	try {
		InputStream s = new FileInputStream(file);
		m.read(s, null);
		
		this.addModel(m, file.getName());
		
		logger.info("The model " + file.getPath() + " successfully imported to repository");
		
	} catch (Throwable t) {
		logger.error("Error reading the model file!", t);
		return;
	}		
}
 
開發者ID:therelaxist,項目名稱:spring-usc,代碼行數:17,代碼來源:Repository.java

示例6: main

import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的package包/類
public static void main(String[] args) throws JSONException, KarmaException, IOException {
	Options options = createCommandLineOptions();
	CommandLine cl = CommandLineArgumentParser.parse(args, options, GenerateContextFromModel.class.getSimpleName());
	if(cl == null)
	{
		return;
	}
	String fileName = (String) cl.getOptionValue("modelpath");
	String output = (String) cl.getOptionValue("outputfile");
	if (fileName == null) {
		System.out.println("No model file specified!");
		return;
	}
	if (output == null) {
		output = fileName + ".json";
	}
	File file = new File(fileName);
	Model model = ModelFactory.createDefaultModel();
       InputStream s = new FileInputStream(file);
       model.read(s, null, "TURTLE");
       JSONObject top = new ContextGenerator(model, true).generateContext();
       PrintWriter pw = new PrintWriter(output);
       pw.println(top.toString(4));
       pw.close();
}
 
開發者ID:therelaxist,項目名稱:spring-usc,代碼行數:26,代碼來源:GenerateContextFromModel.java

示例7: readFrom

import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的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

示例8: loadMetadataTemplate

import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的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

示例9: main

import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的package包/類
public static void main(String[] args) throws FileNotFoundException{
		Model model=ModelFactory.createDefaultModel();
		InputStream in=new FileInputStream("BimSPARQL_example.ttl");
		model.read(in,null,"TTL");
		String query=prefixes+"SELECT ?s\n"+ 
"WHERE{?s ?p ?o .}";
		Query q = QueryFactory.create(query);
		QueryExecution qe = QueryExecutionFactory.create(q, model);
		ResultSet qresults = qe.execSelect();
        ResultSetFormatter.out(qresults);
	}
 
開發者ID:BenzclyZhang,項目名稱:BimSPARQL,代碼行數:12,代碼來源:JenaTest.java

示例10: loadModel

import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的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

示例11: bulkUpdate

import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的package包/類
/**
 * Method called to Chunk the triples into N-Sized batches and post to VIVO.
 * This is designed to work around / handle errors when posting sets of triples
 * over 10,000 to the API.
 *
 * @param namedGraph String with named graph.
 * @param changeModel Jena model with set of changes to sync to store.
 * @param changeType Either add or remove.
 * @return Boolean true if update was successful.
 * @throws IOException
 */
private Boolean bulkUpdate(String namedGraph, Model changeModel, String changeType) throws IOException {
    // Temporary model to hold
    Model tmpModel = ModelFactory.createDefaultModel();
    Integer bSize = Integer.parseInt(batchSize);
    // Use an integer to count triples rather than calling size on the model
    // during each loop.
    Integer size = 0;
    StmtIterator iter = changeModel.listStatements();
    while (iter.hasNext()) {
        Statement stmt = iter.nextStatement();  // get next statement
        tmpModel.add(stmt);
        size++;
        if (size >= bSize) {
            // Submit
            log.info("Submitting " + size + " triples to " + namedGraph);
            submitBatch(tmpModel, namedGraph, changeType);
            // Reset the tmp model.
            tmpModel.removeAll();
            // Reset the counter.
            size = 0;
        }
    }
    log.info("model size:" + tmpModel.size());
    // Submit the remaining statements, if any.
    if (tmpModel.size() > 0) {
        submitBatch(tmpModel, namedGraph, changeType);
    }
    return true;
}
 
開發者ID:lawlesst,項目名稱:karma2vivo,代碼行數:41,代碼來源:VIVOSPARQLClient.java

示例12: createModel

import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的package包/類
private Model createModel() {
  Model model = ModelFactory.createDefaultModel();
  String NS = "http://www.computas.no/zebra/";
  model.setNsPrefix("", NS);
  model.setNsPrefix("xsd", "http://www.w3.org/2001/XMLSchema#");
  //TODO
  return model;
}
 
開發者ID:mehmandarov,項目名稱:zebra-puzzle-workshop,代碼行數:9,代碼來源:Exercise2.java

示例13: createModel

import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的package包/類
private Model createModel() {
  Model model = ModelFactory.createDefaultModel();
  String NS = "http://www.computas.no/zebra/";
  model.setNsPrefix("", NS);
  model.setNsPrefix("xsd", "http://www.w3.org/2001/XMLSchema#");
  Resource subject = model.createResource(NS + "Joe");
  Property predicate = model.createProperty(NS + "hasSentMessage");
  String object = "Hello World!";
  subject.addProperty(predicate, object, XSDDatatype.XSDstring);
  return model;
}
 
開發者ID:mehmandarov,項目名稱:zebra-puzzle-workshop,代碼行數:12,代碼來源:Exercise2.java

示例14: loadModel

import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的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

示例15: getResult

import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的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


注:本文中的com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。