Skip to content

Commit

Permalink
Merge branch 'release/1.15.0'
Browse files Browse the repository at this point in the history
* release/1.15.0:
  1.15.0
  1.15.0-beta1
  changelog update
  fixed some undo behaviour when de-emphasizing singletons
  added changelog
  Sorting now listens to preferences and sorts if keep tree sorted is set to true
  Updated interface of Setting class
  Setting is now its own class
  strings and translations
  action added to menu and document window
  new action to select mentions in tree that are touched
  New method to retrieve annotations that are touched, i.e., that the cursor is in
  increased size of entity labels in tree
  update modification is now in EntityTreeModel
  implement sort by last modified; related to #153
  • Loading branch information
Nils Reiter committed May 13, 2021
2 parents e443aa8 + 9d79744 commit 68ad1c9
Show file tree
Hide file tree
Showing 16 changed files with 327 additions and 147 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
Issue numbers (e.g., #43) refer to GitHub issues:
https://github.com/nilsreiter/CorefAnnotator/issues

## 1.15.0

- The entity tree can now also be sorted based on last change (to the entity).
Thanks @andreasvc! #153 #349
- The maximum length of displayed entity labels is increased to 100 characters.
This is not a long-term solution though. #353
- Pressing cmd-t now displays a mention in the tree, if a) the cursor is placed
in a single mention or b) a single mention is selected exactly. #351
- Fixed (some) undo behaviour when de-emphasizing singletons #347

## 1.14.5

- Fixed behaviour of de-emphasising singletons. Thanks @andreasvc #347
Expand Down
2 changes: 1 addition & 1 deletion 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.5</version>
<version>1.15.0</version>
<packaging>jar</packaging>
<name>CorefAnnotator</name>
<url>https://github.com/nilsreiter/CorefAnnotator/</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.set.MutableSet;
import org.eclipse.collections.impl.factory.Lists;
import org.eclipse.collections.impl.factory.Sets;
import org.kordamp.ikonli.fontawesome.FontAwesome;
import org.kordamp.ikonli.materialdesign.MaterialDesign;
import org.kordamp.ikonli.swing.FontIcon;
Expand Down Expand Up @@ -267,11 +268,24 @@ protected void entityEventInit(FeatureStructureEvent event) {
}

public <T extends Annotation> MutableSet<T> getSelectedAnnotations(Class<T> clazz) {
MutableSet<Annotation> annotations = getDocumentModel().getCoreferenceModel()
.getMentions(getTextPane().getSelectionStart())
.select(a -> a.getBegin() == getTextPane().getSelectionStart()
&& a.getEnd() == getTextPane().getSelectionEnd());
return annotations.selectInstancesOf(clazz);
try {
MutableSet<T> annotations = getTouchedAnnotations(clazz)
.select(a -> a.getBegin() == getTextPane().getSelectionStart()
&& a.getEnd() == getTextPane().getSelectionEnd());
return annotations.selectInstancesOf(clazz);
} catch (NullPointerException e) {
return Sets.mutable.empty();
}
}

public <T extends Annotation> MutableSet<T> getTouchedAnnotations(Class<T> clazz) {
try {
MutableSet<Annotation> annotations = getDocumentModel().getCoreferenceModel()
.getMentions(getTextPane().getSelectionStart());
return annotations.selectInstancesOf(clazz);
} catch (NullPointerException e) {
return Sets.mutable.empty();
}
}

public JTextPane getTextPane() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.unistuttgart.ims.coref.annotator;

import java.time.Instant;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Vector;
Expand Down Expand Up @@ -28,6 +29,8 @@ public class CATreeNode implements MutableTreeNode, Iterable<CATreeNode>, Toolti

CATreeNode parent = null;

long lastModified = 0;

public CATreeNode(Entity e) {
this(e, e.getLabel());
}
Expand Down Expand Up @@ -59,6 +62,14 @@ public int getChildCount() {
return children.size();
}

public long getLastModified() {
return lastModified;
}

public void resetLastModified() {
lastModified = 0;
}

public Vector<CATreeNode> getChildren() {
return this.children;
}
Expand Down Expand Up @@ -219,10 +230,14 @@ public CATreeNode next() {
};
}

public void modify() {
if (isEntity())
this.lastModified = Instant.now().toEpochMilli();
}

@Override
public void remove(int index) {
children.remove(index);

}

@Override
Expand Down
70 changes: 3 additions & 67 deletions src/main/java/de/unistuttgart/ims/coref/annotator/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,79 +2,13 @@

import java.util.Random;

import org.kordamp.ikonli.Ikon;
import org.kordamp.ikonli.materialdesign.MaterialDesign;

