本文整理汇总了Java中com.hp.hpl.jena.ontology.OntClass.addSubClass方法的典型用法代码示例。如果您正苦于以下问题:Java OntClass.addSubClass方法的具体用法?Java OntClass.addSubClass怎么用?Java OntClass.addSubClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.hp.hpl.jena.ontology.OntClass
的用法示例。
在下文中一共展示了OntClass.addSubClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addChildcategories
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
private static void addChildcategories(OntClass categoryClass) {
String categoryName = categoryClass.getLocalName();
try {
List<String> childCategoryNames = wiki.getChildCategories(categoryName);
for (String childCategoryName : childCategoryNames) {
childCategoryName = URIref.encode(childCategoryName.replace(' ', '_').replace("+", "_Plus"));
OntClass childCategoryClass = categoryClass.getOntModel().createClass(PREFIX_NS_EXPERTFINDER + childCategoryName);
categoryClass.addSubClass(childCategoryClass);
// recursively call addChildCategories
addChildcategories(childCategoryClass);
}
} catch (MediaWikiAPIException e) {
e.printStackTrace();
}
}
示例2: createTagOntology
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的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;
}
示例3: createMindRaiderOntology
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的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;
}
示例4: test
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的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.OntClass; //导入方法依赖的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);
}
示例6: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[])
{
String filename = "rdf examples/example5.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);
// Create a new class named "Researcher"
OntClass researcher = model.createClass(ns+"Researcher");
// ** TASK 6.1: Create a new class named "University" **
OntClass university = model.createClass(ns+"University");
// ** TASK 6.2: Add "Researcher" as a subclass of "Person" **
OntClass person = model.createClass(ns+"Person");
researcher.addSubClass(person);
// ** TASK 6.3: Create a new property named "worksIn" **
Property trabajaEn = model.createProperty(ns, "worksIn"); // hasName property
// ** TASK 6.4: Create a new individual of Researcher named "Jane Smith" **
Individual persona1 = researcher.createIndividual(ns+"Jane Smith");
// ** TASK 6.5: Add to the individual JaneSmith the fullName, given and family names **
persona1.addProperty(VCARD.FN, "Jane Smith"); //FN -> Full name
persona1.addProperty(VCARD.Family, "Smith"); //Family -> Apellido
persona1.addProperty(VCARD.Given, "Jane"); //Given -> Nombre
// ** TASK 6.6: Add UPM as the university where John Smith works **
Individual upm = university.createIndividual(ns+"UPM");
persona1.addProperty(trabajaEn, upm);
model.write(System.out, "RDF/XML-ABBREV");
}
示例7: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[])
{
String filename = "example5.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);
// Create a new class named "Researcher"
OntClass researcher = model.createClass(ns+"Researcher");
// ** TASK 6.1: Create a new class named "University" **
OntClass university = model.createClass(ns + "University");
// ** TASK 6.2: Add "Researcher" as a subclass of "Person" **
OntClass person = model.getOntClass(ns + "Person");
person.addSubClass(researcher);
// ** TASK 6.3: Create a new property named "worksIn" **
Property worksIn = model.createProperty(ns + "worksIn");
// ** TASK 6.4: Create a new individual of Researcher named "Jane Smith" **
Individual janeSmith = researcher.createIndividual(ns + "JaneSmith");
// ** TASK 6.5: Add to the individual JaneSmith the fullName, given and family names **
janeSmith.addLiteral(VCARD.FN, "Jane Smith");
janeSmith.addLiteral(VCARD.Given, "Jane");
janeSmith.addLiteral(VCARD.Family, "Smith");
// ** TASK 6.6: Add UPM as the university where John Smith works **
Individual johnSmith = model.getIndividual(ns + "JohnSmith");
Individual upm = university.createIndividual(ns + "UPM");
johnSmith.addProperty(worksIn, upm);
model.write(System.out, "RDF/XML-ABBREV");
System.out.println();
System.out.println("---------------------------------------");
System.out.println();
model.write(System.out, "Turtle");
}
示例8: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[])
{
String filename = "example5.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);
// Create a new class named "Researcher"
OntClass researcher = model.createClass(ns+"Researcher");
// ** TASK 6.1: Create a new class named "University" **
OntClass university = model.createClass(ns+"University");
// ** TASK 6.2: Add "Researcher" as a subclass of "Person" **
OntClass person = model.getOntClass(ns + "Person");
person.addSubClass(researcher);
// ** TASK 6.3: Create a new property named "worksIn" **
Property worksIn = model.createProperty(ns + "WorksIn");
// ** TASK 6.4: Create a new individual of Researcher named "Jane Smith" **
Individual janeSmith = researcher.createIndividual(ns + "JaneSmith");
// ** TASK 6.5: Add to the individual JaneSmith the fullName, given and family names **
janeSmith.addProperty(VCARD.FN, "Jane Smith");
janeSmith.addProperty(VCARD.Given, "Jane");
janeSmith.addProperty(VCARD.Family, "Smith");
// ** TASK 6.6: Add UPM as the university where John Smith works **
Individual upm = university.createIndividual(ns + "UPM");
model.getIndividual(ns+"JonhSmith").addProperty(worksIn, upm);
model.write(System.out, "RDF/XML-ABBREV");
}
示例9: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[])
{
String filename = "rdf examples/example5.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);
// Create a new class named "Researcher"
OntClass researcher = model.createClass(ns+"Researcher");
// ** TASK 6.1: Create a new class named "University" **
OntClass university = model.createClass(ns+"University");
// ** TASK 6.2: Add "Researcher" as a subclass of "Person" **
OntClass person = model.getOntClass(ns+"Person");
person.addSubClass(researcher);
// ** TASK 6.3: Create a new property named "worksIn" **
Property worksIn = model.createProperty(ns+"worksIn");
// ** TASK 6.4: Create a new individual of Researcher named "Jane Smith" **
Individual janeSmith = researcher.createIndividual(ns+"JaneSmith");
// ** TASK 6.5: Add to the individual JaneSmith the fullName, given and family names **
janeSmith.addLiteral(VCARD.FN,"Jane Smith");
janeSmith.addLiteral(VCARD.Given,"Jane");
janeSmith.addLiteral(VCARD.Family,"Smith");
// ** TASK 6.6: Add UPM as the university where John Smith works **
Individual johnSmith = model.getIndividual(ns+"JohnSmith");
Individual upm = university.createIndividual(ns+"UPM");
johnSmith.addProperty(worksIn, upm);
model.write(System.out, "RDF/XML-ABBREV");
}
示例10: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[])
{
String filename = "example5.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);
// Create a new class named "Researcher"
OntClass researcher = model.createClass(ns+"Researcher");
// ** TASK 6.1: Create a new class named "University" **
OntClass university = model.createClass(ns+"University");
// ** TASK 6.2: Add "Researcher" as a subclass of "Person" **
OntClass person = model.getOntClass(ns+"Person");
person.addSubClass(researcher);
// ** TASK 6.3: Create a new property named "worksIn" **
Property propiedad = model.createProperty(ns+"worksIn");
// ** TASK 6.4: Create a new individual of Researcher named "Jane Smith" **
Individual janeSmith = researcher.createIndividual(ns+"JaneSmith");
// ** TASK 6.5: Add to the individual JaneSmith the fullName, given and family names **
janeSmith.addProperty(VCARD.FN, "JaneSmith");
janeSmith.addProperty(VCARD.Given, "Jane");
janeSmith.addProperty(VCARD.Family, "Smith");
// ** TASK 6.6: Add UPM as the university where John Smith works **
Individual upm = university.createIndividual(ns+"UPM");
Individual johnSmith = model.getIndividual(ns + "JohnSmith");
johnSmith.addProperty(propiedad, upm);
//model.write(System.out, "RDF/XML-ABBREV");
model.write(System.out, "TURTLE");
}
示例11: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[])
{
String filename = "example5.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);
// Create a new class named "Researcher"
OntClass researcher = model.createClass(ns+"Researcher");
// ** TASK 6.1: Create a new class named "University" **
OntClass university = model.createClass(ns + "University");
// ** TASK 6.2: Add "Researcher" as a subclass of "Person" **
OntClass person = model.getOntClass(ns + "Person");
person.addSubClass(researcher);
// ** TASK 6.3: Create a new property named "worksIn" **
Property worksIn = model.createProperty(ns + "worksIn");
// ** TASK 6.4: Create a new individual of Researcher named "Jane Smith" **
Individual janeSmith = researcher.createIndividual(ns + "Jane Smith");
// ** TASK 6.5: Add to the individual JaneSmith the fullName, given and family names **
janeSmith.addLiteral(VCARD.FN, "Jane Smith");
janeSmith.addLiteral(VCARD.Given, "Jane");
janeSmith.addLiteral(VCARD.Family, "Smith");
// ** TASK 6.6: Add UPM as the university where John Smith works **
Individual johnSmith = model.getIndividual(ns + "JohnSmith");
Individual upm = university.createIndividual(ns + "UPM");
johnSmith.addProperty(worksIn, upm);
model.write(System.out, "RDF/XML-ABBREV");
}
开发者ID:FacultadInformatica-LinkedData,项目名称:Curso2014-2015,代码行数:48,代码来源:Task06_JoseRodriguezBueno.java
示例12: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[])
{
String filename = "example5.rdf";
// Create an empty model
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM);
// Use the FileManager to find the input file
InputStream inStr = FileManager.get().open(filename);
if (inStr == null)
throw new IllegalArgumentException("File: "+filename+" not found");
// Read the RDF/XML file
model.read(inStr, null);
// Create a new class named "Researcher"
OntClass researcher = model.createClass(ns + "Researcher");
// ** TASK 6.1: Create a new class named "University" **
OntClass university = model.createClass(ns + "University");
// ** TASK 6.2: Add "Researcher" as a subclass of "Person" **
OntClass person = model.createClass(ns + "Person");
person.addSubClass(researcher);
// ** TASK 6.3: Create a new property named "worksIn" **
Property worksIn = model.createProperty(ns+"worksIn");
// ** TASK 6.4: Create a new individual of Researcher named "Jane Smith" **
Individual janeSmith = researcher.createIndividual(ns + "JaneSmith");
// ** TASK 6.5: Add to the individual JaneSmith the fullName, given and family names **
janeSmith.addProperty(VCARD.FN, "Jane Smith");
janeSmith.addProperty(VCARD.Family, "Smith");
// ** TASK 6.6: Add UPM as the university where John Smith works **
Individual upm = university.createIndividual(ns + "UPM");
Individual johnSmith = model.getIndividual(ns + "JohnSmith");
johnSmith.addProperty(worksIn, upm);
model.write(System.out, "RDF/XML-ABBREV");
}
示例13: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[])
{
String filename = "example5.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);
// Create a new class named "Researcher"
OntClass researcher = model.createClass(ns + "Researcher");
// ** TASK 6.1: Create a new class named "University" **
OntClass university = model.createClass(ns + "University");
// ** TASK 6.2: Add "Researcher" as a subclass of "Person" **
OntClass person = model.getOntClass(ns + "Person");
person.addSubClass(researcher);
// ** TASK 6.3: Create a new property named "worksIn" **
Property worksIn = model.createProperty(ns + "worksIn");
// ** TASK 6.4: Create a new individual of Researcher named "Jane Smith" **
Individual janeSmith = researcher.createIndividual(ns + "JaneSmith");
// ** TASK 6.5: Add to the individual JaneSmith the fullName, given and family names **
janeSmith.addProperty(VCARD.FN, "JaneSmith");
janeSmith.addProperty(VCARD.Given, "Jane");
janeSmith.addProperty(VCARD.Family, "Smith");
// ** TASK 6.6: Add UPM as the university where John Smith works **
Individual upm = university.createIndividual(ns + "UPM");
model.getIndividual(ns + "JohnSmith").addProperty(worksIn, upm);
model.write(System.out, "RDF/XML-ABBREV");
}
示例14: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[])
{
String filename = "example5.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);
// Create a new class named "Researcher"
OntClass researcher = model.createClass(ns+"Researcher");
// ** TASK 6.1: Create a new class named "University" **
OntClass university = model.createClass(ns+"University");
// ** TASK 6.2: Add "Researcher" as a subclass of "Person" **
OntClass person = model.createClass(ns + "Person");
person.addSubClass(researcher);
// ** TASK 6.3: Create a new property named "worksIn" **
Property worksIn=model.createProperty(ns+"worksIn");
// ** TASK 6.4: Create a new individual of Researcher named "Jane Smith" **
Individual janeSmith =researcher.createIndividual(ns+"JaneSmith");
// ** TASK 6.5: Add to the individual JaneSmith the fullName, given and family names **
janeSmith.addLiteral(VCARD.FN, "Jane Smith");
janeSmith.addLiteral(VCARD.Given, "Jane");
janeSmith.addLiteral(VCARD.Family, "Smith");
// ** TASK 6.6: Add UPM as the university where John Smith works **
Individual johnSmith = model.getIndividual(ns+"JohnSmith");
Individual uPM= university.createIndividual(ns+"UPM");
johnSmith.addProperty(worksIn, uPM);
model.write(System.out, "RDF/XML-ABBREV");
}
示例15: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[])
{
String filename = "example5.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);
// Create a new class named "Researcher"
OntClass researcher = model.createClass(ns+"Researcher");
// ** TASK 6.1: Create a new class named "University" **
OntClass uneversity = model.createClass(ns+"Unersity");
// ** TASK 6.2: Add "Researcher" as a subclass of "Person" **
OntClass person = model.createClass();
person.addSubClass(researcher);
// ** TASK 6.3: Create a new property named "worksIn" **
Property worksIn = model.createProperty(ns+"WorksIn");
// ** TASK 6.4: Create a new individual of Researcher named "Jane Smith" **
Individual janeSmith = researcher.createIndividual(ns+"Jane Smith");
// ** TASK 6.5: Add to the individual JaneSmith the fullName, given and family names **
janeSmith.addProperty(VCARD.FN,"JaneSmith");
janeSmith.addProperty(VCARD.Given,"Jane" );
janeSmith.addProperty(VCARD.Family, "Smith");
// ** TASK 6.6: Add UPM as the university where John Smith works **
Individual upm = uneversity.createIndividual(ns+"UPM");
Individual jonhSmith = uneversity.createIndividual(ns+"John Smith");
jonhSmith.addProperty(worksIn, upm);
model.write(System.out, "TURTLE");
}