edu.upenn.cis.pdtb.xpath
Class PDTBNavigator

java.lang.Object
  extended byedu.upenn.cis.pdtb.xpath.PDTBNavigator
All Implemented Interfaces:
org.jaxen.Navigator, java.io.Serializable

public class PDTBNavigator
extends java.lang.Object
implements org.jaxen.Navigator

This interfaces with the Jaxen XPath API. For example the following selects all the explicit relations with connective instead:

   ...           
   CorpusFileIterator cfi = new CorpusFileIterator(textRoot, ptbRoot, pdtbRoot);
   RelationLoader loader = new RelationLoaderImpl();
   PDTBNavigator nav = new PDTBNavigator(null);
   XPath xp = nav.parseXPath("//ExplicitRelation[@connHead='instead']");
   int totalCount = 0;
   while(cfi.hasMoreFiles()){
       cfi.nextFile();                
       String secNo = cfi.getSecNoStr();
       String fileNo = cfi.getFileNoStr(); 
       PDTBRelationList rlist = loader.loadRelations(textRoot, ptbRoot, pdtbRoot, secNo, fileNo);
       nav.setRoot(rlist);                
               
       List selectedNodes = xp.selectNodes(nav.getDocument());
               
       for(Iterator iter = selectedNodes.iterator(); iter.hasNext(); iter.next()){
           totalCount++;
       }
   }            
   System.err.println(totalCount);            
           
   ...
 

The PDTBTask class can be used to simplify the code above. The following is the list of Elements, their children, and attributes (the suffix * indicates optionality):

Element QNameChildren QNames Attribute QNames
RelationList ExplicitRelation*, ImplicitRelation*, AltLexRelation*, EntityRelation*, NoRelation*
ExplicitRelation Sup1*, Arg1, Arg2, Sup2* source, factuality, polarity, connHead
ImplicitRelation Sup1*, Arg1, Arg2, Sup2* source, factuality, polarity, type, eConn1*, semanticClass1*, eConn2*, semanticClass2*
AltLexRelation Sup1*, Arg1, Arg2, Sup2* source, factuality, polarity, semanticClass
EntityRelation Arg1, Arg2
NoRelation Arg1, Arg2
Arg1 source, factuality, polarity, rawText
Arg2 source, factuality, polarity, rawText
Sup1 rawText
Sup2 rawText

See the XPath recommendation for further info on XPath.

The second version fixes bugs in the parent axis and preceding axis.

Since:
0.1
Version:
2
Author:
nikhild
See Also:
PDTBTask, Serialized Form

Nested Class Summary
 class PDTBNavigator.PDTBDocument
           
 
Field Summary
protected  PDTBNavigator.PDTBDocument doc
           
static java.util.Iterator EmptyIterator
           
static java.lang.String EmptyString
           
protected  PDTBRelationList root
           
 
Constructor Summary
PDTBNavigator(PDTBRelationList root)
          Creates a new instance of PTBMRGNavigator
 
Method Summary
 java.util.Iterator getAncestorAxisIterator(java.lang.Object obj)
           
 java.util.Iterator getAncestorOrSelfAxisIterator(java.lang.Object obj)
           
 java.util.Iterator getAttributeAxisIterator(java.lang.Object obj)
           
 java.lang.String getAttributeName(java.lang.Object obj)
           
 java.lang.String getAttributeNamespaceUri(java.lang.Object obj)
           
 java.lang.String getAttributeQName(java.lang.Object obj)
           
 java.lang.String getAttributeStringValue(java.lang.Object obj)
           
 java.util.Iterator getChildAxisIterator(java.lang.Object obj)
           
 java.lang.String getCommentStringValue(java.lang.Object obj)
           
protected  java.util.Iterator getConcatenatedIterator(java.lang.Object obj, java.util.Iterator iter)
           
