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


Java OntModel.add方法代碼示例

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


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

示例1: loadDefaultModel

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

示例2: getOntResourcesOfType

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
/**
 * Gets a list of resources of the given type
 * 
 * @param model Jena model
 * @param resource Given resource
 * @return List of resources
 */
public static List<Resource> getOntResourcesOfType(Model model, Resource resource) {
    List<Resource> res = new ArrayList();
    OntModel ontModel = ModelFactory.createOntologyModel();
    ontModel.add(model);
    ontModel.add(coreModel);

    // RDFUtils.print(ontModel);

    Resource r2 = ontModel.createResource(resource.getURI());
    ExtendedIterator it = ontModel.listIndividuals(r2);
    while (it.hasNext()) {
        Individual ind = (Individual) it.next();
        if (ind.isResource()) {
            res.add(ind);
        }
    }
    return res;
}
 
開發者ID:oeg-upm,項目名稱:odrlapi,代碼行數:26,代碼來源:RDFUtils.java

示例3: 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

示例4: main

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

示例5: executePublishing

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
@Override
public void executePublishing() throws Exception {
	super.executeImport();
	SDBConnection conn = new SDBConnection(jenaDataSource);
	StoreDesc storeDesc = new StoreDesc(LayoutType.LayoutTripleNodesHash, BygleSystemUtils.getDBType(databaseType));
	Store store = SDBFactory.connectStore(conn, storeDesc);
	if (!StoreUtils.isFormatted(store))
		store.getTableFormatter().create();
	File importDir = new File(importDirectory);
	FileFilter fileFilter = new WildcardFileFilter("*.nt");
	File[] importFiles = importDir.listFiles(fileFilter);
	if (importFiles.length > 0) {
		OntModel ontModel = ModelFactory.createOntologyModel();
		FileFilter ontologyFileFilter = new WildcardFileFilter("*.owl");
		File[] ontologyfiles = importDir.listFiles(ontologyFileFilter);
		for (int x = 0; x < ontologyfiles.length; x++) {
			FileManager.get().readModel(ontModel, ontologyfiles[x].getAbsolutePath());
		}
		System.out.println("##############################STARTING PUBLISHING#############################");
		for (int i = 0; i < importFiles.length; i++) {
			Model modelTpl = ModelFactory.createDefaultModel();
			FileManager.get().readModel(modelTpl, importFiles[i].getAbsolutePath());
			System.out.println("PUBLISHING  FILE " + importFiles[i].getName());
			System.out.println("##############################START SAVING DATA###############################");
			ontModel.add(modelTpl);
		}
		Dataset dataset = SDBFactory.connectDataset(store);
		dataset.getDefaultModel().add(ontModel);
		store.getConnection().close();
		store.close();
		System.out.println("##############################END PUBLISHING##################################");
		FileUtils.cleanDirectory(importDir);
		System.out.println("##############################PUBLISHING SUCCESS##############################");
	} else {
		System.out.println("##############################NO FILES TO PUBLISH##############################");
	}
}
 
開發者ID:regestaexe,項目名稱:bygle-ldp,代碼行數:38,代碼來源:JenaEndPointManager.java

