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


Java OntModel.getResource方法代碼示例

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


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

示例1: loadSPINRules

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
/**
 * @param rulesFile
 * @param model
 * @throws FileNotFoundException
 */
private void loadSPINRules(String rulesFile, OntModel model) throws FileNotFoundException {

	this.getLogger().fine("---> loadSPINRules(): Starting to load rules from " + rulesFile);
	Scanner scanner = new Scanner(new File(rulesFile)).useDelimiter("\\n---\\n");

	int i = 0;
	while (scanner.hasNext()) {
		i++;
		String uri = scanner.next();
		String rule = scanner.next();
		Query arqQuery = ARQFactory.get().createQuery(model, rule);
		ARQ2SPIN arq2SPIN = new ARQ2SPIN(model);
		org.topbraid.spin.model.Query spinQuery = arq2SPIN.createQuery(arqQuery, null);
		Resource resource = model.getResource(uri);
		resource.addProperty((Property) SPIN.rule, spinQuery);
	}
	this.getLogger().info("<--- loadSPINRules(): " + i + " rules loaded from file: " + rulesFile);
}
 
開發者ID:gsi-upm,項目名稱:shanks-wsn-module,代碼行數:24,代碼來源:ZigBeeCoordiantorNodeSoftware.java

示例2: obtainCityInformation

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
/**
 * This method search in geocitties Ontology to obtain a valid URI containing the city information
 *
 * @param pCity The name of the city to search
 * @return A statmenet contianing the needed knowledge to link a city with its information
 */
private void obtainCityInformation(String pCity, OntModel pModel) {

    // Making the call to geoname database
    //TODO put this url as a static final value at top of this file
    String query = "http://api.geonames.org/search?name_equals="+pCity+"&featureClass=P&type=rdf&&username=elektro";
    ProcessBuilder p = new ProcessBuilder("curl", "-X", "POST", query);
    try {
        System.out.println("Calling to geocities about city information from: "+pCity +"\n");
        LOGGER.info("--> obtainCityInformation: Calling to geocities to obtain information from: "+ pCity);
        // Execute our command
        final Process shell = p.start();
        // catch output and see if all is ok
        BufferedReader reader =
                new BufferedReader(new InputStreamReader(shell.getInputStream()));
        StringBuilder builder = new StringBuilder();
        String line = null;
        // Filling with information the string builder list
        while ((line = reader.readLine()) != null) {
            // with the actual line we need to extract a defiend pattern
            if (line.contains("<gn:Feature rdf:about=") || line.contains("<rdfs:seeAlso rdf:resource=\"http://dbpedia.org/resour")) {
                // Regex pattern to extract the needed URI
                Pattern pattern = Pattern.compile("\"(.*?)\"");
                Matcher matcher = pattern.matcher(line);
                if (matcher.find()) {
                    // Obtaining the needed resource

                    // CAmbiar por el mimso sujeto de arriba que /City4age_ar/pilot/***
                    // y SR -_-

                    Resource subject = pModel.getResource(c4aBaseURI+"City");
                    // Obtaining the needed property
                    Property predicate = pModel.getProperty("owl:sameAS");
                    // Adding the URIS (They are not literal)
                    Resource object = ResourceFactory.createResource(matcher.group(1));
                    // Creating the logical statement
                    //use add property
                    pModel.add(subject, predicate, object);
                    //pModel.add(subject2, predicate, object);
                }else {
                    // we are only to save the problem, but not raise any error.
                    LOGGER.warning("--> obtainCityInformation: We found a possible resource but the Regex matcher" +
                            "is failing for some reason: "+line);
                }
            }
        }
        //System.out.println("Call succeeded. The size of new statement is: "+listStatements.size());
        //LOGGER.info("Call successful. The size of new statements is: "+listStatements.size());
    } catch (IOException e) {
        LOGGER.severe("--> obtainCityInformation: Fatal IO error detected in ProcessBuilder call");
        e.printStackTrace();
    }
}
 
開發者ID:aitoralmeida,項目名稱:c4a_data_repository,代碼行數:59,代碼來源:RuleEngine.java

示例3: createInstanceModel

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
private OntModel createInstanceModel(String thisModelName)
			throws IOException,
			ConfigurationException {
		if (instanceDataModels != null && instanceDataModels.containsKey(thisModelName)) {
			return instanceDataModels.get(thisModelName);
		}
		if (editedTboxModels != null && editedTboxModels.containsKey(thisModelName)) {
			return editedTboxModels.get(thisModelName);
		}
		OntModel model = ModelFactory.createOntologyModel(getConfigurationMgr().getOntModelSpec(null));
		model.getDocumentManager().setFileManager(getConfigurationMgr().getJenaDocumentMgr().getFileManager());
		Resource importOnt = model.getResource(getModelName());
		Ontology ont = model.createOntology(thisModelName);
		ont.addImport(importOnt);
		ont.addComment("This ontology model was created by SadlServerPE.", "en");
		model.getDocumentManager().setProcessImports(true);
		model.loadImports();
//		if (logger.isDebugEnabled()) {
			Iterator<String> importItr = model.listImportedOntologyURIs().iterator();
			while (importItr.hasNext()) {
//				logger.debug("Model '" + thisModelName + "' imports '" + importItr.next() + "'");
				System.out.println("Model '" + thisModelName + "' imports '" + importItr.next() + "'");
		}
//		}
		model.getDocumentManager().setProcessImports(false);
		if (instanceDataModels == null) {
			instanceDataModels = new HashMap<String, OntModel>(); 
		}
		instanceDataModels.put(thisModelName, model);
		return model;
	}
 
開發者ID:crapo,項目名稱:sadlos2,代碼行數:32,代碼來源:SadlServerPEImpl.java

示例4: main

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public static void main(String args[])
{
	String filename = "example6.rdf";
	
	// Create an empty model
	OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
	
	// Use the FileManager to find the input file
	InputStream in = FileManager.get().open(filename);

	if (in == null)
		throw new IllegalArgumentException("File: "+filename+" not found");

	// Read the RDF/XML file
	model.read(in, null);
	
	
	// ** TASK 7.1: List all individuals of "Person" **
	
	Resource individ = model.getResource(ns + "Person");
	ExtendedIterator<Individual> iter = model.listIndividuals(individ);
	while(iter.hasNext())
	{
		System.out.println("Persons: " + iter.next().getURI());
	}
	
	
	// ** TASK 7.2: List all subclasses of "Person" **
	
	OntClass person = model.getOntClass(ns + "Person");
	ExtendedIterator<? extends OntResource> iter2 = person.listInstances();
	iter2 = person.listSubClasses();
	while(iter2.hasNext()) 
	{
		OntClass subclass = (OntClass)iter2.next();
		System.out.println("subclasses of Person: " + subclass);
	}
	
	// ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. TIP: you need some inference... **
	

}
 
開發者ID:FacultadInformatica-LinkedData,項目名稱:Curso2014-2015,代碼行數:43,代碼來源:Task07_Tarasyuk.java


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