protected  java.util.Iterator getConcatenatedIterator(java.util.Stack iterators)
           
 java.util.Iterator getDescendantAxisIterator(java.lang.Object obj)
           
 java.util.Iterator getDescendantOrSelfAxisIterator(java.lang.Object obj)
           
 PDTBNavigator.PDTBDocument getDocument()
           
 java.lang.Object getDocument(java.lang.String str)
           
 java.lang.Object getDocumentNode(java.lang.Object obj)
           
 java.lang.Object getElementById(java.lang.Object obj, java.lang.String str)
           
 java.lang.String getElementName(java.lang.Object obj)
           
 java.lang.String getElementNamespaceUri(java.lang.Object obj)
           
 java.lang.String getElementQName(java.lang.Object obj)
           
 java.lang.String getElementStringValue(java.lang.Object obj)
           
 java.util.Iterator getFollowingAxisIterator(java.lang.Object obj)
           
 java.util.Iterator getFollowingSiblingAxisIterator(java.lang.Object obj)
           
 java.util.Iterator getNamespaceAxisIterator(java.lang.Object obj)
           
 java.lang.String getNamespacePrefix(java.lang.Object obj)
           
 java.lang.String getNamespaceStringValue(java.lang.Object obj)
           
 short getNodeType(java.lang.Object obj)
           
 java.util.Iterator getParentAxisIterator(java.lang.Object obj)
           
 java.lang.Object getParentNode(java.lang.Object obj)
           
 java.util.Iterator getPrecedingAxisIterator(java.lang.Object obj)
           
 java.util.Iterator getPrecedingSiblingAxisIterator(java.lang.Object obj)
           
 java.lang.String getProcessingInstructionData(java.lang.Object obj)
           
 java.lang.String getProcessingInstructionTarget(java.lang.Object obj)
           
 PDTBRelationList getRoot()
           
 java.util.Iterator getSelfAxisIterator(java.lang.Object obj)
           
 java.lang.String getTextStringValue(java.lang.Object obj)
           
 boolean isAttribute(java.lang.Object obj)
           
 boolean isComment(java.lang.Object obj)
           
 boolean isDocument(java.lang.Object obj)
           
 boolean isElement(java.lang.Object obj)
           
 boolean isNamespace(java.lang.Object obj)
           
 boolean isProcessingInstruction(java.lang.Object obj)
           
 boolean isText(java.lang.Object obj)
           
static void main(java.lang.String[] args)
           
 org.jaxen.XPath parseXPath(java.lang.String str)
           
 void setRoot(PDTBRelationList root)
           
 java.lang.String translateNamespacePrefixToUri(java.lang.String str, java.lang.Object obj)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

root

protected PDTBRelationList root

doc

protected PDTBNavigator.PDTBDocument doc

EmptyIterator

public static final java.util.Iterator EmptyIterator

EmptyString

public static final java.lang.String EmptyString
See Also:
Constant Field Values
Constructor Detail

PDTBNavigator

public PDTBNavigator(PDTBRelationList root)
Creates a new instance of PTBMRGNavigator

Method Detail

setRoot

public void setRoot(PDTBRelationList root)

getRoot

public PDTBRelationList getRoot()

getDocument

public PDTBNavigator.PDTBDocument getDocument()

getConcatenatedIterator

protected java.util.Iterator getConcatenatedIterator(java.lang.Object obj,
                                                     java.util.Iterator iter)

getConcatenatedIterator

protected java.util.Iterator getConcatenatedIterator(java.util.Stack iterators)

getAncestorAxisIterator

public java.util.Iterator getAncestorAxisIterator(java.lang.Object obj)
                                           throws org.jaxen.UnsupportedAxisException
Specified by:
getAncestorAxisIterator in interface org.jaxen.Navigator
Throws:
org.jaxen.UnsupportedAxisException

getAncestorOrSelfAxisIterator

public java.util.Iterator getAncestorOrSelfAxisIterator(java.lang.Object obj)
                                                 throws org.jaxen.UnsupportedAxisException
Specified by:
getAncestorOrSelfAxisIterator in interface org.jaxen.Navigator
Throws:
org.jaxen.UnsupportedAxisException

getAttributeAxisIterator

public java.util.Iterator getAttributeAxisIterator(java.lang.Object obj)
                                            throws org.jaxen.UnsupportedAxisException