import de.unistuttgart.ims.coref.annotator.api.v1.Entity;
import de.unistuttgart.ims.coref.annotator.api.v1.Mention;
import de.unistuttgart.ims.coref.annotator.document.op.AddFlag;

public class Constants {
public static class Setting<T> {

public T defaultValue;
public Ikon[] ikon;
public String preferencesKey;
public String toggleActionStringKey;
public String toggleActionTooltipKey;

public Setting(String preferencesKey, String toggleActionKey, String toggleActionTooltipKey, T defaultValue,
Ikon... ikon) {
this.preferencesKey = preferencesKey;
this.toggleActionStringKey = toggleActionKey;
this.defaultValue = defaultValue;
this.toggleActionTooltipKey = toggleActionTooltipKey;
this.ikon = ikon;
}

public Setting(String preferencesKey, String toggleActionKey, T defaultValue, Ikon... ikon) {
this.preferencesKey = preferencesKey;
this.toggleActionStringKey = toggleActionKey;
this.defaultValue = defaultValue;
this.ikon = ikon;
}

public T getDefaultValue() {
return defaultValue;
}

public Ikon[] getIkon() {
return ikon;
}

public String getPreferencesKey() {
return preferencesKey;
}

public String getToggleActionStringKey() {
return toggleActionStringKey;
}

public String getToggleActionTooltipKey() {
return toggleActionTooltipKey;
}

public void setDefaultValue(T defaultValue) {
this.defaultValue = defaultValue;
}

public void setIkon(Ikon[] ikon) {
this.ikon = ikon;
}

public void setPreferencesKey(String preferencesKey) {
this.preferencesKey = preferencesKey;
}

public void setToggleActionStringKey(String toggleActionStringKey) {
this.toggleActionStringKey = toggleActionStringKey;
}

public void setToggleActionTooltipKey(String toggleActionTooltipKey) {
this.toggleActionTooltipKey = toggleActionTooltipKey;
}
}

/**
* Annotator name or id
*/
Expand Down Expand Up @@ -256,9 +190,11 @@ public void setToggleActionTooltipKey(String toggleActionTooltipKey) {
public static final Setting<Boolean> SETTING_SHOW_TEXT_LABELS = new Setting<Boolean>(CFG_SHOW_TEXT_LABELS,
Strings.ACTION_TOGGLE_SHOW_TEXT_LABELS, Strings.ACTION_TOGGLE_SHOW_TEXT_LABELS_TOOLTIP, false,
MaterialDesign.MDI_FORMAT_TEXT);

public static final Setting<Boolean> SETTING_SHOW_LINE_NUMBER_IN_TREE = new Setting<Boolean>(
CFG_SHOW_LINE_NUMBER_IN_TREE, Strings.ACTION_TOGGLE_SHOW_LINE_NUMBER_IN_TREE,
Strings.ACTION_TOGGLE_SHOW_LINE_NUMBER_IN_TREE_TOOLTIP, false, MaterialDesign.MDI_FORMAT_TEXT);

public static final Setting<Boolean> SETTING_TRIM_WHITESPACE = new Setting<Boolean>(CFG_TRIM_WHITESPACE,
Strings.ACTION_TOGGLE_TRIM_WHITESPACE, Strings.ACTION_TOGGLE_TRIM_WHITESPACE_TOOLTIP, true,
MaterialDesign.MDI_ARROW_COMPRESS);
Expand Down Expand Up @@ -286,7 +222,7 @@ public void setToggleActionTooltipKey(String toggleActionTooltipKey) {
public static final String[] SUPPORTED_LANGUAGES = new String[] { "x-unspecified", "de", "en", "es", "fr", "it",
"nl", "ru", "gmh" };

public static final int UI_MAX_STRING_WIDTH_IN_TREE = 50;
public static final int UI_MAX_STRING_WIDTH_IN_TREE = 100;
public static final int UI_MAX_STRING_WIDTH_IN_MENU = 30;
public static final int UI_MAX_STRING_WIDTH_IN_STATUSBAR = 30;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
import de.unistuttgart.ims.coref.annotator.action.SelectNextMentionAction;
import de.unistuttgart.ims.coref.annotator.action.SelectPreviousMentionAction;
import de.unistuttgart.ims.coref.annotator.action.SetLanguageAction;
import de.unistuttgart.ims.coref.annotator.action.ShowASelectedMentionInTreeAction;
import de.unistuttgart.ims.coref.annotator.action.ShowDocumentStatistics;
import de.unistuttgart.ims.coref.annotator.action.ShowFlagEditor;
import de.unistuttgart.ims.coref.annotator.action.ShowLogWindowAction;
Expand Down Expand Up @@ -378,6 +379,8 @@ protected void initializeWindow() {
textPane.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.ALT_DOWN_MASK),
SelectPreviousMentionAction.class);

textPane.addCaretListener(actions.showASelectedMentionInTree);

highlightManager = new HighlightManager(textPane);

// scrollPane.setRowHeaderView(segmentIndicator);
Expand Down Expand Up @@ -418,6 +421,7 @@ protected void initialiseActions() {
this.actions.deleteAction = new DeleteAction(this);
this.actions.sortByAlpha = SortTree.getSortByAlphabet(this);
this.actions.sortByMentions = SortTree.getSortByMention(this);
this.actions.sortByLastModified = SortTree.getSortByLastModified(this);
this.actions.fileSaveAction = new FileSaveAction(this);
this.actions.showSearchPanelAction = new ShowSearchPanelAction(Annotator.app, this);
this.actions.copyAction = new CopyAction(this);
Expand All @@ -441,6 +445,10 @@ protected void initialiseActions() {
documentStateListeners.add(actions.undoAction);
documentStateListeners.add(actions.fileSaveAction);

Annotator.app.getPreferences().addPreferenceChangeListener(actions.sortByAlpha);
Annotator.app.getPreferences().addPreferenceChangeListener(actions.sortByLastModified);
Annotator.app.getPreferences().addPreferenceChangeListener(actions.sortByMentions);

Annotator.logger.trace("Actions initialised.");

}
Expand Down Expand Up @@ -588,6 +596,7 @@ protected JMenu initialiseMenuEntity() {
// entityMenu.add(new JCheckBoxMenuItem(actions.toggleMentionNonNominal));
entityMenu.add(actions.deleteAllAction);
entityMenu.add(mentionFlagsInMenuBar);
entityMenu.add(actions.showASelectedMentionInTree);
entityMenu.addSeparator();
entityMenu.add(Annotator.getString(Strings.MENU_EDIT_ENTITIES));
entityMenu.add(new JMenuItem(actions.newEntityAction));
Expand All @@ -604,13 +613,16 @@ protected JMenu initialiseMenuEntity() {
JMenu sortMenu = new JMenu(Annotator.getString(Strings.MENU_EDIT_ENTITIES_SORT));
JRadioButtonMenuItem radio1 = new JRadioButtonMenuItem(this.actions.sortByAlpha);
JRadioButtonMenuItem radio2 = new JRadioButtonMenuItem(this.actions.sortByMentions);
JRadioButtonMenuItem radio3 = new JRadioButtonMenuItem(this.actions.sortByLastModified);
radio2.setSelected(true);
ButtonGroup grp = new ButtonGroup();
grp.add(radio3);
grp.add(radio2);
grp.add(radio1);

sortMenu.add(radio1);
sortMenu.add(radio2);
sortMenu.add(radio3);
sortMenu.add(new JCheckBoxMenuItem(this.actions.sortDescending));

entityMenu.add(sortMenu);
Expand Down Expand Up @@ -813,6 +825,7 @@ public void setDocumentModel(DocumentModel model) {
model.getTreeModel().addTreeModelListener((SortingTreeModelListener) modelHandler);
model.getTreeModel().addEntitySortOrderListener(actions.sortByAlpha);
model.getTreeModel().addEntitySortOrderListener(actions.sortByMentions);
model.getTreeModel().addEntitySortOrderListener(actions.sortByLastModified);
model.getTreeModel().addEntitySortOrderListener(actions.sortDescending);

// listeners to the flag model
Expand Down Expand Up @@ -1834,6 +1847,7 @@ class ActionContainer {
AbstractAction showDocumentStatistics = new ShowDocumentStatistics(DocumentWindow.this);
SortTree sortByAlpha;
SortTree sortByMentions;
SortTree sortByLastModified;
ToggleEntitySortOrder sortDescending = new ToggleEntitySortOrder(DocumentWindow.this);
FormEntityGroup formGroupAction = new FormEntityGroup(DocumentWindow.this);
MergeSelectedEntities mergeSelectedEntitiesAction = new MergeSelectedEntities(DocumentWindow.this);
Expand All @@ -1848,6 +1862,8 @@ class ActionContainer {
LineNumberStyle.FIXED);
ViewSetLineNumberStyle lineNumberStyleDynamic = new ViewSetLineNumberStyle(DocumentWindow.this,
LineNumberStyle.DYNAMIC);
ShowASelectedMentionInTreeAction showASelectedMentionInTree = new ShowASelectedMentionInTreeAction(
DocumentWindow.this);

}

Expand Down
Loading

0 comments on commit 68ad1c9

Please sign in to comment.