本文整理匯總了Java中com.hp.hpl.jena.ontology.OntModel.createIndividual方法的典型用法代碼示例。如果您正苦於以下問題:Java OntModel.createIndividual方法的具體用法?Java OntModel.createIndividual怎麽用?Java OntModel.createIndividual使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.hp.hpl.jena.ontology.OntModel
的用法示例。
在下文中一共展示了OntModel.createIndividual方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: createJenaModel
import com.hp.hpl.jena.ontology.OntModel; //導入方法依賴的package包/類
public void createJenaModel(RegisterContextRequest rcr) {
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
Model entityOnt = FileManager.get().loadModel(ONT_FILE);
ontModel.addSubModel(entityOnt);
ontModel.setNsPrefixes(entityOnt.getNsPrefixMap());
// OntClass regClass = ontModel.getOntClass(ONT_URL + "iotReg");
// OntClass entClass = ontModel.createOntClass(ONT_URL + "entity");
// OntClass regClass = (OntClass) ontModel.createOntResource(OntClass.class, null,ONT_URL+"Registration" );
// OntClass regClass = (OntClass) ontModel.createClass(ONT_URL + "Registration");
// OntClass entityClass = (OntClass) ontModel.createClass(ONT_URL + "Entity");
OntClass entityClass = (OntClass) ontModel.getOntClass(ONT_URL + "Entity");
// System.out.println("Class type is: " + regClass.getLocalName());
// System.out.println(rcr.getRegistrationId());
Individual regIndividual = ontModel.createIndividual(ONT_URL + "roomSensor13CII01", entityClass);
System.out.println("has propertry \"expiry\":"+regIndividual.hasProperty(ontModel.getProperty(ONT_URL, "expiry")));
// Property p = ontModel.createProperty(ONT_URL, "hasRegistrationId");
// regIndividual.addProperty(p, "");
regIndividual.setPropertyValue(ontModel.getProperty(ONT_URL, "registrationId"), ontModel.createLiteral(rcr.getRegistrationId()));
// p = ontModel.createProperty(ONT_URL, "hasDuration");
// regIndividual.addProperty(p, "");
regIndividual.setPropertyValue(ontModel.getProperty(ONT_URL, "expiry"), ontModel.createLiteral(rcr.getDuration()));
System.out.println("has propertry \"expiry\":"+regIndividual.hasProperty(ontModel.getProperty(ONT_URL, "expiry")));
ExtendedIterator<OntProperty> iter = ontModel.listAllOntProperties();
while (iter.hasNext()) {
OntProperty ontProp = iter.next();
System.out.println(ontProp.getLocalName());
// if (formParams.containsKey(ontProp.getLocalName())) {
// regIndividual.addProperty(ontProp, ontModel.getcreateTypedLiteral(formParams.get(ontProp.getLocalName())[0]));
// }
}
ontModel.write(System.out, "TURTLE");
// ontModel.write(System.out, "RDF/XML");
// ontModel.write(System.out, "JSON-LD");
}
示例3: 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");
}