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

Fix #380 and #372 #385

Merged
merged 1 commit into from
Apr 8, 2022
Merged

Fix #380 and #372 #385

merged 1 commit into from
Apr 8, 2022

Conversation

bkis
Copy link
Collaborator

@bkis bkis commented Feb 15, 2022

Possible fix for issues #380 and #372

After fighting with the debugger for two full days, I think I might have found the problem behind these two issues.
In de.unistuttgart.ims.coref.annotator.document.CoreferenceModel, when a new FeatureStructure (e.g. a Mention or Entity) is created, it is explicitly passed the respective org.apache.uima.jcas.JCas instance for the document:

protected Entity createEntity(String l) {
	Entity e = new Entity(documentModel.getJcas());
	e.setColor(colorMap.getNextColor().getRGB());
	e.setLabel(l);
	e.setFlags(new EmptyFSList<Flag>(documentModel.getJcas()));
	e.setMembers(new FSArray<Entity>(documentModel.getJcas(), 0));
	e.addToIndexes();
	return e;
}

See the call to documentModel.getJcas() above (which could be replaced by just getJCas(), but that's another issue). Later in that code, e.addToIndexes() is called, a method of org.apache.uima.cas.impl.FeatureStructureImplC:

/** add the corresponding FeatureStructure to all Cas indexes in the view where this FS was created*/
public void addToIndexes() {
	_casView.addFsToIndexes(this);
}

Here, the instance variable _casView seems to be the correct object reference. Adding the FeatureStructure to the indices works as expected. This is not the case for when e.g. a Mention (or Entity or anything else) is deleted, renamed, moved, whatever!

Here is an example: When deleting a Mention, the respective event is passed around and eventually this happens (m is the object reference to the Mention that is to be deleted):

m.removeFromIndexes();

In FeatureStructureImplC, this method acts just like the addToIndexes() we saw above: It assumes that the instance variable _casView of m holds the correct JCas reference. I am very far from understanding UIMA and its internal workings, but for me, this looks like it should work. But it doesn't. In fact, the _casView object used inside m.removeFromIndexes() is not the same as the one that's used when saving the project or exporting to CSV. I double-checked.

Now if we replace every call to addToIndexes() and removeFromIndexes() inside CoreferenceModel by addToIndexes(getJCas()) and removeFromIndexes(getJCas()), respectively (so we explicitly pass the JCas object used for the document), it all starts to work as intended:

  • deleting mentions/entities, saving/exporting the project, reopening the project --> correct state!
  • using the "Clear" or "Delete all entities" feature , reopening the project --> correct state!

Important question

Is there any case where a project/document uses multiple JCas instances? My solution assumes that the one returned by documentModel.getJcas() is the one true instance. I don't understand the project well enough, so that'd be important to check. If it's okay to just use this reference and pass it around, this PR solves those problems.


closes #380
closes #372

@bkis bkis added the bug Something isn't working label Feb 15, 2022
@bkis bkis requested a review from nilsreiter February 15, 2022 14:38
@bkis
Copy link
Collaborator Author

bkis commented Feb 15, 2022

@nilsreiter If you could give a quick answer on this last question at the end of the PR comment, I could try and merge all the PRs. By now there is a handful of fixes that would make a good improved release, I think.

@nilsreiter
Copy link
Owner

I think the only case multiple JCass are used is when documents are merged or compared. But it could be that this is handled after opening. And the annotations are not editable in then anyways.

@bkis
Copy link
Collaborator Author

bkis commented Feb 16, 2022

And as new entities are explicitly associated with the one JCas the document uses (new Entity(documentModel.getJcas())), this must be correct instance for further operations, right?

@nilsreiter nilsreiter changed the base branch from master to release/2.0.2 April 8, 2022 12:59
@nilsreiter
Copy link
Owner

nilsreiter commented Apr 8, 2022

This is related, but not exactly the same because it is concerned with document annotations: https://issues.apache.org/jira/browse/UIMA-6199

It was fixed in UIMA 3.2.0, but it doesn't help us.

@nilsreiter nilsreiter changed the base branch from release/2.0.2 to fix/380 April 8, 2022 15:18
@nilsreiter
Copy link
Owner

I don't really have another idea ...

@nilsreiter nilsreiter merged commit 7eaa515 into nilsreiter:fix/380 Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Delete all does not work properly Delete annotations of already saved and then reopened files
2 participants