本文整理汇总了Java中com.hp.hpl.jena.ontology.OntClass.listSubClasses方法的典型用法代码示例。如果您正苦于以下问题:Java OntClass.listSubClasses方法的具体用法?Java OntClass.listSubClasses怎么用?Java OntClass.listSubClasses使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.hp.hpl.jena.ontology.OntClass
的用法示例。
在下文中一共展示了OntClass.listSubClasses方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findAllLabels
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public LinkedList<SemanticConcept> findAllLabels(String ontologyUri,String rootClass){
LinkedList<SemanticConcept> list = new LinkedList<>();
try{
//Create a reasoner
OntModel model = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
//Create new URL of ontology
URL url = new URL(ontologyUri);
//Create model for the ontology
model.read(url.openStream(),null);
//Load model to the reasoner
model.prepare();
//Compute the classification tree
((PelletInfGraph) model.getGraph()).getKB().classify();
//Set OWL root element (e.g., it could be thing: model.getOntClass(OWL.Thing.getURI()))
OntClass owlRoot = model.getOntClass(rootClass);
SemanticConcept sc = new SemanticConcept();
sc.setUrl(owlRoot.getURI());
sc.setName("");
sc.setSemanticSimilarity("");
list.add(sc);
//For each subclass (direct or indirect)
for (Iterator it = owlRoot.listSubClasses(false); it.hasNext();) {
OntClass subclass = (OntClass) it.next();
//If subclass is not anonymous
if (!subclass.isAnon()) {
//If subclass is not nothing
if(!subclass.getURI().equals(com.hp.hpl.jena.vocabulary.OWL.Nothing.getURI())){
sc = new SemanticConcept();
sc.setUrl(subclass.getURI());
sc.setName("");
sc.setSemanticSimilarity("");
list.add(sc);
}
}
}
}catch(IOException ex){}
return list;
}
示例2: getSubClasses
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
/**
* Returns an iterator over all subclasses of the class specified by the
* given uri or an empty iterator if no such class exists or if it has no
* subclasses.
*
* @param uri
* @return an iterator over all super classes of the class specified by the
* given uri or an empty iterator if no such class exists or if it
* has no super classes.
*/
@SuppressWarnings("unchecked")
public Iterator<OntClass> getSubClasses(String uri) {
OntModel model = OntologyIndex.get().getModel();
OntClass clazz = model.getOntClass(uri);
if (clazz != null) {
return clazz.listSubClasses(true);
}
return EmptyIterator.INSTANCE;
}
示例3: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[]) {
TEOJENACalendarAnalyzer analyzer = new TEOJENACalendarAnalyzer();
String fileName = "src/test/resources/TEO/TEO_1.1.0.owl";
analyzer.load(fileName);
// test case - all defined Federal Holidays
String classStr = CalendarConstants.getWithNS("TEO_0000017"); // federal holidays
OntClass rootClass = analyzer.getModel().getOntClass(classStr);
ExtendedIterator<OntClass> subClsItor = rootClass.listSubClasses(true);
int testYear = 2019;
DateConstraint yearConstraint = new DateConstraint();
yearConstraint.setMaxYear(testYear);
yearConstraint.setMinYear(testYear);
ArrayList<String> dates = null;
OntClass subCls = null;
while (subClsItor.hasNext()) {
try {
subCls = subClsItor.next();
dates = analyzer.getSpecialDateInstances(subCls.toString(), yearConstraint);
for (String date : dates) {
System.out.println("Possible dates of \"" + subCls.getLabel(null) + "\" in year = " + testYear + " are: " + date);
System.out.println();
}
} catch (TEOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
示例4: checkForSubClassCardinalityExistence
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
private boolean checkForSubClassCardinalityExistence(com.hp.hpl.jena.rdf.model.Resource sr, OntClass subjClass,
Property prop, SadlResource propResource) throws InvalidTypeException {
ExtendedIterator<OntClass> ei = subjClass.listSubClasses();
while (ei.hasNext()) {
OntClass subClass = ei.next();
if (checkForCardinalityExistence(sr, subClass, prop, propResource)) {
return true;
}
if (checkForSubClassCardinalityExistence(sr, subClass, prop, propResource)) {
return true;
}
}
return false;
}
示例5: loadViaOntology
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
private Set<String> loadViaOntology(String ontString) {
Set<String> toLoadInto = new HashSet<>();
OntClass oc = this.model.getOntClass(this.toURI(ontString));
if (oc == null)
return toLoadInto;
ExtendedIterator<OntClass> ei = oc.listSubClasses(false);
while (ei.hasNext()) {
OntClass occ = ei.next();
toLoadInto.add(occ.getLocalName());
}
return toLoadInto;
}
示例6: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的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.getOntClass(ns+"Person");
ExtendedIterator<? extends OntResource> it = person.listInstances();
System.out.println("List of all the individuals of Person");
while (it.hasNext()){
System.out.println(it.next());
}
// ** TASK 7.2: List all subclasses of "Person" **
it = person.listSubClasses();
System.out.println("List of all the subclasses of Person");
while (it.hasNext()){
System.out.println(it.next());
}
// ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. TIP: you need some inference... **
// not yet
}
示例7: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[])
{
String filename = "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.getOntClass(ns + "Person");
ExtendedIterator<Individual> personIter = model.listIndividuals(person);
while (personIter.hasNext()) {
Individual indiv = personIter.next();
System.out.println("Individual uri = " + indiv.getURI());
}
// ** TASK 7.2: List all subclasses of "Person" **
ExtendedIterator<OntClass> personsubclasses = person.listSubClasses();
while (personsubclasses.hasNext()) {
OntClass subclass = personsubclasses.next();
System.out.println("Subclass uri = " + subclass.getURI());
}
// ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. TIP: you need some inference... **
}
示例8: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[])
{
String filename = "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.getOntClass(ns + "Person");
ExtendedIterator<Individual> listaInd = model.listIndividuals(person);
while (listaInd.hasNext())
{
System.out.println("Individual: " + listaInd.next());
}
// ** TASK 7.2: List all subclasses of "Person" **
ExtendedIterator<OntClass> listaSub = person.listSubClasses();
while (listaSub.hasNext())
{
System.out.println("Individual: " + listaSub.next());
}
// ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. TIP: you need some inference... **
}
示例9: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
String filename = "example7.rdf";
String namespace = "www.example.org/resources#";
// 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 personClass = model.getOntClass(namespace + "Person");
ExtendedIterator<? extends OntResource> personInstances = personClass.listInstances();
OntResource person;
while(personInstances.hasNext()) {
person = personInstances.next();
System.out.println("Person Instance: " + person.getURI());
}
// Task 7.1: List all subclasses of "Person"
ExtendedIterator<? extends OntResource> subclassesOfPerson = personClass.listSubClasses();
OntResource personSubclass;
while(subclassesOfPerson.hasNext()) {
personSubclass = subclassesOfPerson.next();
System.out.println("Person Subclasse: " + personSubclass.getURI());
}
// Task 7.2: Make the necessary changes to get as well indirect instances and subclasses
ExtendedIterator<? extends OntResource> indirectPersons = personClass.listInstances(false);
OntResource indirectPerson;
while(indirectPersons.hasNext()) {
indirectPerson = indirectPersons.next();
if( !indirectPerson.hasRDFType(personClass, true) )
System.out.println("Person Indirect Intance: " + indirectPerson.getURI());
}
/* ------------------------------------------------ */
ExtendedIterator<? extends OntResource> indirectSubclassesOfPerson = personClass.listSubClasses(false);
OntResource indirectPersonSubclass;
while(indirectSubclassesOfPerson.hasNext()) {
indirectPersonSubclass = indirectSubclassesOfPerson.next();
if( !indirectPersonSubclass.asClass().isSameAs(personClass) )
System.out.println("Person Indirect Subclass: " + indirectPersonSubclass.getURI());
}
}
示例10: loadViaOntology
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
private Set<String> loadViaOntology(String ontString) {
Set<String> toLoadInto = new HashSet<>();
OntClass oc = this.model.getOntClass(this.toURI(ontString));
ExtendedIterator<OntClass> ei = oc.listSubClasses(false);
while (ei.hasNext()) {
OntClass occ = ei.next();
toLoadInto.add(occ.getLocalName());
}
return toLoadInto;
}
示例11: createTree
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
private Node createTree(OntClass owlClass) {
//If is a class Nothing, return null
if(owlClass.getURI().equals(com.hp.hpl.jena.vocabulary.OWL.Nothing.getURI()))
return null;
//Create new node, and set name and url
Node node = new Node();
node.setName(owlClass.getLabel(null));
node.setUrl(owlClass.getURI());
//Create list of processed subclasses
HashMap<String,String> processedSubclasses = new HashMap<>();
//For each direct subclass
for(Iterator it=owlClass.listSubClasses(true);it.hasNext();){
OntClass subclass = (OntClass) it.next();
//If subclass is not anonymous
if(!subclass.isAnon()){
//If subclass was not already processed
if(!processedSubclasses.containsKey(subclass.getURI())){
//Recursively call method "createTree" to process subclass
Node subNode = createTree(subclass);
//If subclass is not owl:Nothing, create add subclass to parent node. Otherwise, the returned node is null
if(subNode != null) {
//Add subclass node to parent node
node.getChildrenNode().add(subNode);
//Add subclass to list of processed subclasses
processedSubclasses.put(subNode.getUrl(),subNode.getName());
}
}
}
}
return node;
}
示例12: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的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());
}
}
}
示例13: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[])
{
String filename = "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" **
Resource individ = model.getResource(ns + "Person");
ExtendedIterator<Individual> iter = model.listIndividuals(individ);
while(iter.hasNext())
{
System.out.println("Persons: " + iter.next().getURI());
}
// ** TASK 7.2: List all subclasses of "Person" **
OntClass person = model.getOntClass(ns + "Person");
ExtendedIterator<? extends OntResource> iter2 = person.listInstances();
iter2 = person.listSubClasses();
while(iter2.hasNext())
{
OntClass subclass = (OntClass)iter2.next();
System.out.println("subclasses of Person: " + subclass);
}
// ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. TIP: you need some inference... **
}
示例14: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[]) {
String filename = "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" **
System.out.println("TASK 7.1");
OntClass person = model.getOntClass(ns + "Person");
ExtendedIterator<Individual> iterator = model.listIndividuals(person);
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
// ** TASK 7.2: List all subclasses of "Person" **
System.out.println("TASK 7.2");
ExtendedIterator<OntClass> listSubClass = person.listSubClasses();
while (listSubClass.hasNext()) {
System.out.println(listSubClass.next());
}
// ** TASK 7.3: Make the necessary changes to get as well indirect
// instances and sutbclasses. TIP: you need some inference... **
System.out.println("TASK 7.3");
listSubClass = person.listSubClasses();
while (listSubClass.hasNext()) {
OntClass ont = listSubClass.next();
ExtendedIterator<? extends OntResource> iter = ont
.listInstances();
while (iter.hasNext()) {
System.out.println(ont.toString()+ " Tiene como instancia: "+iter.next());
}
}
}
开发者ID:FacultadInformatica-LinkedData,项目名称:Curso2014-2015,代码行数:52,代码来源:MiguelOrtegaMoreno_Task07.java
示例15: main
import com.hp.hpl.jena.ontology.OntClass; //导入方法依赖的package包/类
public static void main(String args[])
{
String filename = "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.getOntClass(ns+"Person");
ExtendedIterator<Individual> it=model.listIndividuals(person);
if(it.hasNext())
{
Individual auxind = it.next();
System.out.println("Person: "+auxind.getLocalName());
}
// ** TASK 7.2: List all subclasses of "Person" ** //
System.out.println("TASK 7.2: List all subclasses of ");
ExtendedIterator<OntClass> it2 =person.listSubClasses();
if(it2.hasNext())
{
OntClass auxclass = it2.next();
System.out.println("Lista de Subclasses "+auxclass.getSubClass().getLocalName());
}
// ** TASK 7.3: Make the necessary changes to get as well indirect instances and subclasses. TIP: you need some inference... **
//model.write(System.out, "TURTLE");
}