Skip to content

Commit

Permalink
Merge branch 'release/1.14.5'
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Nils Reiter committed Mar 20, 2021
2 parents 52171a0 + 1990e97 commit e443aa8
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 40 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
Issue numbers (e.g., #43) refer to GitHub issues:
https://github.com/nilsreiter/CorefAnnotator/issues

## 1.14.5

- Fixed behaviour of de-emphasising singletons. Thanks @andreasvc #347
- Fixed upating of status bar if selection changes #350
- Fixed the bug that prevented automatically removing empty entities #352
- XMI files are now pretty printed, making them more git-friendly.
Thanks @andreasvc #339

## 1.14.4

- Fixed a bug caused by old flags no longer being generated
Expand Down
22 changes: 11 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.unistuttgart.ims</groupId>
<artifactId>coref.annotator</artifactId>
<version>1.14.4</version>
<version>1.14.5</version>
<packaging>jar</packaging>
<name>CorefAnnotator</name>
<url>https://github.com/nilsreiter/CorefAnnotator/</url>
Expand All @@ -15,7 +15,7 @@
<version.eclipse>9.2.0</version.eclipse>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<version.javafx>13.0.1</version.javafx>
<version.javafx>13.0.2</version.javafx>
</properties>
<build>
<plugins>
Expand Down Expand Up @@ -87,7 +87,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<version>3.2.4</version>
<configuration>
<transformers>
<transformer
Expand Down Expand Up @@ -189,7 +189,7 @@
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<version>3.0.0</version>
<executions>
<execution>
<id>duplicate build directory</id>
Expand Down Expand Up @@ -231,7 +231,7 @@
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>4.1.0</version>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
Expand All @@ -253,7 +253,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<version>3.2.0</version>
<executions>
<execution>
<id>quadrama-add-source</id>
Expand Down Expand Up @@ -317,7 +317,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<version>3.2.0</version>
<executions>
<execution>
<id>creta-add-source</id>
Expand Down Expand Up @@ -365,7 +365,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<version>3.2.0</version>
<executions>
<execution>
<id>sfb1391-add-source</id>
Expand Down Expand Up @@ -499,7 +499,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.1-jre</version>
<version>28.2-jre</version>
</dependency>

<dependency>
Expand All @@ -525,7 +525,7 @@
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.11</version>
<version>0.9.12</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down Expand Up @@ -594,7 +594,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.1.0</version>
<version>3.4.4</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -760,13 +760,26 @@ public void showSearch() {
searchPanel.setVisible(true);
}

@Override
protected void entityEventAdd(FeatureStructureEvent event) {
super.entityEventAdd(event);
updateStatusBar();
}

@Override
protected void entityEventRemove(FeatureStructureEvent event) {
super.entityEventRemove(event);
updateStatusBar();
}

@Override
protected void entityEventMove(FeatureStructureEvent event) {
for (FeatureStructure fs : event)
if (fs instanceof Mention) {
highlightManager.unUnderline((Annotation) fs);
highlightManager.underline((Mention) fs, new Color(((Entity) event.getArgument2()).getColor()));
}
updateStatusBar();
}

@Override
Expand Down Expand Up @@ -910,6 +923,33 @@ public void updateStyle(Object constant, Object value) {
switchStyle(currentStyle);
}

protected void updateStatusBar() {
int low = Math.min(textPane.getSelectionStart(), textPane.getSelectionEnd());
int high = Math.max(textPane.getSelectionStart(), textPane.getSelectionEnd());

MutableSet<Mention> mentions = Sets.mutable.empty();
if (getDocumentModel() != null && getDocumentModel().getCoreferenceModel() != null) {

// nothing is selected: show all mentions cursor is part of
MutableSet<? extends Annotation> annotations = Sets.mutable
.withAll(getDocumentModel().getCoreferenceModel().getMentions(low));
mentions = annotations.selectInstancesOf(Mention.class);

// something is selected
if (low != high) {
ImmutableSet<Mention> ms = getDocumentModel().getCoreferenceModel().getMentionsBetween(low, high)
.selectInstancesOf(Mention.class);
mentions.addAllIterable(ms);
}
setCollectionPanel(mentions.collect(m -> {
EntityPanel ep = new EntityPanel(getDocumentModel(), m.getEntity());
Annotator.app.getPreferences().addPreferenceChangeListener(ep);
getDocumentModel().getCoreferenceModel().addCoreferenceModelListener(ep);
return ep;
}));
}
}

@Override
public void switchStyle(StylePlugin sv) {
switchStyle(sv, sv.getBaseStyle());
Expand Down Expand Up @@ -1480,34 +1520,10 @@ class TextCaretListener implements CaretListener {

@Override
public void caretUpdate(CaretEvent e) {
int dot = e.getDot();
int mark = e.getMark();
int low = Math.min(dot, mark);
int high = Math.max(dot, mark);

MutableSet<Mention> mentions = Sets.mutable.empty();
if (getDocumentModel() != null && getDocumentModel().getCoreferenceModel() != null) {

// nothing is selected: show all mentions cursor is part of
MutableSet<? extends Annotation> annotations = Sets.mutable
.withAll(getDocumentModel().getCoreferenceModel().getMentions(low));
mentions = annotations.selectInstancesOf(Mention.class);

// something is selected
if (dot != mark) {
ImmutableSet<Mention> ms = getDocumentModel().getCoreferenceModel().getMentionsBetween(low, high)
.selectInstancesOf(Mention.class);
mentions.addAllIterable(ms);
}
setCollectionPanel(mentions.collect(m -> {
EntityPanel ep = new EntityPanel(getDocumentModel(), m.getEntity());
Annotator.app.getPreferences().addPreferenceChangeListener(ep);
getDocumentModel().getCoreferenceModel().addCoreferenceModelListener(ep);
return ep;
}));
}

updateStatusBar();
if (getDocumentModel() != null)
highlightSegmentInTOC(dot);
highlightSegmentInTOC(e.getDot());

}

Expand Down Expand Up @@ -1607,7 +1623,13 @@ else if (anno instanceof DetachedMentionPart)
mi.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
getDocumentModel().edit(new AddMentionsToEntity(entity, getSelection()));
if (Annotator.app.getPreferences().getBoolean(Constants.CFG_REPLACE_MENTION, false)
&& getSelectedAnnotations(Mention.class).size() == 1) {
getDocumentModel().edit(
new MoveMentionsToEntity(entity, getSelectedAnnotations(Mention.class)));
} else {
getDocumentModel().edit(new AddMentionsToEntity(entity, getSelection()));
}
}
});
mi.setIcon(FontIcon.of(MaterialDesign.MDI_ACCOUNT, new Color(entity.getColor())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,13 @@ protected synchronized void edit(CoreferenceModelOperation operation) {
return addTo(op.getEntity(), sp);
}));
fireEvent(Event.get(this, Event.Type.Add, op.getEntity(), op.getMentions()));
int newNumberOfMentions = getSize(op.getEntity());
// may trigger underlining in gray if singleton
if (getSpecialHandlingForSingletons() && newNumberOfMentions - op.getMentions().size() == 1
&& newNumberOfMentions > 1) {
fireEvent(Event.get(this, Event.Type.Update, op.getEntity()));
fireEvent(Event.get(this, Event.Type.Update, get(op.getEntity())));
}
} else if (operation instanceof AttachPart) {
AttachPart op = (AttachPart) operation;
op.setPart(addTo(op.getMention(), op.getSpan()));
Expand All @@ -328,6 +335,21 @@ protected synchronized void edit(CoreferenceModelOperation operation) {
MoveMentionsToEntity op = (MoveMentionsToEntity) operation;
op.getMentions().forEach(m -> moveTo(op.getTarget(), m));
fireEvent(Event.get(this, Event.Type.Move, op.getSource(), op.getTarget(), op.getMentions()));
// may trigger underlining in gray if singleton
if (getSpecialHandlingForSingletons()) {
int numberOfMentionsMoved = op.getMentions().size();
// handle the source
if (getSize(op.getSource()) == 1) {
fireEvent(Event.get(this, Event.Type.Update, op.getSource()));
fireEvent(Event.get(this, Event.Type.Update, get(op.getSource())));
}
// target
if (getSize(op.getTarget()) - numberOfMentionsMoved == 1) {
fireEvent(Event.get(this, Event.Type.Update, op.getTarget()));
fireEvent(Event.get(this, Event.Type.Update, get(op.getTarget())));
}
}

} else if (operation instanceof MoveMentionPartToMention) {
MoveMentionPartToMention op = (MoveMentionPartToMention) operation;
op.getObjects().forEach(d -> {
Expand Down Expand Up @@ -465,6 +487,22 @@ protected void edit(RemoveMention op) {
}
});
fireEvent(Event.get(this, Event.Type.Remove, op.getEntity(), op.getFeatureStructures()));

// may trigger underlining in gray if singleton
if (getSpecialHandlingForSingletons()) {
if (getSize(op.getEntity()) == 1) {
fireEvent(Event.get(this, Event.Type.Update, op.getEntity()));
fireEvent(Event.get(this, Event.Type.Update, get(op.getEntity())));
}
}

// remove entity if its empty
Entity e = op.getEntity();
if (entityMentionMap.get(e).isEmpty() && getPreferences().getBoolean(Constants.CFG_DELETE_EMPTY_ENTITIES,
Defaults.CFG_DELETE_EMPTY_ENTITIES)) {
remove(e);
op.setEntityAutoDeleted(true);
}
registerEdit(op);
}

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

protected int getSize(Entity e) {
return get(e).size();
}

public ImmutableList<Entity> getEntities(final EntitySorter entitySorter) {

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

private boolean getSpecialHandlingForSingletons() {
return getPreferences().getBoolean(Constants.CFG_UNDERLINE_SINGLETONS_IN_GRAY,
Defaults.CFG_UNDERLINE_SINGLETONS_IN_GRAY);
}

public String getToolTipText(FeatureStructure featureStructure) {
if (featureStructure instanceof EntityGroup) {
StringBuilder b = new StringBuilder();
Expand Down Expand Up @@ -969,6 +1016,11 @@ private void undo(DuplicateMentions op) {
}

private void undo(RemoveMention op) {
if (op.isEntityAutoDeleted()) {
op.getEntity().addToIndexes();
fireEvent(Event.get(this, Event.Type.Add, null, op.getEntity()));
}

// re-create all mentions and set them to the op
op.getFeatureStructures().forEach(m -> {
m.addToIndexes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
public class RemoveMention extends AbstractRemoveOperation<Mention> implements CoreferenceModelOperation {
Entity entity;
ImmutableList<Span> spans;
boolean entityAutoDeleted = false;

public RemoveMention(Mention... mention) {
super(mention);
Expand Down Expand Up @@ -51,4 +52,18 @@ public void setMentions(ImmutableList<Mention> mention) {
public ImmutableList<Mention> getMentions() {
return getFeatureStructures();
}

/**
* @return the entityAutoDeleted
*/
public boolean isEntityAutoDeleted() {
return entityAutoDeleted;
}

/**
* @param entityAutoDeleted the entityAutoDeleted to set
*/
public void setEntityAutoDeleted(boolean entityAutoDeleted) {
this.entityAutoDeleted = entityAutoDeleted;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected Object doInBackground() throws Exception {
os = new GZIPOutputStream(new FileOutputStream(file));
}
if (os != null)
XmiCasSerializer.serialize(jcas.getCas(), os);
XmiCasSerializer.serialize(jcas.getCas(), null, os, true, null);
} finally {
if (os != null)
os.close();
Expand Down

0 comments on commit e443aa8

Please sign in to comment.