Commit 05cf8764 authored by Christos Christodoulopoulos's avatar Christos Christodoulopoulos
Browse files

Fixed a bug with prep frameset lookup

Current context is now centered in context window
Switched CTRL key for a platform-independent mapping
Added code for the argument scope patch
parent 7e52924f
......@@ -145,7 +145,10 @@ public class JBCorpus {
// Start from copying the current annotation
JBDataStructure newAnnotation = null;
try {
String pbInstanceString = annotator + " " + lemma + " " + lemma + ".XX#";
String framesetLemma = lemma;
if (lemma.contains("-p"))
framesetLemma = lemma.split("-")[0];
String pbInstanceString = annotator + " " + lemma + " " + framesetLemma + ".XX#";
newAnnotation = new JBDataStructure(current.getTbTree().toTextTree(), pbInstanceString,
current.getIndexInContext());
} catch (Exception e) {
......
......@@ -27,6 +27,7 @@ import jubilee.datastructure.JBDataStructure;
import jubilee.util.DataManager;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
......@@ -45,13 +46,15 @@ public class JBMenuBar extends JMenuBar {
JMenuItem[] argArgs, argFunc;
JMenuItem argErase;
JMenuItem helpAbout;
/**
private int menuShortcutKeyMask;
/**
* Creates a menubar.
* @param jbtk parent class.
*/
public JBMenuBar(JBToolkit jbtk) {
this.jbtk = jbtk;
this.menuShortcutKeyMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
initMenuFile();
initMenuTreebank();
......@@ -91,18 +94,18 @@ public class JBMenuBar extends JMenuBar {
private void initMenuFile() {
JMenu mFile = new JMenu("File");
mFile.setMnemonic(KeyEvent.VK_F);
fileOpen = getJMenuItem("Open", KeyEvent.VK_O, KeyEvent.VK_O, KeyEvent.CTRL_MASK);
fileOpen = getJMenuItem("Open", KeyEvent.VK_O, KeyEvent.VK_O, menuShortcutKeyMask);
mFile.add(fileOpen);
mFile.addSeparator();
fileSave = getJMenuItem("Save", KeyEvent.VK_S, KeyEvent.VK_S, KeyEvent.CTRL_MASK);
fileSave = getJMenuItem("Save", KeyEvent.VK_S, KeyEvent.VK_S, menuShortcutKeyMask);
mFile.add(fileSave);
fileSaveAs = getJMenuItem("Save As", KeyEvent.VK_A);
fileSaveAs = getJMenuItem("Save As", KeyEvent.VK_A, KeyEvent.VK_S, menuShortcutKeyMask+KeyEvent.SHIFT_MASK);
mFile.add(fileSaveAs);
mFile.addSeparator();
fileQuit = getJMenuItem("Quit", KeyEvent.VK_Q, KeyEvent.VK_Q, KeyEvent.CTRL_MASK);
fileQuit = getJMenuItem("Quit", KeyEvent.VK_Q, KeyEvent.VK_Q, menuShortcutKeyMask);
mFile.add(fileQuit);
add(mFile);
......@@ -116,10 +119,10 @@ public class JBMenuBar extends JMenuBar {
mTreebank.add(tbPrev);
tbNext = getJMenuItem("Next Tree", KeyEvent.VK_N, KeyEvent.VK_PERIOD, 0);
mTreebank.add(tbNext);
tbJump = getJMenuItem("Jump To", KeyEvent.VK_J, KeyEvent.VK_J, KeyEvent.CTRL_MASK);
tbJump = getJMenuItem("Jump To", KeyEvent.VK_J, KeyEvent.VK_J, menuShortcutKeyMask);
mTreebank.add(tbJump);
mTreebank.addSeparator();
tbView = getJMenuItem("Edit Tree", KeyEvent.VK_T, KeyEvent.VK_T, KeyEvent.CTRL_MASK);
tbView = getJMenuItem("Edit Tree", KeyEvent.VK_T, KeyEvent.VK_T, menuShortcutKeyMask);
mTreebank.add(tbView);
add(mTreebank);
......@@ -134,12 +137,12 @@ public class JBMenuBar extends JMenuBar {
fsNext = getJMenuItem("Next Roleset", KeyEvent.VK_N, KeyEvent.VK_CLOSE_BRACKET, 0);
mFrameset.add(fsNext);
fsViewExample = getJMenuItem("View Example", KeyEvent.VK_E, KeyEvent.VK_E, KeyEvent.CTRL_MASK);
fsViewExample = getJMenuItem("View Example", KeyEvent.VK_E, KeyEvent.VK_E, menuShortcutKeyMask);
mFrameset.add(fsViewExample);
fsViewArgument = getJMenuItem("View Arguments", KeyEvent.VK_W, KeyEvent.VK_W, KeyEvent.CTRL_MASK);
fsViewArgument = getJMenuItem("View Arguments", KeyEvent.VK_W, KeyEvent.VK_W, menuShortcutKeyMask);
mFrameset.add(fsViewArgument);
fsViewRolesetComment = getJMenuItem("View Roleset Comments", KeyEvent.VK_C, KeyEvent.VK_C, KeyEvent.CTRL_MASK);
fsViewRolesetComment = getJMenuItem("View Roleset Comments", KeyEvent.VK_C, KeyEvent.VK_C, menuShortcutKeyMask);
mFrameset.add(fsViewRolesetComment);
add(mFrameset);
......@@ -161,7 +164,7 @@ public class JBMenuBar extends JMenuBar {
for (int i=0; i<operators.size(); i++) {
String[] operator = operators.get(i);
argFunc[i] = getJMenuItem(operator[0], 0, operator[1].charAt(0), KeyEvent.CTRL_MASK+KeyEvent.SHIFT_MASK);
argFunc[i] = getJMenuItem(operator[0], 0, operator[1].charAt(0), menuShortcutKeyMask+KeyEvent.SHIFT_MASK);
mArgFunc.add(argFunc[i]);
}
......@@ -178,16 +181,8 @@ public class JBMenuBar extends JMenuBar {
add(mHelp);
}
// set menu-item with name, short-key
private JMenuItem getJMenuItem(String text, int mnemonic) {
JMenuItem mi = new JMenuItem(text, mnemonic);
mi.addActionListener(jbtk);
return mi;
}
// set menu-item with name, short-key, accelerator
// set menu-item with name, short-key, accelerator
private JMenuItem getJMenuItem(String text, int mnemonic, int keyCode, int modifiers) {
JMenuItem mi = new JMenuItem(text, mnemonic);
......
......@@ -72,8 +72,9 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
int i_maxAnn;
static public String s_sysDir = null;
private JScrollPane sentencePane;
public JBToolkit(String title, String sysDir, String userID, final int maxAnn) {
public JBToolkit(String title, String sysDir, String userID, final int maxAnn) {
super(title);
str_frameTitle = title;
s_sysDir = sysDir;
......@@ -145,7 +146,7 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
ta_context = new JTextArea();
ta_context.setEditable(false);
ta_context.setBackground(Color.white);
ta_context.setRows(15);
ta_context.setRows(16);
ta_context.setLineWrap(true);
tv_tree = new JBTreePanel();
......@@ -189,7 +190,7 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
// bottom of the treeview
JScrollPane sentencePane = new JScrollPane(ta_context);
sentencePane = new JScrollPane(ta_context);
sentencePane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JPanel bottomPanel = new JPanel();
......@@ -336,10 +337,17 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
else tf_annotator.setBackground(Color.LIGHT_GRAY);
// Update the context window
int bId = 0, eId = -1;
for (int i=0; i<=corpus.getCurrentAnnotation().getIndexInContext(); i++) {
bId = eId + 1;
eId = ta_context.getText().indexOf("\n", bId);
int bId = 0, eId = -1, bExtraId = 0, eExtraId = -1;
int indexInContext = corpus.getCurrentAnnotation().getIndexInContext();
// Set the caret position so that the highlighted text is shown in the middle
int extraLines = Math.min(indexInContext + 8, corpus.getContexts().size());
for (int i = 0; i <= extraLines; i++) {
if (i <= indexInContext) {
bId = eId + 1;
eId = ta_context.getText().indexOf("\n", bId);
}
bExtraId = eExtraId + 1;
eExtraId = ta_context.getText().indexOf("\n", bExtraId);
}
Highlighter h = ta_context.getHighlighter();
......@@ -348,7 +356,7 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
h.addHighlight(bId, eId, new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW));
}
catch (BadLocationException e) {e.printStackTrace();}
ta_context.setCaretPosition(bId);
ta_context.setCaretPosition(bExtraId);
}
private void updateGoldList() {
......@@ -408,7 +416,8 @@ public class JBToolkit extends JFrame implements ActionListener, ItemListener, L
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", "Add annotation",
"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",
JOptionPane.QUESTION_MESSAGE);
if (response != null) {
......
......@@ -44,7 +44,7 @@ public class Jubilee {
catch (IllegalAccessException e) {e.printStackTrace();}
String usage = "Usage: java -jar jubilee.jar -u <userId> [-m <max-annotations=2> -s <system-folder=system>]";
String title = "Jubilee 3.10";
String title = "Jubilee 3.21";
String userId = null;
int maxAnn = 2;
String sysDir = "system" + File.separator;
......
......@@ -409,7 +409,10 @@ public class TBTree {
private void fixArgSpanInternal(TBNode node) {
if (node.getArg() != null && node.getParent() != null) {
if (getWordsAux(node, " ") != null && getWordsAux(node.getParent(), " ") != null) {
if (getWordsAux(node, " ").equals(getWordsAux(node.getParent(), " ")) && node.getArg().startsWith("A")) {
// use this for verb arguments
// if (getWordsAux(node, " ").equals(getWordsAux(node.getParent(), " ")) && node.getArg().startsWith("A")) {
// us this for prep arguments
if (node.getArg().contains("OBJ")) {
String loc = node.getLoc();
int splitPoint = loc.lastIndexOf(":");
String token = loc.substring(0, splitPoint);
......
package jubilee.util;
import jubilee.datastructure.JBCorpus;
import jubilee.datastructure.JBDataStructure;
import jubilee.treebank.TBTree;
import org.json.JSONException;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
/**
* A patch that fixes the placements of argument labels. It propagates each arg label to its maximum projection.
* NB: Propositions containing references (*) are excluded from the patch.
*/
public class FixArgs {
public static void main(String[] args) throws IOException, JSONException {
String annotator = args[0];
fixDirFiles(new File("resource/annotation"), annotator);
fixDirFiles(new File("resource/task"), annotator);
}
private static void fixDirFiles(File dir, String annotator) throws IOException, JSONException {
String[] list = dir.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return !name.endsWith("bak") && !name.startsWith(".");
}
});
for (String fileName : list) {
String file = dir + "/" + fileName;
System.out.println("Patching " + file);
JBCorpus corpus = new JBCorpus(file, annotator);
corpus.saveCorpus(file + ".bak");
for (int i = 0; i < corpus.getSize(); i++) {
JBDataStructure dataStructure = corpus.getAnnotation(i);
TBTree tree = dataStructure.getTbTree();
tree.fixArgSpan();
corpus.replaceAnnotation(i, dataStructure);
}
corpus.saveCorpus(file);
}
}
}
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