There are a couple of possibilities you might consider:

1)      Create subproperties of date for use with each different class. This is 
probably the best approach, as you won’t get confused with your properties, and 
the property name (publishDate, eventDate) would indicate what it’s used for.

2)      Create a union of the classes (Datable?), and define the domain to be 
the union class.


From: Luis Eufrasio Teixeira Neto [mailto:[email protected]]
Sent: Wednesday, September 04, 2013 9:01 AM
To: [email protected]
Subject: Help loading Ontology

Dear All,

I am trying to load an Ontology (attached) where there are classes with the 
same datatype property. For example:

foaf:Document  a       owl:Class , rdfs:Class ;
      rdfs:label "foaf:Document" ;
      rdfs:subClassOf [ a owl:Restriction ;
            owl:onProperty dc:creator ;
            owl:maxCardinality "2"^^<http://www.w3.org/2001/XMLSchema#int>
      ] .

dc:title
      a       rdf:Property , owl:DatatypeProperty ;
      rdfs:domain foaf:Document;
      rdfs:label "dc:title" ;
      rdfs:range xsd:string .

dc:date
      a       rdf:Property , owl:DatatypeProperty ;
      rdfs:domain foaf:Document;
      rdfs:label "dc:date" ;
      rdfs:range xsd:string .

and

conf:Conference  a       owl:Class , rdfs:Class ;
      rdfs:label "conf:Conference" .

rdfs:label
      a       rdf:Property , owl:DatatypeProperty ;
      rdfs:domain conf:Conference;
      rdfs:label "rdfs:label" ;
      rdfs:range xsd:string .

dc:date
      a       rdf:Property , owl:DatatypeProperty ;
      rdfs:domain conf:Conference;
      rdfs:label "dc:date" ;
      rdfs:range xsd:string .

So datatype property dc:date is reused into classes foaf:Document and 
conf:Conference.

The problem is: when I load the ontology the datatype porperty dc:date only 
appears one time with conf:Conference as domain class.

I need that it appears for the two classes. Below follows the code I wrote for 
loading it:

        OntModel ontModel = ModelFactory
                .createOntologyModel(OntModelSpec.OWL_MEM);
        String filePath = mc.getOntologyFilePath();
        if (filePath != null && !"".equals(filePath)) {
            ontModel.read(new FileInputStream(new File(filePath)),
                    "http://ufc.br/rdb2rdfmb/";, mc.getOntologyLang());
        } else {
            ontModel.read(mc.getOntologyURL(), mc.getOntologyLang());
        }

        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());
                }
            }
        }

--
Kind Regards,
Luís Eufrasio T. Neto
MSN: [email protected]<mailto:[email protected]>

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

Reply via email to