Specified by:
getAttributeAxisIterator in interface org.jaxen.Navigator
Throws:
org.jaxen.UnsupportedAxisException

getAttributeName

public java.lang.String getAttributeName(java.lang.Object obj)
Specified by:
getAttributeName in interface org.jaxen.Navigator

getAttributeNamespaceUri

public java.lang.String getAttributeNamespaceUri(java.lang.Object obj)
Specified by:
getAttributeNamespaceUri in interface org.jaxen.Navigator

getAttributeQName

public java.lang.String getAttributeQName(java.lang.Object obj)
Specified by:
getAttributeQName in interface org.jaxen.Navigator

getAttributeStringValue

public java.lang.String getAttributeStringValue(java.lang.Object obj)
Specified by:
getAttributeStringValue in interface org.jaxen.Navigator

getChildAxisIterator

public java.util.Iterator getChildAxisIterator(java.lang.Object obj)
                                        throws org.jaxen.UnsupportedAxisException
Specified by:
getChildAxisIterator in interface org.jaxen.Navigator
Throws:
org.jaxen.UnsupportedAxisException

getCommentStringValue

public java.lang.String getCommentStringValue(java.lang.Object obj)
Specified by:
getCommentStringValue in interface org.jaxen.Navigator

getDescendantAxisIterator

public java.util.Iterator getDescendantAxisIterator(java.lang.Object obj)
                                             throws org.jaxen.UnsupportedAxisException
Specified by:
getDescendantAxisIterator in interface org.jaxen.Navigator
Throws:
org.jaxen.UnsupportedAxisException

getDescendantOrSelfAxisIterator

public java.util.Iterator getDescendantOrSelfAxisIterator(java.lang.Object obj)
                                                   throws org.jaxen.UnsupportedAxisException
Specified by:
getDescendantOrSelfAxisIterator in interface org.jaxen.Navigator
Throws:
org.jaxen.UnsupportedAxisException

getDocument

public java.lang.Object getDocument(java.lang.String str)
                             throws org.jaxen.FunctionCallException
Specified by:
getDocument in interface org.jaxen.Navigator
Throws:
org.jaxen.FunctionCallException

getDocumentNode

public java.lang.Object getDocumentNode(java.lang.Object obj)
Specified by:
getDocumentNode in interface org.jaxen.Navigator

getElementById

public java.lang.Object getElementById(java.lang.Object obj,
                                       java.lang.String str)
Specified by:
getElementById in interface org.jaxen.Navigator

getElementName

public java.lang.String getElementName(java.lang.Object obj)
Specified by:
getElementName in interface org.jaxen.Navigator

getElementNamespaceUri

public java.lang.String getElementNamespaceUri(java.lang.Object obj)
Specified by:
getElementNamespaceUri in interface org.jaxen.Navigator

getElementQName

public java.lang.String getElementQName(java.lang.Object obj)
Specified by:
getElementQName in interface org.jaxen.Navigator

getElementStringValue

public java.lang.String getElementStringValue(java.lang.Object obj)
Specified by:
getElementStringValue in interface org.jaxen.Navigator

getFollowingAxisIterator

public java.util.Iterator getFollowingAxisIterator(java.lang.Object obj)
                                            throws org.jaxen.UnsupportedAxisException
Specified by:
getFollowingAxisIterator in interface org.jaxen.Navigator
Throws:
org.jaxen.UnsupportedAxisException

getFollowingSiblingAxisIterator

public java.util.Iterator getFollowingSiblingAxisIterator(java.lang.Object obj)
                                                   throws org.jaxen.UnsupportedAxisException
Specified by:
getFollowingSiblingAxisIterator in interface org.jaxen.Navigator
Throws:
org.jaxen.UnsupportedAxisException

getNamespaceAxisIterator

public java.util.Iterator getNamespaceAxisIterator(java.lang.Object obj)
                                            throws org.jaxen.UnsupportedAxisException
