Dear Mr Taiden,

the code below I used to create an ontology tree into my application. Maybe
this can hep you:

ExtendedIterator<OntClass> i = ontModel.listClasses();
        while (i.hasNext()) {
            OntClass ontClass = (OntClass) i.next();
            String prefix =
ontModel.getNsURIPrefix(ontClass.getNameSpace());
            String name = ontClass.getLocalName();

            if (classes.get(name + prefix) == null) {
                Class_ c = new Class_(prefix, name);
                classes.put(prefix + name, c);
                mapPrefixes.put(prefix, ontClass.getNameSpace());

                OntClass superClass = ontClass.getSuperClass();
                if (superClass != null) {
                    String superName = superClass.getLocalName();
                    String superPrefix =
ontModel.getNsURIPrefix(superClass.getNameSpace());
                    Class_ superC = classes.get(superPrefix + superName);

                    if (superC == null) {
                        superC = new Class_(superPrefix, superName);
                        classes.put(superPrefix + superName, superC);
                        mapPrefixes.put(superPrefix,
superClass.getNameSpace());
                    }

                    c.setSuperClass(superC);
                }
            }
        }

        ExtendedIterator<DatatypeProperty> i2 = ontModel
                .listDatatypeProperties();
        while (i2.hasNext()) {
            DatatypeProperty datatypeProperty = (DatatypeProperty)
i2.next();

            if (datatypeProperty.getDomain() != null &&
datatypeProperty.getRange() != null) {
                String dClassPrefix =
ontModel.getNsURIPrefix(datatypeProperty.getDomain().getNameSpace());
                String dClassName =
datatypeProperty.getDomain().getLocalName();
                Class_ dClass = classes.get(dClassPrefix + dClassName);
                String dpName = datatypeProperty.getLocalName();
                String dpPrefix =
ontModel.getNsURIPrefix(datatypeProperty.getNameSpace());
                String rangeName =
datatypeProperty.getRange().getLocalName();

                DataProperty dp = new DataProperty(dpPrefix, dpName,
dClass, rangeName);
                if (dClass != null) {
                    dClass.getdProperties().add(dp);
                    mapPrefixes.put(dpPrefix,
datatypeProperty.getNameSpace());
                }
            }
        }

        ExtendedIterator<com.hp.hpl.jena.ontology.ObjectProperty> i3 =
ontModel.listObjectProperties();
        while (i3.hasNext()) {
            ObjectProperty objectProperty = (ObjectProperty) i3.next();

            if (objectProperty.getDomain() != null &&
objectProperty.getRange() != null) {
                String dClassPrefix =
ontModel.getNsURIPrefix(objectProperty.getDomain().getNameSpace());
                String dClassName =
objectProperty.getDomain().getLocalName();
                String rClassPrefix =
ontModel.getNsURIPrefix(objectProperty.getDomain().getNameSpace());
                String rClassName =
objectProperty.getRange().getLocalName();
                String opName = objectProperty.getLocalName();
                String opPrefix =
ontModel.getNsURIPrefix(objectProperty.getNameSpace());

                Class_ dClass = classes.get(dClassPrefix + dClassName);
                Class_ rClass = classes.get(rClassPrefix + rClassName);

                ObjProperty op = new ObjProperty(opPrefix, opName, dClass,
rClass);
                if (dClass != null) {
                    dClass.getoProperties().add(op);
                    mapPrefixes.put(opPrefix,
objectProperty.getNameSpace());
                }
            }
        }



2013/4/20 aar thi <[email protected]>

>   Set<String> prop = new HashSet<String>();
>            ExtendedIterator rootIterator =
> classname.listDeclaredProperties();
>         int i=0;
>         while (rootIterator.hasNext()){
>             OntProperty ontRoot = (OntProperty) rootIterator.next();
>             String properties = ontRoot.toString();
>             int propertyLength = properties.length();
>                 int propertyIndex = properties.lastIndexOf("#");
>             if (propertyIndex != -1){
>                 String property = properties.substring(propertyIndex+1,
>  propertyLength);
>                 prop.add(property);
>             }
>         }
>
>          but this code display a property again and again.... i used to get
> a single property multiple times.. how to avoid that?
>
>
> On Fri, Apr 19, 2013 at 2:48 PM, Andy Seaborne <[email protected]> wrote:
>
> > On 19/04/13 19:21, aar thi wrote:
> >
> >> hi i'm doing a small project in ontology,  i  need to retrieve all the
> >> property names present in a particular class in the ontology. some one
> >> help
> >> me to do that in jena
> >>
> >>
> > What have you tried?
> >
> >
> >
>



-- 
Um abraço,
Luís Eufrasio T. Neto
MSN: [email protected]

"Ser LIVRE é ser capaz de AMAR sem exigir nada em troca."

Reply via email to