Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registering ModelChangedListener on OntModel when using Reasoner results in no statement changed events #2868

Open
cdorn opened this issue Nov 25, 2024 · 2 comments
Labels
bug OntAPI Ontology API

Comments

@cdorn
Copy link

cdorn commented Nov 25, 2024

Version

5.1.0

What happened?

Given OntModel m with inference model:
var m = OntModelFactory.createModel( OntSpecification.OWL2_DL_MEM_RDFS_INF );

Given we register some model changed listener:
m.register(listener);

and we create a type
var type = m.createOntClass(SOMEURI);

and we delete that type:
type.deleteProperties();

then listener is not called with any deleted statements.

I also identified the cause:
inside ModelCom.register(ModelChangedListener listener) //line 1359
the getGraph() call returns the inference graph and not the underlying UnionGraph, hence any fine granular changes in the union graph and below have no listener registered

my current work around is pasted below in "Relevant output and stacktrace"
not sure if that workaround would work for other OntModel implementations and inference models.

Relevant output and stacktrace

my current workaround is:
private void register(OntModel model, ModelChangedListener listener) {
  var given = model.getGraph();
	if (given instanceof InfGraph infG) {
            Graph raw = infG.getRawGraph();
            if (raw instanceof UnionGraph ugraph) {
            	ugraph.getEventManager().register(((ModelCom)model).adapt(listener));
            }            
        }
        if (given instanceof UnionGraph ugraph) {
        	ugraph.getEventManager().register(((ModelCom)model).adapt(listener));
        }
	}

Are you interested in making a pull request?

Maybe

@cdorn cdorn added the bug label Nov 25, 2024
@afs afs added the OntAPI Ontology API label Nov 25, 2024
@sszuev
Copy link
Contributor

sszuev commented Nov 25, 2024

Feel free to create a PR or let me know if you wouldn't and I'll create it.

@cdorn
Copy link
Author

cdorn commented Nov 26, 2024

let me test and use that workaround a bit more, as I'm not sure whether in the InfGraph case, the listener should also be added the the outer InfGraph as well (and not just the UnionGraph below).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug OntAPI Ontology API
Projects
None yet
Development

No branches or pull requests

3 participants