本文整理匯總了Java中com.hp.hpl.jena.ontology.OntModel.createProperty方法的典型用法代碼示例。如果您正苦於以下問題:Java OntModel.createProperty方法的具體用法?Java OntModel.createProperty怎麽用?Java OntModel.createProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.hp.hpl.jena.ontology.OntModel
的用法示例。
在下文中一共展示了OntModel.createProperty方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的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);
// ** TASK 6.1: Create a new class named "University" **
model.createClass(ns+"University");
// ** TASK 6.2: Add "Researcher" as a subclass of "Person" **
model.getOntClass(ns+"Person").addSubClass(model.createClass(ns+"Researcher"));
// ** TASK 6.3: Create a new property named "worksIn" **
model.createProperty(ns+"worksIn");
// ** TASK 6.4: Create a new individual of Researcher named "Jane Smith" **
model.getOntClass(ns+"Researcher").createIndividual(ns+"JaneSmith");
// ** TASK 6.5: Add to the individual JaneSmith the fullName, given and family names **
model.getIndividual(ns+"JaneSmith").addProperty(VCARD.FN, "Jane Smith");
model.getIndividual(ns+"JaneSmith").addProperty(VCARD.Given, "Jane");
model.getIndividual(ns+"JaneSmith").addProperty(VCARD.Family, "Smith");
// ** TASK 6.6: Add UPM as the university where John works **
model.getIndividual(ns+"JohnSmith").addProperty(model.getProperty(ns+"worksIn"), model.getOntClass(ns+"University").createIndividual(ns+"UPM"));
model.write(System.out, "RDF/XML-ABBREV");
}
示例2: 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);
}
示例3: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的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" **
model.getOntClass(ns+"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 **
// create an instance of university for upm
Individual upm = university.createIndividual(ns+"UPM");
// complete the property
model.getIndividual(ns+"JohnSmith").addProperty(worksIn, upm);
model.write(System.out, "TURTLE");
}
示例4: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的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");
}
示例5: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public static void main(String args[])
{
String filename = "src/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" **
model.getOntClass(ns+"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 inJane = researcher.createIndividual(ns+"JaneSmith");
model.createIndividual(inJane);
// ** TASK 6.5: Add to the individual JaneSmith the fullName, given and family names **
inJane.addLiteral(VCARD.FN, "Jane Smith");
inJane.addLiteral(VCARD.Given, "Jane");
inJane.addLiteral(VCARD.Family, "Smith");
// ** TASK 6.6: Add UPM as the university where John Smith works **
Individual UPM = university.createIndividual(ns+"UPM");
Individual john = model.getIndividual(ns+"JohnSmith");
john.addProperty(worksIn, UPM);
model.write(System.out, "RDF/XML-ABBREV");
}
示例6: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public static void main(String args[])
{
String filename = "src/pruebasJena/examplesRDF/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" **
model.getOntClass(ns+"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 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,代碼行數:45,代碼來源:Task06JorgeFernandezManteca.java
示例7: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的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" **
model.getOntClass(ns+"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 **
model.getIndividual(ns+"JohnSmith").addProperty( worksin,
university.createIndividual(ns+"UPM") );
model.write(System.out, "TURTLE");
}
示例8: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的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");
}
示例9: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的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");
}
示例10: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的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");
}
示例11: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的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");
}
示例12: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public static void main(String args[])
{
String filename = "src/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" **
model.getOntClass(ns+"Person").addSubClass(researcher);
// ** TASK 6.3: Create a new property named "worksIn" **
Property worksIn = model.createProperty(ns+"worksIn");
//System.out.println("WorksIn: "+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 johnSmith = model.getIndividual(ns+"JohnSmith");
Individual upm = university.createIndividual(ns+"UPM");
//System.out.println("UPM: "+upm);
//System.out.println("JS: "+johnSmith);
johnSmith.addProperty(worksIn, upm);
model.write(System.out, "RDF/XML-ABBREV");
}
示例13: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的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");
}
示例14: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的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" **
model.getOntClass(ns+"Person").addSubClass(model.createClass(ns+"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");
Individual john = model.getIndividual(ns + "JohnSmith");
john.addProperty(worksIn, upm);
model.write(System.out, "TURTLE");
}
示例15: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的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");
}