Commit 778b2b4d authored by Christos Christodoulopoulos's avatar Christos Christodoulopoulos
Browse files

Addressed bug with deleting annotations

This is not a fix, but it might help identify the problem and in the meantime it won't cause the same problems
Started moving to Java 7.
parent 36a5108e
No preview for this file type
package jubilee.datastructure;
import jubilee.toolkit.JBToolkit;
import jubilee.util.DataManager;
import org.json.JSONArray;
import org.json.JSONException;
......@@ -7,10 +8,7 @@ import org.json.JSONObject;
import javax.swing.*;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* The Jubilee corpus for each annotation task. It consists of a list of {@link JBDataStructure}s
......@@ -37,10 +35,10 @@ public class JBCorpus {
public JBCorpus(String file, String annotator) throws Exception {
this.annotator = annotator;
annotations = new ArrayList<JBDataStructure>();
contexts = new ArrayList<String>();
contextToAnnotation = new HashMap<Integer, List<JBDataStructure>>();
bookmarks = new HashMap<String, String>();
annotations = new ArrayList<>();
contexts = new ArrayList<>();
contextToAnnotation = new HashMap<>();
bookmarks = new HashMap<>();
corpusFile = file;
currentAnnotationIndex = 0;
currentAnnotationOriginal = new JBDataStructure();
......@@ -65,18 +63,18 @@ public class JBCorpus {
contexts = corpora[0].contexts;
currentAnnotationIndex = 0;
currentAnnotationOriginal = new JBDataStructure();
bookmarks = new HashMap<String, String>();
bookmarks = new HashMap<>();
// Aggregate the annotations across corpora
contextToAnnotation = new HashMap<Integer, List<JBDataStructure>>();
annotations = new ArrayList<JBDataStructure>();
contextToAnnotation = new HashMap<>();
annotations = new ArrayList<>();
for (int i = 0; i < contexts.size(); i++) {
for (JBCorpus corpus : corpora) {
if (!corpus.contextToAnnotation.containsKey(i)) continue;
List<JBDataStructure> tempOtherList = corpus.contextToAnnotation.get(i);
List<JBDataStructure> tempList;
if (!contextToAnnotation.containsKey(i))
tempList = new ArrayList<JBDataStructure>();
tempList = new ArrayList<>();
else tempList = contextToAnnotation.get(i);
for (JBDataStructure otherAnn : tempOtherList) {
if (!existsInList(tempList, otherAnn)) {
......@@ -108,7 +106,7 @@ public class JBCorpus {
return false;
}
public void readCorpus() throws Exception {
private void readCorpus() throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(corpusFile)));
String fileString = "";
String line;
......@@ -129,7 +127,7 @@ public class JBCorpus {
List<JBDataStructure> annotationList;
if (contextToAnnotation.containsKey(position))
annotationList = contextToAnnotation.get(position);
else annotationList = new ArrayList<JBDataStructure>();
else annotationList = new ArrayList<>();
annotationList.add(structure);
contextToAnnotation.put(position, annotationList);
}
......@@ -194,14 +192,12 @@ public class JBCorpus {
}
private void confirmChanges(boolean approved) {
boolean save = false;
boolean save;
if (approved) save = true;
else {
int response = JOptionPane.showConfirmDialog(null, "Do you want to keep the changes to the annotation?",
"Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (response == JOptionPane.NO_OPTION) save = false;
else if (response == JOptionPane.YES_OPTION) save = true;
else if (response == JOptionPane.CLOSED_OPTION) save = false;
save = JBToolkit.isYes(response);
}
if (!save) {
try {
......@@ -227,7 +223,7 @@ public class JBCorpus {
contextToAnnotation.get(newAnnotation.getIndexInContext()).add(newAnnotation);
}
public void revertChanges() throws Exception {
private void revertChanges() throws Exception {
// Make sure that there is something to revert back to
if (currentAnnotationOriginal == null) throw new Exception("Original annotation is missing");
annotations.set(currentAnnotationIndex, currentAnnotationOriginal);
......@@ -240,6 +236,16 @@ public class JBCorpus {
if (annotationsForContext.size() == 1) contextToAnnotation.remove(indexInContext);
else {
annotationsForContext.remove(currentAnnotation);
// This shouldn't happen
if (annotationsForContext.size() == 0) {
JOptionPane.showMessageDialog(null, "0 annotations remaining! Please check the console output." +
"\nAnnotation will not be deleted.", "Error",
JOptionPane.ERROR_MESSAGE);
System.err.println("Annotation ID: " + currentAnnotationIndex +
" (" + currentAnnotation.getIndexInContext() + ")");
System.err.println(currentAnnotation.toProbankString());
return;
}
contextToAnnotation.put(indexInContext, annotationsForContext);
}
annotations.remove(currentAnnotationIndex);
......@@ -306,7 +312,8 @@ public class JBCorpus {
int position = 0;
for (JBDataStructure other : otherAnnotations) {
position++;
if (other.getPredicateIndex() == annotation.getPredicateIndex()) break;
if (other.getPredicateIndex() == annotation.getPredicateIndex() &&
other.getRoleset().equals(annotation.getRoleset())) break;
}
return position;
}
......
......@@ -47,7 +47,7 @@ import java.util.List;
@SuppressWarnings("serial")
public class JBToolkit extends JFrame implements ActionListener, ItemListener, ListSelectionListener {
public final static String EDITED = "[EDITED] ";
public final static String GOLD_MISSING = "MISSING";
private final static String GOLD_MISSING = "MISSING";
private final static String WHITE_STAR = "\u2606";
private final static String BLACK_STAR = "\u2605";
private String str_frameTitle;
......@@ -73,7 +73,7 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
private JBCorpus[] moreCorpora;
int i_currSetting = 0; // current project setting (i.e. english.sample.path)
int i_maxAnn;
private int i_maxAnn;
// Reference lists (shown during tree editing)
private ArrayList<String[]> terminalsList;
......@@ -138,7 +138,7 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
return str_userID;
}
public void showOpenDialog() {
private void showOpenDialog() {
new JBOpenDialog(this, false, i_maxAnn);
setVisible(true);
}
......@@ -146,7 +146,7 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
/**
* Reads and stores reference material (related to the annotation guidelines) for later use
*/
public void readReferenceMaterial() {
void readReferenceMaterial() {
terminalsList = DataManager.getContents("terminals.txt");
nonTerminalsList = DataManager.getContents("non-terminals.txt");
}
......@@ -172,7 +172,7 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
buttonRemoveAnnotation.addActionListener(this);
buttonAddAnnotation.addActionListener(this);
comboJump = new JComboBox<String>();
comboJump = new JComboBox<>();
comboJump.setMaximumRowCount(20);
comboJump.addItemListener(this);
comboJump.setFocusable(false);
......@@ -247,8 +247,8 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
top.add(top1, BorderLayout.NORTH);
if (isGold()) {
lm_gold = new DefaultListModel<String>();
ls_gold = new JList<String>(lm_gold);
lm_gold = new DefaultListModel<>();
ls_gold = new JList<>(lm_gold);
ls_gold.setFont(new Font("Courier", Font.PLAIN, 11));
ls_gold.addListSelectionListener(this);
......@@ -402,19 +402,26 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
}
}
public void updateAll() {
void updateAll() {
JBDataStructure annotation = corpus.getCurrentAnnotation();
tv_tree.setAnnotation(annotation);
framesetPanel.updateFrameset(annotation.getType(), annotation.getRoleset());
String annotator = annotation.getAnnotator();
tf_annotator.setText(annotator);
if (annotator.equals("auto"))
tf_annotator.setBackground(Color.RED.brighter());
else if (annotator.equals("babySRL"))
tf_annotator.setBackground(Color.GREEN);
else if (annotator.equals("gold"))
tf_annotator.setBackground(Color.YELLOW);
else tf_annotator.setBackground(Color.LIGHT_GRAY);
switch (annotator) {
case "auto":
tf_annotator.setBackground(Color.RED.brighter());
break;
case "babySRL":
tf_annotator.setBackground(Color.GREEN);
break;
case "gold":
tf_annotator.setBackground(Color.YELLOW);
break;
default:
tf_annotator.setBackground(Color.LIGHT_GRAY);
break;
}
// Update the context window
int bId = 0, eId = -1, bExtraId = 0, eExtraId = -1;
......@@ -476,7 +483,7 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
ls_gold.invalidate();
}
public void updateGoldTopList() {
void updateGoldTopList() {
int maxLength = maxAnnotationLength();
JBDataStructure annotation = corpus.getCurrentAnnotation();
lm_gold.setElementAt(StringManager.addIndent("GOLD", 12) +
......@@ -533,13 +540,10 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
}
private void actionButtonRemoveAnnotation() {
boolean delete = false;
int response = JOptionPane.showConfirmDialog(null, "Do you really want to remove this annotation?\n" +
"THIS ACTION IS NOT REVERSIBLE!",
"Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (response == JOptionPane.NO_OPTION) delete = false;
else if (response == JOptionPane.YES_OPTION) delete = true;
else if (response == JOptionPane.CLOSED_OPTION) delete = false;
boolean delete = isYes(response);
if (delete) {
int index = corpus.getCurrentAnnotationIndex();
......@@ -561,7 +565,15 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
}
}
private void actionButtonAddAnnotation() {
public static boolean isYes(int response) {
boolean answer = false;
if (response == JOptionPane.NO_OPTION) answer = false;
else if (response == JOptionPane.YES_OPTION) answer = true;
else if (response == JOptionPane.CLOSED_OPTION) answer = false;
return answer;
}
private void actionButtonAddAnnotation() {
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\n\n" +
"If this is a preposition please add \"-p\" (e.g. on-p).", "Add annotation",
......@@ -807,7 +819,7 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
new JOptionPane().showMessageDialog(this, msg, "About", JOptionPane.INFORMATION_MESSAGE);
}
public String getListStr(ArrayList<String[]> items) {
private String getListStr(ArrayList<String[]> items) {
String listStr = "";
for (String[] strings : items) {
listStr += strings[0] + "\t" + strings[1] + " ";
......@@ -819,11 +831,11 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
return listStr.trim();
}
public String getTerminalsList() {
String getTerminalsList() {
return getListStr(terminalsList);
}
public String getNonTerminalsList() {
String getNonTerminalsList() {
return getListStr(nonTerminalsList);
}
}
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