-
Notifications
You must be signed in to change notification settings - Fork 653
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
Comments
Feel free to create a PR or let me know if you wouldn't and I'll create it. |
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). |
@sszuev sorry for the delay in getting back on this issue. I realized that the workaround only works for me as a client using the OntModel as the registration call is handled by the ModelCom class in org.apache.jena.rdf.model package, with no knowledge of the UnionGraph and InfGraph , which are in the ONTAPI. |
@cdorn There are number of ways to delete triple\statement from a graph\model. The public static void main(String[] args) {
var listener = new MCL();
var m = OntModelFactory.createModel(OntSpecification.OWL2_DL_MEM_RDFS_INF);
m.register(listener);
var type = m.createOntClass("http://x");
m.remove(type.getMainStatement());
Assertions.assertEquals(1, listener.added.size());
Assertions.assertEquals(1, listener.removed.size());
}
static class MCL extends ObjectListener {
private final List<Object> added = new ArrayList<>();
private final List<Object> removed = new ArrayList<>();
@Override
public void added(Object x) {
System.out.println("added: " + x);
added.add(x);
}
@Override
public void removed(Object x) {
System.out.println("removed: " + x);
removed.add(x);
}
} |
dear @sszuev sorry for the typo, its was not #deleteProperties() but #removeProperties() , below a full example: import java.util.ArrayList; import org.apache.jena.graph.Graph; public class GraphListenerTest {
} the same behavior occurs if I replace |
perhaps to elaborate on what I like to achieve: for me the information that some properties from that resource are removed is insufficient, I need to know the exact statements, hence I'm using the StatementListener. |
This issue also exists in the Legacy Ont API. The simplest solution (and probably the most suitable one) is to use only @Override
public OntGraphModelImpl register(ModelChangedListener listener) {
getUnionGraph().getEventManager().register(adapt(listener));
return this;
} |
…unctionality: use only UnionGraph (not InfGraph) to hold graph-listeners
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
Are you interested in making a pull request?
Maybe
The text was updated successfully, but these errors were encountered: