001    package edu.upenn.cis.propbank_shen;
002    
003    import java.util.LinkedList;
004    import java.util.List;
005    
006    import org.w3c.dom.Node;
007    import org.w3c.dom.NamedNodeMap;
008    import org.w3c.dom.Attr;
009    
010    
011    /**
012       This class represents a "role" in the propbank lexical guidelines. 
013    
014       A role may consist of a number of things.  All roles have an associated
015       argument label. 
016       @see edu.upenn.cis.propbank_shen.ArgLabel
017       @author Scott Cotton
018     */
019    public class Role {
020    
021        /** the node of the xml document from which this thing was made */
022        protected Node node;
023        /** a description of the role */
024        protected String descr;
025        /** the argument label associated with the role 
026            @see edu.upenn.cis.propbank_shen.ArgLabel */
027        protected ArgLabel arglabel;
028        /** the modifying label associated with the roleset, or null
029            if there is none.
030            @see edu.upenn.cis.propbank_shen.ModLabel
031        */
032        protected ModLabel modlabel;
033        /**
034           A list of the verbnet roles associated with the role.
035           @see edu.upenn.cis.propbank_shen.VNRole
036        */
037        protected List vnroles;
038        
039        /**
040           construct a Role object from a role node in a frameset 
041           xml document.
042         */
043        public Role(Node n) throws CorruptDataException
044        {
045            node = n;
046            NamedNodeMap attrs = n.getAttributes();
047            int len = attrs.getLength();
048            String anm = null;
049            for(int i=0; i<len; i++) {
050                Attr attr = (Attr) attrs.item(i);
051                anm = attr.getNodeName();
052                if (anm.equals("descr")) {
053                    descr = attr.getNodeValue();
054                } else if (anm.equals("n")) {
055                    arglabel = ArgLabel.ofString("Arg" + attr.getNodeValue());
056                } else if (anm.equals("f")) {
057                    modlabel = ModLabel.ofString(attr.getNodeValue());
058                }
059            }
060            vnroles = new LinkedList();
061            Node nc = node.getFirstChild();
062            while (nc != null) {
063                if (nc.getNodeName().equals("vnrole")) {
064                    vnroles.add((Object) new VNRole(nc));
065                }
066                nc = nc.getNextSibling();
067            }
068        }
069        
070        /** return the brief description of the role */
071        public String getDescription() 
072        {
073            return descr;
074        }
075    
076        /** return the associated argument label */
077        public ArgLabel getArgLabel() 
078        {
079            return arglabel;
080        }
081    
082        /** 
083            return the associated modifying label, or null
084            if there is no such modifying label.
085            @see edu.upenn.cis.propbank_shen.ModLabel
086        */
087        public ModLabel getModLabel() 
088        {
089            return modlabel;
090        }
091    
092        /** return true iff this role has a modifying label 
093            @see edu.upenn.cis.propbank_shen.ModLabel */
094        public boolean hasModLabel() 
095        {
096            return modlabel != null;
097        }
098    
099        /**
100           return a list (possibly empty) of the associated VerbNet roles
101           see also the <a href="http://www.cis.upenn.edu/verbnet">VerbNet website</a>
102        */
103        public List getVNRoles() 
104        {
105            return vnroles;
106        }
107    }