001 package edu.upenn.cis.propbank_shen;
002
003 import java.io.*;
004 import java.util.List;
005 import java.util.LinkedList;
006
007 import org.w3c.dom.Node;
008 import org.w3c.dom.Attr;
009 import org.w3c.dom.NamedNodeMap;
010
011
012 /**
013 A class representing a "predicate" in the propbank frames. A predicate
014 is either the root form of a verb, such as "go", or it is a phrasalized
015 root form, such as "go on".
016
017 Phrasalized forms have their parts joined by underscores.
018 @author Scott Cotton
019 */
020 public class Predicate {
021 /** the lemma (root form) associate with the predicate */
022 protected String lemma;
023 /** the node from the xml document used to create this Predicate object */
024 protected Node node;
025 /** a list of the rolesets associated with this predicate
026 @see edu.upenn.cis.propbank_shen.RoleSet */
027 protected List rolesets;
028
029 /** the separator for phasal parts, here '_', so "go on" would be "go_on" */
030 public static String phrasalSep = "_";
031
032 /** construct a Predicate object from a predicate node in a frameset
033 xml document */
034 public Predicate(Node n) throws CorruptDataException
035 {
036 node = n;
037 lemma = null;
038 NamedNodeMap attrs = n.getAttributes();
039 int len = attrs.getLength();
040 for(int i=0; i<len; i++) {
041 Attr attr = (Attr) attrs.item(i);
042 if (attr.getNodeName().equals("lemma")) {
043 lemma = attr.getNodeValue();
044 break;
045 }
046 }
047 if (lemma == null) {
048 System.err.println("error with Predicate object, no lemma found");
049 }
050 rolesets = new LinkedList();
051 Node nc = node.getFirstChild();
052 while (nc != null) {
053 if (nc.getNodeName().equals("roleset")) {
054 rolesets.add(new RoleSet(nc));
055 }
056 nc = nc.getNextSibling();
057 }
058 }
059 // XXX add constructor from string
060
061 /** return the lemma associated with this Predicate object */
062 public String getLemma()
063 {
064 return lemma;
065 }
066
067 /** return true iff this Predicate object refers to a phrasal predicate */
068 public boolean isPhrasal()
069 {
070 return lemma.indexOf(Predicate.phrasalSep) != -1;
071 }
072
073 /**
074 Return a list of the rolesets associated with this Predicate object.
075 */
076 public List getRoleSets()
077 {
078 return rolesets;
079 }
080 }