Specified by:
getNamespaceAxisIterator in interface org.jaxen.Navigator
Throws:
org.jaxen.UnsupportedAxisException

getNamespacePrefix

public java.lang.String getNamespacePrefix(java.lang.Object obj)
Specified by:
getNamespacePrefix in interface org.jaxen.Navigator

getNamespaceStringValue

public java.lang.String getNamespaceStringValue(java.lang.Object obj)
Specified by:
getNamespaceStringValue in interface org.jaxen.Navigator

getNodeType

public short getNodeType(java.lang.Object obj)
Specified by:
getNodeType in interface org.jaxen.Navigator

getParentAxisIterator

public java.util.Iterator getParentAxisIterator(java.lang.Object obj)
                                         throws org.jaxen.UnsupportedAxisException
Specified by:
getParentAxisIterator in interface org.jaxen.Navigator
Throws:
org.jaxen.UnsupportedAxisException

getParentNode

public java.lang.Object getParentNode(java.lang.Object obj)
                               throws org.jaxen.UnsupportedAxisException
Specified by:
getParentNode in interface org.jaxen.Navigator
Throws:
org.jaxen.UnsupportedAxisException

getPrecedingAxisIterator

public java.util.Iterator getPrecedingAxisIterator(java.lang.Object obj)
                                            throws org.jaxen.UnsupportedAxisException
Specified by:
getPrecedingAxisIterator in interface org.jaxen.Navigator
Throws:
org.jaxen.UnsupportedAxisException

getPrecedingSiblingAxisIterator

public java.util.Iterator getPrecedingSiblingAxisIterator(java.lang.Object obj)
                                                   throws org.jaxen.UnsupportedAxisException
Specified by:
getPrecedingSiblingAxisIterator in interface org.jaxen.Navigator
Throws:
org.jaxen.UnsupportedAxisException

getProcessingInstructionData

public java.lang.String getProcessingInstructionData(java.lang.Object obj)
Specified by:
getProcessingInstructionData in interface org.jaxen.Navigator

getProcessingInstructionTarget

public java.lang.String getProcessingInstructionTarget(java.lang.Object obj)
Specified by:
getProcessingInstructionTarget in interface org.jaxen.Navigator

getSelfAxisIterator

public java.util.Iterator getSelfAxisIterator(java.lang.Object obj)
                                       throws org.jaxen.UnsupportedAxisException
Specified by:
getSelfAxisIterator in interface org.jaxen.Navigator
Throws:
org.jaxen.UnsupportedAxisException

getTextStringValue

public java.lang.String getTextStringValue(java.lang.Object obj)
Specified by:
getTextStringValue in interface org.jaxen.Navigator

isAttribute

public boolean isAttribute(java.lang.Object obj)
Specified by:
isAttribute in interface org.jaxen.Navigator

isComment

public boolean isComment(java.lang.Object obj)
Specified by:
isComment in interface org.jaxen.Navigator

isDocument

public boolean isDocument(java.lang.Object obj)
Specified by:
isDocument in interface org.jaxen.Navigator

isElement

public boolean isElement(java.lang.Object obj)
Specified by:
isElement in interface org.jaxen.Navigator

isNamespace

public boolean isNamespace(java.lang.Object obj)
Specified by:
isNamespace in interface org.jaxen.Navigator

isProcessingInstruction

public boolean isProcessingInstruction(java.lang.Object obj)
Specified by:
isProcessingInstruction in interface org.jaxen.Navigator

isText

public boolean isText(java.lang.Object obj)
Specified by:
isText in interface org.jaxen.Navigator

parseXPath

public org.jaxen.XPath parseXPath(java.lang.String str)
                           throws org.jaxen.saxpath.SAXPathException
Specified by:
parseXPath in interface org.jaxen.Navigator
Throws:
org.jaxen.saxpath.SAXPathException

translateNamespacePrefixToUri

public java.lang.String translateNamespacePrefixToUri(java.lang.String str,
                                                      java.lang.Object obj)
Specified by:
translateNamespacePrefixToUri in interface org.jaxen.Navigator

main

public static void main(java.lang.String[] args)