On 09/09/14 07:40, huang huiliang wrote:
I'm creating an ontology from excel files and I have some problems to make my program work.The first problem I encounter is that I can't get the right superclass .The simplest code example is below. Code begin: OntModel individuals = ModelFactory.createOntologyModel(); TreeMap<String, String> namespaces=new TreeMap<String,String>(); namespaces.put("pubo", "http://www.xxx.org.cn/standards/publishing/ontology/cores/"); individuals.setNsPrefixes(namespaces); OntClass class1=individuals.createClass(namespaces.get("pubo")+"class1"); class1.setLabel("class1", "en"); OntClass class2=individuals.createClass(namespaces.get("pubo")+"class2"); class2.setLabel("class2", "en"); class2.setSuperClass(class1); System.out.println(class2.getSuperClass().getURI()); DatatypeProperty p = individuals.createDatatypeProperty(namespaces .get("pubo") + "haha"); p.addDomain(class2); System.out.println(class2.getSuperClass().getURI()); Code end The first output is: <http://www.xxx.org.cn/standards/publishing/ontology/cores/class1> http://www.xxx.org.cn/standards/publishing/ontology/cores/class1 The second output is : http://www.w3.org/2000/01/rdf-schema#Resource I have no idea why the two output are different? Have I done something wrong? Any suggestions?
Mostly likely possibility is that getSuperClass is simply picking a different random value from the set of super classes (see the javadoc). I don't know if getSuperClass is supposed to list only direct superclasses but if you are getting rdfs:Resource then probably not.
Suggest using listSuperClasses(true) to find out what's going on. Dave
