owlcs / jfact

JFact repository
13 stars 8 forks source link

getObjectLabel does not work (not returning simple concepts) #25

Open boborova3 opened 2 years ago

boborova3 commented 2 years ago

Hello, I was working with KnowledgeEplorer a bit and found some potential bugs in the method addC in the class KnowledgeExplorer. I guess there should be p.getpName() instead of p.getId(), because p.getId() is always 0, thus everything is filtered out.

I do not know about the individual case, because it does not seem that label includes IndividualName but nominals, ObjectOfOne, so the synonyms are not added if there is an equal individual.

I was not sure if I should repair it and commit changes. I do not want to mess it up though.

I also published this issue on StackOverflow: https://stackoverflow.com/questions/72716584/jfact-knowledgeexplorer-getobjectlabel-does-not-return-simple-concepts

My suggested solution is:

private void addC(Expression e) {
        // check named concepts
        if (e instanceof ConceptName) {
            cs.get((ConceptName) e).stream().filter(p -> p.getpName() != 0)
                    .forEach(p -> concepts.add(d2i.getCExpr(p.getpName())));
            return;
        }

        // check named individuals
        if (e instanceof IndividualName) {
            is.get((IndividualName) e).forEach(p -> concepts.add(d2i.getCExpr(p.getpName())));
            return;
        }

        if (e instanceof ConceptOneOf) {
           List<IndividualName> list = ((ConceptOneOf) e).getArguments();
            for (IndividualName i : list) {
                is.get(i).stream()
                        .forEach(p -> concepts.add(d2i.getCExpr(p.getpName())));
            }
            return;
        }
        concepts.add(e);
}