Commit e18696a6 authored by Christos Christodoulopoulos's avatar Christos Christodoulopoulos
Browse files

Added ability to add new annotations (by copying the existing one)

Fixed crash with empty SRL annotations
parent dac419c5
......@@ -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()) {
......
......@@ -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;
......
......@@ -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 ----------------------
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment