Skip to content

Commit e443aa8

Browse files
author
Nils Reiter
committed
Merge branch 'release/1.14.5'
* release/1.14.5: changelog update 1.14.5 fixed test issue Updated changelog fixes #352 changelog fixes #350 fixes #347 enable pretty print when serializing .xmi; related to #339 replacing now also works from context menu; fixes #345; related to #149 Bump build-helper-maven-plugin from 3.0.0 to 3.2.0 Bump maven-antrun-plugin from 1.8 to 3.0.0 Bump maven-shade-plugin from 3.2.1 to 3.2.4 Bump mockito-core from 3.1.0 to 3.4.4 1.15.0-SNAPSHOT Bump plexus-archiver from 4.1.0 to 4.2.2 Bump version.javafx from 13.0.1 to 13.0.2 Bump reflections from 0.9.11 to 0.9.12 Bump guava from 28.1-jre to 28.2-jre
2 parents 52171a0 + 1990e97 commit e443aa8

File tree

6 files changed

+137
-40
lines changed

6 files changed

+137
-40
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
Issue numbers (e.g., #43) refer to GitHub issues:
44
https://github.com/nilsreiter/CorefAnnotator/issues
55

6+
## 1.14.5
7+
8+
- Fixed behaviour of de-emphasising singletons. Thanks @andreasvc #347
9+
- Fixed upating of status bar if selection changes #350
10+
- Fixed the bug that prevented automatically removing empty entities #352
11+
- XMI files are now pretty printed, making them more git-friendly.
12+
Thanks @andreasvc #339
13+
614
## 1.14.4
715

816
- Fixed a bug caused by old flags no longer being generated

pom.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>de.unistuttgart.ims</groupId>
66
<artifactId>coref.annotator</artifactId>
7-
<version>1.14.4</version>
7+
<version>1.14.5</version>
88
<packaging>jar</packaging>
99
<name>CorefAnnotator</name>
1010
<url>https://github.com/nilsreiter/CorefAnnotator/</url>
@@ -15,7 +15,7 @@
1515
<version.eclipse>9.2.0</version.eclipse>
1616
<maven.compiler.source>1.8</maven.compiler.source>
1717
<maven.compiler.target>1.8</maven.compiler.target>
18-
<version.javafx>13.0.1</version.javafx>
18+
<version.javafx>13.0.2</version.javafx>
1919
</properties>
2020
<build>
2121
<plugins>
@@ -87,7 +87,7 @@
8787
<plugin>
8888
<groupId>org.apache.maven.plugins</groupId>
8989
<artifactId>maven-shade-plugin</artifactId>
90-
<version>3.2.1</version>
90+
<version>3.2.4</version>
9191
<configuration>
9292
<transformers>
9393
<transformer
@@ -189,7 +189,7 @@
189189
<plugins>
190190
<plugin>
191191
<artifactId>maven-antrun-plugin</artifactId>
192-
<version>1.8</version>
192+
<version>3.0.0</version>
193193
<executions>
194194
<execution>
195195
<id>duplicate build directory</id>
@@ -231,7 +231,7 @@
231231
<dependency>
232232
<groupId>org.codehaus.plexus</groupId>
233233
<artifactId>plexus-archiver</artifactId>
234-
<version>4.1.0</version>
234+
<version>4.2.2</version>
235235
</dependency>
236236
<dependency>
237237
<groupId>org.apache.velocity</groupId>
@@ -253,7 +253,7 @@
253253
<plugin>
254254
<groupId>org.codehaus.mojo</groupId>
255255
<artifactId>build-helper-maven-plugin</artifactId>
256-
<version>3.0.0</version>
256+
<version>3.2.0</version>
257257
<executions>
258258
<execution>
259259
<id>quadrama-add-source</id>
@@ -317,7 +317,7 @@
317317
<plugin>
318318
<groupId>org.codehaus.mojo</groupId>
319319
<artifactId>build-helper-maven-plugin</artifactId>
320-
<version>3.0.0</version>
320+
<version>3.2.0</version>
321321
<executions>
322322
<execution>
323323
<id>creta-add-source</id>
@@ -365,7 +365,7 @@
365365
<plugin>
366366
<groupId>org.codehaus.mojo</groupId>
367367
<artifactId>build-helper-maven-plugin</artifactId>
368-
<version>3.0.0</version>
368+
<version>3.2.0</version>
369369
<executions>
370370
<execution>
371371
<id>sfb1391-add-source</id>
@@ -499,7 +499,7 @@
499499
<dependency>
500500
<groupId>com.google.guava</groupId>
501501
<artifactId>guava</artifactId>
502-
<version>28.1-jre</version>
502+
<version>28.2-jre</version>
503503
</dependency>
504504

505505
<dependency>
@@ -525,7 +525,7 @@
525525
<dependency>
526526
<groupId>org.reflections</groupId>
527527
<artifactId>reflections</artifactId>
528-
<version>0.9.11</version>
528+
<version>0.9.12</version>
529529
</dependency>
530530
<dependency>
531531
<groupId>org.apache.commons</groupId>
@@ -594,7 +594,7 @@
594594
<dependency>
595595
<groupId>org.mockito</groupId>
596596
<artifactId>mockito-core</artifactId>
597-
<version>3.1.0</version>
597+
<version>3.4.4</version>
598598
<scope>test</scope>
599599
</dependency>
600600
<dependency>

src/main/java/de/unistuttgart/ims/coref/annotator/DocumentWindow.java

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -760,13 +760,26 @@ public void showSearch() {
760760
searchPanel.setVisible(true);
761761
}
762762

763+
@Override
764+
protected void entityEventAdd(FeatureStructureEvent event) {
765+
super.entityEventAdd(event);
766+
updateStatusBar();
767+
}
768+
769+
@Override
770+
protected void entityEventRemove(FeatureStructureEvent event) {
771+
super.entityEventRemove(event);
772+
updateStatusBar();
773+
}
774+
763775
@Override
764776
protected void entityEventMove(FeatureStructureEvent event) {
765777
for (FeatureStructure fs : event)
766778
if (fs instanceof Mention) {
767779
highlightManager.unUnderline((Annotation) fs);
768780
highlightManager.underline((Mention) fs, new Color(((Entity) event.getArgument2()).getColor()));
769781
}
782+
updateStatusBar();
770783
}
771784

772785
@Override
@@ -910,6 +923,33 @@ public void updateStyle(Object constant, Object value) {
910923
switchStyle(currentStyle);
911924
}
912925

926+
protected void updateStatusBar() {
927+
int low = Math.min(textPane.getSelectionStart(), textPane.getSelectionEnd());
928+
int high = Math.max(textPane.getSelectionStart(), textPane.getSelectionEnd());
929+
930+
MutableSet<Mention> mentions = Sets.mutable.empty();
931+
if (getDocumentModel() != null && getDocumentModel().getCoreferenceModel() != null) {
932+
933+
// nothing is selected: show all mentions cursor is part of
934+
MutableSet<? extends Annotation> annotations = Sets.mutable
935+
.withAll(getDocumentModel().getCoreferenceModel().getMentions(low));
936+
mentions = annotations.selectInstancesOf(Mention.class);
937+
938+
// something is selected
939+
if (low != high) {
940+
ImmutableSet<Mention> ms = getDocumentModel().getCoreferenceModel().getMentionsBetween(low, high)
941+
.selectInstancesOf(Mention.class);
942+
mentions.addAllIterable(ms);
943+
}
944+
setCollectionPanel(mentions.collect(m -> {
945+
EntityPanel ep = new EntityPanel(getDocumentModel(), m.getEntity());
946+
Annotator.app.getPreferences().addPreferenceChangeListener(ep);
947+
getDocumentModel().getCoreferenceModel().addCoreferenceModelListener(ep);
948+
return ep;
949+
}));
950+
}
951+
}
952+
913953
@Override
914954
public void switchStyle(StylePlugin sv) {
915955
switchStyle(sv, sv.getBaseStyle());
@@ -1480,34 +1520,10 @@ class TextCaretListener implements CaretListener {
14801520

14811521
@Override
14821522
public void caretUpdate(CaretEvent e) {
1483-
int dot = e.getDot();
1484-
int mark = e.getMark();
1485-
int low = Math.min(dot, mark);
1486-
int high = Math.max(dot, mark);
1487-
1488-
MutableSet<Mention> mentions = Sets.mutable.empty();
1489-
if (getDocumentModel() != null && getDocumentModel().getCoreferenceModel() != null) {
1490-
1491-
// nothing is selected: show all mentions cursor is part of
1492-
MutableSet<? extends Annotation> annotations = Sets.mutable
1493-
.withAll(getDocumentModel().getCoreferenceModel().getMentions(low));
1494-
mentions = annotations.selectInstancesOf(Mention.class);
1495-
1496-
// something is selected
1497-
if (dot != mark) {
1498-
ImmutableSet<Mention> ms = getDocumentModel().getCoreferenceModel().getMentionsBetween(low, high)
1499-
.selectInstancesOf(Mention.class);
1500-
mentions.addAllIterable(ms);
1501-
}
1502-
setCollectionPanel(mentions.collect(m -> {
1503-
EntityPanel ep = new EntityPanel(getDocumentModel(), m.getEntity());
1504-
Annotator.app.getPreferences().addPreferenceChangeListener(ep);
1505-
getDocumentModel().getCoreferenceModel().addCoreferenceModelListener(ep);
1506-
return ep;
1507-
}));
1508-
}
1523+
1524+
updateStatusBar();
15091525
if (getDocumentModel() != null)
1510-
highlightSegmentInTOC(dot);
1526+
highlightSegmentInTOC(e.getDot());
15111527

15121528
}
15131529

@@ -1607,7 +1623,13 @@ else if (anno instanceof DetachedMentionPart)
16071623
mi.addActionListener(new ActionListener() {
16081624
@Override
16091625
public void actionPerformed(ActionEvent e) {
1610-
getDocumentModel().edit(new AddMentionsToEntity(entity, getSelection()));
1626+
if (Annotator.app.getPreferences().getBoolean(Constants.CFG_REPLACE_MENTION, false)
1627+
&& getSelectedAnnotations(Mention.class).size() == 1) {
1628+
getDocumentModel().edit(
1629+
new MoveMentionsToEntity(entity, getSelectedAnnotations(Mention.class)));
1630+
} else {
1631+
getDocumentModel().edit(new AddMentionsToEntity(entity, getSelection()));
1632+
}
16111633
}
16121634
});
16131635
mi.setIcon(FontIcon.of(MaterialDesign.MDI_ACCOUNT, new Color(entity.getColor())));

src/main/java/de/unistuttgart/ims/coref/annotator/document/CoreferenceModel.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,13 @@ protected synchronized void edit(CoreferenceModelOperation operation) {
320320
return addTo(op.getEntity(), sp);
321321
}));
322322
fireEvent(Event.get(this, Event.Type.Add, op.getEntity(), op.getMentions()));
323+
int newNumberOfMentions = getSize(op.getEntity());
324+
// may trigger underlining in gray if singleton
325+
if (getSpecialHandlingForSingletons() && newNumberOfMentions - op.getMentions().size() == 1
326+
&& newNumberOfMentions > 1) {
327+
fireEvent(Event.get(this, Event.Type.Update, op.getEntity()));
328+
fireEvent(Event.get(this, Event.Type.Update, get(op.getEntity())));
329+
}
323330
} else if (operation instanceof AttachPart) {
324331
AttachPart op = (AttachPart) operation;
325332
op.setPart(addTo(op.getMention(), op.getSpan()));
@@ -328,6 +335,21 @@ protected synchronized void edit(CoreferenceModelOperation operation) {
328335
MoveMentionsToEntity op = (MoveMentionsToEntity) operation;
329336
op.getMentions().forEach(m -> moveTo(op.getTarget(), m));
330337
fireEvent(Event.get(this, Event.Type.Move, op.getSource(), op.getTarget(), op.getMentions()));
338+
// may trigger underlining in gray if singleton
339+
if (getSpecialHandlingForSingletons()) {
340+
int numberOfMentionsMoved = op.getMentions().size();
341+
// handle the source
342+
if (getSize(op.getSource()) == 1) {
343+
fireEvent(Event.get(this, Event.Type.Update, op.getSource()));
344+
fireEvent(Event.get(this, Event.Type.Update, get(op.getSource())));
345+
}
346+
// target
347+
if (getSize(op.getTarget()) - numberOfMentionsMoved == 1) {
348+
fireEvent(Event.get(this, Event.Type.Update, op.getTarget()));
349+
fireEvent(Event.get(this, Event.Type.Update, get(op.getTarget())));
350+
}
351+
}
352+
331353
} else if (operation instanceof MoveMentionPartToMention) {
332354
MoveMentionPartToMention op = (MoveMentionPartToMention) operation;
333355
op.getObjects().forEach(d -> {
@@ -465,6 +487,22 @@ protected void edit(RemoveMention op) {
465487
}
466488
});
467489
fireEvent(Event.get(this, Event.Type.Remove, op.getEntity(), op.getFeatureStructures()));
490+
491+
// may trigger underlining in gray if singleton
492+
if (getSpecialHandlingForSingletons()) {
493+
if (getSize(op.getEntity()) == 1) {
494+
fireEvent(Event.get(this, Event.Type.Update, op.getEntity()));
495+
fireEvent(Event.get(this, Event.Type.Update, get(op.getEntity())));
496+
}
497+
}
498+
499+
// remove entity if its empty
500+
Entity e = op.getEntity();
501+
if (entityMentionMap.get(e).isEmpty() && getPreferences().getBoolean(Constants.CFG_DELETE_EMPTY_ENTITIES,
502+
Defaults.CFG_DELETE_EMPTY_ENTITIES)) {
503+
remove(e);
504+
op.setEntityAutoDeleted(true);
505+
}
468506
registerEdit(op);
469507
}
470508

@@ -560,6 +598,10 @@ public ImmutableList<Entity> getSingletons() {
560598
.select(e -> getMentions(e).size() == 1).toList().toImmutable();
561599
}
562600

601+
protected int getSize(Entity e) {
602+
return get(e).size();
603+
}
604+
563605
public ImmutableList<Entity> getEntities(final EntitySorter entitySorter) {
564606

565607
MutableSet<Entity> eset = Sets.mutable.withAll(JCasUtil.select(documentModel.getJcas(), Entity.class));
@@ -650,6 +692,11 @@ public Preferences getPreferences() {
650692
return documentModel.getPreferences();
651693
}
652694

695+
private boolean getSpecialHandlingForSingletons() {
696+
return getPreferences().getBoolean(Constants.CFG_UNDERLINE_SINGLETONS_IN_GRAY,
697+
Defaults.CFG_UNDERLINE_SINGLETONS_IN_GRAY);
698+
}
699+
653700
public String getToolTipText(FeatureStructure featureStructure) {
654701
if (featureStructure instanceof EntityGroup) {
655702
StringBuilder b = new StringBuilder();
@@ -969,6 +1016,11 @@ private void undo(DuplicateMentions op) {
9691016
}
9701017

9711018
private void undo(RemoveMention op) {
1019+
if (op.isEntityAutoDeleted()) {
1020+
op.getEntity().addToIndexes();
1021+
fireEvent(Event.get(this, Event.Type.Add, null, op.getEntity()));
1022+
}
1023+
9721024
// re-create all mentions and set them to the op
9731025
op.getFeatureStructures().forEach(m -> {
9741026
m.addToIndexes();

src/main/java/de/unistuttgart/ims/coref/annotator/document/op/RemoveMention.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
public class RemoveMention extends AbstractRemoveOperation<Mention> implements CoreferenceModelOperation {
1010
Entity entity;
1111
ImmutableList<Span> spans;
12+
boolean entityAutoDeleted = false;
1213

1314
public RemoveMention(Mention... mention) {
1415
super(mention);
@@ -51,4 +52,18 @@ public void setMentions(ImmutableList<Mention> mention) {
5152
public ImmutableList<Mention> getMentions() {
5253
return getFeatureStructures();
5354
}
55+
56+
/**
57+
* @return the entityAutoDeleted
58+
*/
59+
public boolean isEntityAutoDeleted() {
60+
return entityAutoDeleted;
61+
}
62+
63+
/**
64+
* @param entityAutoDeleted the entityAutoDeleted to set
65+
*/
66+
public void setEntityAutoDeleted(boolean entityAutoDeleted) {
67+
this.entityAutoDeleted = entityAutoDeleted;
68+
}
5469
}

src/main/java/de/unistuttgart/ims/coref/annotator/worker/SaveJCasWorker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected Object doInBackground() throws Exception {
3737
os = new GZIPOutputStream(new FileOutputStream(file));
3838
}
3939
if (os != null)
40-
XmiCasSerializer.serialize(jcas.getCas(), os);
40+
XmiCasSerializer.serialize(jcas.getCas(), null, os, true, null);
4141
} finally {
4242
if (os != null)
4343
os.close();

0 commit comments

Comments
 (0)