VisualDataWeb / OWL2VOWL

Converting ontologies for WebVOWL
http://vowl.visualdataweb.org
MIT License
137 stars 50 forks source link

should consider both prefix and baseiri when checking if a class is external #34

Open FonyLi opened 7 years ago

FonyLi commented 7 years ago

Vowl marks all classes in SNOMED.owl as external. The reason is that vowl check it like this:

class ImportedChecker{
public void execute() { 
       //......
        vowlData.getEntityMap().values().forEach(abstractEntity -> {
        IRI entityIri = abstractEntity.getIri();
        if ( entityIri.toString().contains("http://owl2vowl.de#") )  {
            return;
        };

        if (ComparisonHelper.hasDifferentNameSpace(entityIri.toString(), loadedOntology, loadPath){
            addImportedAttribute(entityIri);
            }
        });
    }
}

Notice that ComparisonHelper.hasDifferentNameSpace(entityIri.toString(), loadedOntology, loadPath) only compares the class' name space with the base iri of ontology.

But from my understanding, besides base iri of ontology, the prefixes should be considered as well.

Say I have an ontology like this:

<?xml..>
<!DOCTYPE rdf:RDF [
    ...
    <!ENTITY somePrefix "http://bb.com/b.owl#" > //a prefix
    ...]
>
// a base
<rdf:RDF xmlns="http://aa.com/a.owl#"
     xml:base="http://aa.com/a.owl"
>

//a class whose name space is defined in xml:base of this ontoloyg
<owl:Class rdf:about="http://aa.com/a.owl#class_C">
        <rdfs:label xml:lang="en">class c</rdfs:label>
    </owl:Class>
//a class whose name space is defined in the prefix  of this ontoloyg
<owl:Class rdf:about="http://bb.com/b.owl#class_D">
        <rdfs:label xml:lang="en">class d</rdfs:label>
    </owl:Class>

Both class C and class D should be marked as normal class but not external class. But our current vowl will mark class D as external, which from my understanding is not correct.

A possible solution is like:

public void execute() {
        ......
        //read prefixes from ontology
        OWLDocumentFormat format = manager.getOntologyFormat(loadedOntology);
        OWLXMLDocumentFormat owlxmlFormat = new OWLXMLDocumentFormat();

        if (format.isPrefixOWLDocumentFormat()) {
            owlxmlFormat.copyPrefixesFrom(format.asPrefixOWLDocumentFormat());
        }

        //prefixes in ontology is a map of <prefixName, prefixIri>, 
                //here we ignore prefixNames and store all prefixIris into a set
        Set<String> prefixIris = new HashSet<>();
        owlxmlFormat.prefixNames().forEach(prefix -> prefixIris.add(owlxmlFormat.getPrefix(prefix)));

        vowlData.getEntityMap().values().forEach(abstractEntity -> {
            IRI entityIri = abstractEntity.getIri();
            if (entityIri.toString().contains("http://owl2vowl.de#")) {
                return;
            }

            if (ComparisonHelper.hasDifferentNameSpace(entityIri.toString(), loadedOntology, loadPath) //check if entityIri.toString() is baseiri of ontology
                    && !prefixIris.contains(entityIri.getNamespace())) { //check if entityIri's name space is in prefixes of ontology
                addImportedAttribute(entityIri);
            }
        });
    }

Please do point out if anything wrong, thanks.

Cheers, Tony

BlackDark commented 6 years ago

@steffen-l is this a valid issue?