Commit 909bd7f0 authored by Christos Christodoulopoulos's avatar Christos Christodoulopoulos
Browse files

Added a "View in Browser" for predicate frames

Fixed issue #5
parent 3e457cc5
No preview for this file type
......@@ -66,7 +66,7 @@ public class PBFramesetReader {
NodeList ndPredicate = doc.getElementsByTagName("predicate");
for (int i=0; i<ndPredicate.getLength(); i++) {
Element emPredicate = (Element)ndPredicate.item(i);
PBPredicate predicate = new PBPredicate();
PBPredicate predicate = new PBPredicate(lemma.contains("-p"));
predicate.setLemma(emPredicate.getAttribute("lemma").trim());
NodeList ndRoleset = emPredicate.getElementsByTagName("roleset");
......
......@@ -36,13 +36,16 @@ import java.util.Vector;
*/
public class PBPredicate {
private String lemma;
private boolean isPrep;
private Vector<PBRoleset> rolesets;
/**
* Initializes the predicate.
*/
public PBPredicate() {
* @param isPrep Whether the predicate is a preposition
*/
public PBPredicate(boolean isPrep) {
rolesets = new Vector<PBRoleset>();
this.isPrep = isPrep;
}
/**
......@@ -90,4 +93,8 @@ public class PBPredicate {
return ids;
}
public boolean isPrep() {
return isPrep;
}
}
......@@ -37,6 +37,9 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.StringTokenizer;
import java.util.Vector;
......@@ -46,7 +49,7 @@ public class JBFramesetPanel extends JPanel implements ActionListener, ItemListe
JComboBox<String> cb_roleset;
JTextField tf_predicate;
JTextArea ta_role;
JButton bt_example;
JButton bt_example, btOpenInBrowser;
PBFramesetReader fr_reader;
JBCorpus corpus = null;
JDCTextAreaFrame fr_example = null;
......@@ -86,11 +89,18 @@ public class JBFramesetPanel extends JPanel implements ActionListener, ItemListe
bt_example = new JButton("Example");
bt_example.addActionListener(this);
bt_example.setEnabled(false);
JPanel main = new JPanel();
btOpenInBrowser = new JButton("View in Browser");
btOpenInBrowser.addActionListener(this);
btOpenInBrowser.setEnabled(false);
JPanel main = new JPanel();
main.setLayout(new BorderLayout());
main.add(top, BorderLayout.CENTER);
main.add(bt_example, BorderLayout.EAST);
JPanel buttons = new JPanel(new BorderLayout());
buttons.add(bt_example, BorderLayout.NORTH);
buttons.add(btOpenInBrowser, BorderLayout.SOUTH);
main.add(buttons, BorderLayout.EAST);
add(main, BorderLayout.NORTH);
}
......@@ -106,13 +116,11 @@ public class JBFramesetPanel extends JPanel implements ActionListener, ItemListe
// ---------------------- utilties ----------------------
// called from PBToolKit
public void setCorpus(JBCorpus corpus)
{
public void setCorpus(JBCorpus corpus) {
this.corpus = corpus;
}
public String getRoleset()
{
public String getRoleset() {
return (String)cb_roleset.getSelectedItem();
}
......@@ -148,15 +156,22 @@ public class JBFramesetPanel extends JPanel implements ActionListener, ItemListe
ta_role.setText("");
bt_example.setEnabled(false);
}
if (frameset.getPredicate(vec_pNum.get(0)).isPrep())
btOpenInBrowser.setEnabled(false);
else
btOpenInBrowser.setEnabled(Desktop.isDesktopSupported());
corpus.getCurrentAnnotation().setRoleset((String) cb_roleset.getSelectedItem());
}
public void actionPerformed(ActionEvent e)
{
showExample();
public void actionPerformed(ActionEvent e) {
if (e.getSource() == bt_example)
showExample();
else if (e.getSource() == btOpenInBrowser)
openInBrowser();
}
public void showExample() {
PBPredicate predicate = frameset.getPredicate(getPredicateNum());
PBRoleset roleset = predicate.getRoleset(getRolesetNum());
......@@ -165,7 +180,19 @@ public class JBFramesetPanel extends JPanel implements ActionListener, ItemListe
fr_example.dispose();
fr_example = new JDCTextAreaFrame("Examples for "+roleset.getId(), roleset.getExamples());
}
private void openInBrowser() {
PBPredicate predicate = frameset.getPredicate(vec_pNum.get(0));
try {
String url = "http://verbs.colorado.edu/propbank/framesets-english/" + predicate.getLemma() + "-v.html";
Desktop.getDesktop().browse(new URI(url));
} catch (IOException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
public void viewRolesetComment() {
PBPredicate predicate = frameset.getPredicate(getPredicateNum());
PBRoleset roleset = predicate.getRoleset(getRolesetNum());
......
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