本文整理匯總了Java中com.hp.hpl.jena.ontology.OntModel.createClass方法的典型用法代碼示例。如果您正苦於以下問題:Java OntModel.createClass方法的具體用法?Java OntModel.createClass怎麽用?Java OntModel.createClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.hp.hpl.jena.ontology.OntModel
的用法示例。
在下文中一共展示了OntModel.createClass方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testSomeMethod2
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
@Test
public void testSomeMethod2() throws Exception {
Dataset ds = TDBFactory.createDataset("/scratch/WORK2/jena/dataset2/");
OntModel model1 = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, ds.getNamedModel("vijaym1"));
OntModel model2 = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, ds.getNamedModel("vijaym2"));
OntClass thing = model1.createClass("http://www.w3.org/2002/07/owl#Thing");
model1.createIndividual("http://example.com/onto1#VijayRaj", thing);
model2.createIndividual("http://example.;cegilovcom/onto2#VijayRaj", thing);
Model m = model1.union(model2);
FileWriter fw = new FileWriter("/scratch/WORK2/jena/testModels/mergetestds.xml");
RDFDataMgr.write(fw, ds, RDFFormat.NQUADS_UTF8);
}
示例2: 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;
}
示例3: 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;
}
示例4: 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();
}
}
示例5: 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");
}
示例6: 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);
}
示例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 **
// 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");
}
示例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" **
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");
}
示例9: 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
示例10: main
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public static void main(String args[])
{
String filename = "rdf examples/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" **
OntClass person = model.createClass(ns+"Person");
ExtendedIterator<Individual> individuals = model.listIndividuals();
while (individuals.hasNext()) {
Individual individual = individuals.next();
System.out.println("Person: " + individual.getLocalName());
}
// ** TASK 7.2: List all subclasses of "Person" **
ExtendedIterator<OntClass> subClases = person.listSubClasses();
while (subClases.hasNext()) {
OntClass essaClasse = (OntClass) subClases.next();
System.out.println("Subclass: "+essaClasse.getURI());
}
// ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. TIP: you need some inference... **
ExtendedIterator<OntClass> listaSubclases = person.listSubClasses();
//Imprimiremos las subclases y las instancias de cada subclase
while (listaSubclases.hasNext()){
OntClass clase = (OntClass) listaSubclases.next();
ExtendedIterator<Individual> listaInstancias = (ExtendedIterator<Individual>) clase.listInstances();
while(listaInstancias.hasNext()){
System.out.println("Clase: "+clase.getURI()+" Nombre Instancia: "+ listaInstancias.next().getURI());
}
}
}
示例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 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");
}
示例12: 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");
}
示例13: 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");
}
示例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" **
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");
}
示例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.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");
}