示例6: writeSemanticModelFiles

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
/**
	 * Uses the classes from the DB to write the RDF files based on those.
	 */
	public static void writeSemanticModelFiles() {
		logger.debug("Writing the context model to a file");

		// TODO: Complement the model with the other required entities 
		OntModel usersModel = writeUserEntries();
		OntModel projectsModel = writeProjectEntries();
		OntModel metadataModel = writeMetaDataModelEntries();

		//	uqModel.write(System.out, "RDF/XML");
		//	RDFDataMgr.write(System.out, uqModel, RDFFormat.RDFXML_PRETTY);

		// Write the individual models to a single file
		// holding all the triples
		final OntModel combined = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
		for (final OntModel part : new OntModel[] { usersModel, projectsModel, metadataModel } ) {
			combined.add(part);
		}
		try {
			String dataDir = UQasarUtil.getDataDirPath();
			// TODO: Find out why this does not work in Linux
//			String modelPath = "file:///" + dataDir + ONTOLOGYFILE;
			String modelPath = dataDir + ONTOLOGYFILE;
			
			combined.write(new FileOutputStream(modelPath, false));
			logger.debug("Context Model written to file " +modelPath);
			UQasarUtil.setUqModel(combined);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
 
開發者ID:U-QASAR,項目名稱:u-qasar.platform,代碼行數:34,代碼來源:UQasarUtil.java

示例7: getDataModel

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public OntModel getDataModel(QueryVars queryVars){

		OntModel dataModel = ModelFactory.createOntologyModel();

		for(Term term: super.getBody()){
			dataModel.add(dataModel.asStatement(queryClauseToTriple(term,queryVars)));
		}
		return dataModel;
	}
 
開發者ID:peterjohnlawrence,項目名稱:com.inova8.remediator,代碼行數:10,代碼來源:QueryClause.java

示例8: isOfKind

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
static boolean isOfKind(Resource rrule, String uri) {
    if (rrule == null || uri == null || uri.isEmpty() || rrule.getURI() == null) {
        return false;
    }
    OntModel ontModel = ModelFactory.createOntologyModel();
    ontModel.add(coreModel);
    Individual res = ontModel.getIndividual(rrule.getURI());
    OntClass clase = ontModel.getOntClass(uri);
    if (res == null || clase == null) {
        return false;
    }
    return res.hasOntClass(clase);

}
 
開發者ID:oeg-upm,項目名稱:odrlapi,代碼行數:15,代碼來源:RDFUtils.java

示例9: testUploadedData

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
/**
 * Test is new infered data is uploaded into Fuseki server. To do this it is needed.
 *
 *          --> A Fuseki server runing in localhost int port 3030
 *          ---> A city4age dataset created into Fuseki Server
 *
 */
@Test
public void testUploadedData() throws Exception {
    boolean res = false;
    InfModel inf = ModelFactory.createInfModel(this.myReasoner, this.instances);
    final OntModel finalResult = ModelFactory.createOntologyModel();


    finalResult.add(this.instances);
    finalResult.add(inf.getDeductionsModel());
    // Set prefix map
    finalResult.setNsPrefixes(this.instances.getNsPrefixMap());
    finalResult.setNsPrefixes(inf.getDeductionsModel().getNsPrefixMap());

    // Converting final result to string and writ it
    StringWriter out = new StringWriter();
    finalResult.write(out, "RDF/XML");
    String result = out.toString();
    // Launch curl to upload or current knowledge into Fuseki
    ProcessBuilder p = new ProcessBuilder("curl", "-k", "-X", "POST", "--header", "Content-Type: application/rdf+xml",
            "-d", result, "http://localhost:3030/city4age/data");
    try {
        System.out.println("Uploading new Knowledge to Fuseki......................");
        System.out.println("");
        // 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;
        while ( (line = reader.readLine()) != null) {
            builder.append(line);
            builder.append(System.getProperty("line.separator"));
        }
        String output = builder.toString();
        if (output.length() > 0 && output.contains("count")) {
            // We have good response from the server
            res = true;
        }else {
            System.err.println("Some error happened. Is Fuseki activated?");
        }
    }catch (IOException e) {
        e.printStackTrace();
    }

    // Asserting the result
    assertTrue(res);
}
 
開發者ID:aitoralmeida,項目名稱:c4a_data_repository,代碼行數:56,代碼來源:RuleEngineTest.java

示例10: toRdf

import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
/**
 * Save tags ontology. If it doesn't exists, build it from scratch.
 * 
 * TODO called on EVERY SAVE of the notebook - very inefficient. 
 *  
 * @throws MindRaiderException 
 */
public void toRdf() throws MindRaiderException {
    // build the ontology and save it using RDF custodian
    
    // create ontology using runtime information
    // (tag is class and tagged resource is an instance of this class)
    // take tag one by one and create statements
    OwlOntology tagOntology=new OwlOntology();
    OntModel ontology = tagOntology.getOntology();
    
    OntClass tag= ontology.createClass(MindRaiderConstants.MR_OWL_TAG);
    OntClass flag = ontology.createClass(MindRaiderConstants.MR_OWL_FLAG);

    // properties
    ObjectProperty flagPropertyType = ontology.createObjectProperty(MindRaiderConstants.MR_OWL_PROPERTY_FLAG);
    flagPropertyType.addRange(flag);
    ObjectProperty tagPropertyType = ontology.createObjectProperty(MindRaiderConstants.MR_OWL_PROPERTY_TAG);
    tagPropertyType.addRange(tag);
    
    Collection<TagEntry> values = tags.values();
    if(values!=null) {
        TagEntryImpl[] tagEntries = values.toArray(new TagEntryImpl[0]);
        Property tagProperty = ontology.getProperty(MindRaiderConstants.MR_OWL_PROPERTY_TAG);
        Property inNotebookProperty = ontology.createProperty(MindRaiderConstants.MR_OWL_PROPERTY_IN_NOTEBOOK);
        if(tagEntries!=null && tagEntries.length>0) {
            for(TagEntry tagEntry: tagEntries) {
                OntClass tagClass = ontology.createClass(tagEntry.getTagUri());
                tagClass.addLabel(tagEntry.getTagLabel(), "en");
                flag.addSubClass(tagClass);
                tag.addSubClass(tagClass);
                
                // include tagged resources - iterate the hashmap
                TaggedResourceEntry[] resources = tagEntry.getResources();
                if(resources!=null && resources.length>0) {
                    logger.debug("  Tag entry resources: "+resources.length);
                    for(TaggedResourceEntry resource: resources) {
                        Resource conceptResource = ontology.createResource(resource.conceptUri);
                        // tagged resource is the instance of the class
                        ontology.add(ontology.createStatement(conceptResource, tagProperty, tagClass));
                        ontology.add(ontology.createStatement(conceptResource, RDFS.label, ontology.createLiteral(resource.conceptLabel, "en")));
                        // timestamp and notebook information is not stored - it would just duplicate
                        // what's stored in notebook/concepts models - this information will be filled
                        // on concept load - btw this would also cause problems e.g. on refactoring of
                        // concepts and notebooks
                        // ... but I will store it anyway :-) concept is addressed in a notebook
                        Resource notebookResource= ontology.createResource(resource.notebookUri);
                        ontology.add(ontology.createStatement(
                                conceptResource, 
                                inNotebookProperty,
                                notebookResource));
                        ontology.add(ontology.createStatement(
                                notebookResource, 
                                RDFS.label, 
                                ontology.createLiteral(resource.notebookLabel, "en")));
                    }
                }
            }
        }
    }
    
    // store the ontology
    MindRaider.rdfCustodian.saveOntology(RdfCustodian.FILENAME_TAGS_ONTOLOGY,tagOntology);
}
 
開發者ID:dvorka,項目名稱:mindraider,代碼行數:70,代碼來源:TagCustodian.java


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