本文整理匯總了Java中com.hp.hpl.jena.ontology.OntModel.createObjectProperty方法的典型用法代碼示例。如果您正苦於以下問題:Java OntModel.createObjectProperty方法的具體用法?Java OntModel.createObjectProperty怎麽用?Java OntModel.createObjectProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.hp.hpl.jena.ontology.OntModel
的用法示例。
在下文中一共展示了OntModel.createObjectProperty方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createTagOntology
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
/**
* Create initial (empty) version of tags ontology.
*/
private OwlOntology createTagOntology() {
OwlOntology tagOntology = new OwlOntology();
OntModel ontology = tagOntology.getOntology();
// merge in former flags ontology and build tags hierarchy in parallel
String flagUris[]={
MindRaiderConstants.MR_OWL_FLAG_IMPORTANT,
MindRaiderConstants.MR_OWL_FLAG_COOL,
MindRaiderConstants.MR_OWL_FLAG_LATER,
MindRaiderConstants.MR_OWL_FLAG_OBSOLETE,
MindRaiderConstants.MR_OWL_FLAG_PROBLEM,
MindRaiderConstants.MR_OWL_FLAG_PERSONAL,
MindRaiderConstants.MR_OWL_FLAG_TODO
};
// set flags as subclass of tag, flags and set label the same as local name (it is safe)
OntClass tag= ontology.createClass(MindRaiderConstants.MR_OWL_TAG);
OntClass flag = ontology.createClass(MindRaiderConstants.MR_OWL_FLAG);
for(String flagUri: flagUris) {
//OntClass flagClass = ontology.createClass(MindRaiderConstants.MR_OWL_TAG_NS+flagUri);
OntClass flagClass = ontology.createClass(flagUri);
flagClass.addLabel(flagUri, "en");
flag.addSubClass(flagClass);
tag.addSubClass(flagClass);
}
// properties
ObjectProperty flagProperty = ontology.createObjectProperty(MindRaiderConstants.MR_OWL_PROPERTY_FLAG);
flagProperty.addRange(flag);
return tagOntology;
}
示例2: createMindRaiderOntology
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
/**
* Build MR's OWL ontology.
*
* @param ontology
* the OntModel
*/
private OwlOntology createMindRaiderOntology() {
OwlOntology mrOntology = new OwlOntology();
OntModel ontology = mrOntology.getOntology();
// MR resource type classes
OntClass mrResource = ontology.createClass(MindRaiderConstants.MR_OWL_CLASS_RESOURCE);
OntClass profile = ontology.createClass(MindRaiderConstants.MR_OWL_CLASS_PROFILE);
OntClass mindMap = ontology.createClass(MindRaiderConstants.MR_OWL_CLASS_MINDMAP);
OntClass folder = ontology.createClass(MindRaiderConstants.MR_OWL_CLASS_FOLDER);
OntClass notebook = ontology.createClass(MindRaiderConstants.MR_OWL_CLASS_NOTEBOOK);
OntClass concept = ontology.createClass(MindRaiderConstants.MR_OWL_CLASS_CONCEPT);
OntClass attachment = ontology.createClass(MindRaiderConstants.MR_OWL_CLASS_ATTACHMENT);
OntClass localAttachment = ontology.createClass(MindRaiderConstants.MR_OWL_CLASS_LOCAL_ATTACHMENT);
OntClass webAttachment = ontology.createClass(MindRaiderConstants.MR_OWL_CLASS_WEB_ATTACHMENT);
OntClass mrAttachment = ontology.createClass(MindRaiderConstants.MR_OWL_CLASS_MR_ATTACHMENT);
// taxonomy
mrResource.addSubClass(mindMap);
mrResource.addSubClass(profile);
mindMap.addSubClass(folder);
mindMap.addSubClass(notebook);
mindMap.addSubClass(concept);
mindMap.addSubClass(attachment);
attachment.addSubClass(localAttachment);
attachment.addSubClass(webAttachment);
attachment.addSubClass(mrAttachment);
// properties
ObjectProperty hasAttachment = ontology.createObjectProperty(MindRaiderConstants.MR_OWL_PROPERTY_HAS_ATTACH);
hasAttachment.addDomain(concept);
hasAttachment.addRange(attachment);
ontology.createObjectProperty(MindRaiderConstants.MR_OWL_PROPERTY_IS_DISCARDED);
return mrOntology;
}
示例3: Build
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public void Build(String path) throws IOException {
List<HNode> sortedLeafHNodes = new ArrayList<HNode>();
worksheet.getHeaders().getSortedLeafHNodes(sortedLeafHNodes);
OntModel autoOntology = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
String ns = Namespaces.KARMA;
autoOntology.setNsPrefix("karma", ns);
OntClass topClass = autoOntology.createClass( ns + worksheet.getTitle().replaceAll(" ", "_")); // replace blank spaces with undrscore
for (HNode hNode : sortedLeafHNodes){
DatatypeProperty dp = autoOntology.createDatatypeProperty(ns+hNode.getColumnName().trim().replaceAll(" ", "_"));
dp.addDomain(topClass);
dp.addRange(XSD.xstring);
}
// OntClass thingClass = autoOntology.createClass(Uris.THING_URI);
ObjectProperty op = autoOntology.createObjectProperty(ns + "relatedTo");
op.addDomain(topClass);
// op.addRange(thingClass);
Writer outUTF8 =null;
try {
outUTF8 = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(path), "UTF8"));
autoOntology.write(outUTF8, null);
outUTF8.flush();
outUTF8.close();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
示例4: test
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
@Test
public void test() {
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
// Create the Classes : animal, plant, sheep, grass, vegetarian;
OntClass animal = model.createClass(NS + "Animal");
OntClass plant = model.createClass(NS + "Plant");
OntClass sheep = model.createClass(NS + "Sheep");
OntClass grass = model.createClass(NS + "Grass");
OntClass vegetarian = model.createClass(NS + "Vegetarian");
// Set sheep as subClass of animal, set grass as subClass of plant;
animal.addSubClass(sheep);
plant.addSubClass(grass);
// Create the object property eat and part_of (there domain and range are owl:Thing);
ObjectProperty eat = model.createObjectProperty(NS + "eat");
ObjectProperty partOf = model.createObjectProperty(NS + "partOf");
// Create Restriction : eatAllGrass, set sheep as its subclass;
AllValuesFromRestriction avr = model.createAllValuesFromRestriction(null, eat, grass);
avr.addSubClass(sheep);
// Create Restriction : partofSomePlant; partofSomeAnimal;
SomeValuesFromRestriction plantPart = model.createSomeValuesFromRestriction(null, partOf, plant);
SomeValuesFromRestriction animalPart = model.createSomeValuesFromRestriction(null, partOf, animal);
// Create the Union Class meat : (animal, partofSomeAnimal);
RDFNode[] nodes1 = {animal, animalPart};
RDFList meatList = model.createList(nodes1);
UnionClass meat = model.createUnionClass(null, meatList);
// Create the Union Class vegetable : (plant, partofSomePlant):
RDFNode[] nodes2 = {plant, plantPart};
RDFList vegetableList = model.createList(nodes2);
UnionClass vegetable = model.createUnionClass(null, vegetableList);
model.write(System.out, "RDF/XML-ABBREV");
model.write(System.out, "N3");
}
示例5: 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);
}