From e18696a6ece053471e07db6f3f8f8e7f2fa45771 Mon Sep 17 00:00:00 2001 From: Christos Christodoulopoulos <christos.c2009@gmail.com> Date: Tue, 11 Nov 2014 19:52:55 -0600 Subject: [PATCH] Added ability to add new annotations (by copying the existing one) Fixed crash with empty SRL annotations --- src/jubilee/datastructure/JBCorpus.java | 14 ++++++ .../datastructure/JBDataStructure.java | 17 ++++++-- src/jubilee/toolkit/JBToolkit.java | 43 +++++++++++++++---- 3 files changed, 63 insertions(+), 11 deletions(-) diff --git a/src/jubilee/datastructure/JBCorpus.java b/src/jubilee/datastructure/JBCorpus.java index a37a808..64124e4 100644 --- a/src/jubilee/datastructure/JBCorpus.java +++ b/src/jubilee/datastructure/JBCorpus.java @@ -140,6 +140,20 @@ public class JBCorpus { annotations.remove(currentAnnotationIndex); } + public void addAnnotation(String annotator, String lemma) { + JBDataStructure current = getCurrentAnnotation(); + // Start from copying the current annotation + JBDataStructure newAnnotation = null; + try { + String pbInstanceString = annotator + " " + lemma + " " + lemma + ".XX#"; + newAnnotation = new JBDataStructure(current.getTbTree().toTextTree(), pbInstanceString, + current.getIndexInContext()); + } catch (Exception e) { + e.printStackTrace(); + } + annotations.add(currentAnnotationIndex, newAnnotation); + } + public void backup(JBDataStructure currentAnnotation) { // If this is the first type we visit this annotation, make a copy if (currentAnnotationOriginal.getIndexInContext() != currentAnnotation.getIndexInContext()) { diff --git a/src/jubilee/datastructure/JBDataStructure.java b/src/jubilee/datastructure/JBDataStructure.java index 2909998..e5cccc6 100644 --- a/src/jubilee/datastructure/JBDataStructure.java +++ b/src/jubilee/datastructure/JBDataStructure.java @@ -101,8 +101,11 @@ public class JBDataStructure { } private void readPBInstance(String pbInstanceString) { - String info = pbInstanceString.split("#")[0]; - String labels = pbInstanceString.split("#")[1]; + String[] split = pbInstanceString.split("#"); + String info = split[0]; + String labels = null; + if (split.length > 1) + labels = split[1]; StringTokenizer tok = new StringTokenizer(info); @@ -110,7 +113,8 @@ public class JBDataStructure { type = tok.nextToken(); roleset = tok.nextToken(); - readPropbankLabels(labels, tbTree); + if (labels != null) + readPropbankLabels(labels, tbTree); } private void readPropbankLabels(String labels, TBTree tree) { @@ -160,6 +164,13 @@ public class JBDataStructure { } } + public void setType(String type) { + if (!this.type.equals(type)){ + this.type = type; + hasChanged(true); + } + } + public void setAnnotator(String annotator) { if (!this.annotator.equals(annotator)) { this.annotator = annotator; diff --git a/src/jubilee/toolkit/JBToolkit.java b/src/jubilee/toolkit/JBToolkit.java index c25545f..1d9c3db 100644 --- a/src/jubilee/toolkit/JBToolkit.java +++ b/src/jubilee/toolkit/JBToolkit.java @@ -23,6 +23,7 @@ */ package jubilee.toolkit; +import com.sun.codemodel.internal.JOp; import jubilee.awt.JDCFileDialog; import jubilee.awt.JDCTextAreaFrame; import jubilee.datastructure.JBCorpus; @@ -51,7 +52,7 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L private String str_annFile; // Treeview: top-pane - private JButton bt_prev, bt_next, buttonTreeEdit, buttonRemoveAnnotation; + private JButton bt_prev, bt_next, buttonTreeEdit, buttonRemoveAnnotation, buttonAddAnnotation; private JComboBox<String> comboJump; private JTextField tf_annotator; private JTextArea ta_sentence; @@ -115,8 +116,7 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L // -------------------- initialize components -------------------- - private void initComponents() - { + private void initComponents() { bt_prev = new JButton("Prev"); bt_prev.addActionListener(this); @@ -126,9 +126,11 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L buttonTreeEdit = new JButton("Edit Tree"); buttonTreeEdit.addActionListener(this); - buttonRemoveAnnotation = new JButton("Remove Annotation"); + buttonRemoveAnnotation = new JButton("[-] Remove Annotation"); + buttonAddAnnotation = new JButton("[+] Add Annotation"); buttonRemoveAnnotation.addActionListener(this); - + buttonAddAnnotation.addActionListener(this); + comboJump = new JComboBox<String>(); comboJump.setMaximumRowCount(20); comboJump.addItemListener(this); @@ -192,9 +194,10 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L bottomPanel.add(sentencePane, BorderLayout.NORTH); JPanel treeEditPanel = new JPanel(); - treeEditPanel.setLayout(new BorderLayout()); - treeEditPanel.add(buttonTreeEdit, BorderLayout.EAST); - treeEditPanel.add(buttonRemoveAnnotation, BorderLayout.WEST); + treeEditPanel.setLayout(new GridLayout(1, 3, 50, 0)); + treeEditPanel.add(buttonAddAnnotation); + treeEditPanel.add(buttonRemoveAnnotation); + treeEditPanel.add(buttonTreeEdit); bottomPanel.add(treeEditPanel, BorderLayout.SOUTH); @@ -293,6 +296,7 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L else if (e.getSource() == mbar.helpAbout) menuHelpAbout(); else if (e.getSource() == buttonTreeEdit) actionButtonTreeEdit(); else if (e.getSource() == buttonRemoveAnnotation) actionButtonRemoveAnnotation(); + else if (e.getSource() == buttonAddAnnotation) actionButtonAddAnnotation(); menuArgumentArg(e); menuArgumentFunc(e); } @@ -381,6 +385,29 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L else comboJump.setSelectedIndex(index - 1); } } + + private void actionButtonAddAnnotation() { + boolean delete = false; + String response = JOptionPane.showInputDialog(null, "This will add a new annotation by copying " + + "the existing one.\nPlease enter the predicate lemma of the new annotation", "Add annotation", + JOptionPane.QUESTION_MESSAGE); + + if (response != null) { + // Add the new annotation + corpus.addAnnotation(str_userID, response); + + // Rebuild the combo box + comboJump.removeAllItems(); + for (int i = 0; i < corpus.getSize(); i++) { + int position = corpus.getAnnotation(i).getIndexInContext(); + String contextId = corpus.getContext(position); + comboJump.insertItemAt(i + " - \"" + contextId.substring(0, contextId.indexOf(":")) + "\"", i); + } + + // Now move to the next annotation + comboJump.setSelectedIndex(corpus.getCurrentAnnotationIndex()); + } + } // ---------------------- Menu-File Action ---------------------- -- GitLab