edu.upenn.cis.ptb.xpath
Class PTBNavigator
java.lang.Object
edu.upenn.cis.ptb.xpath.PTBNavigator
- All Implemented Interfaces:
- org.jaxen.Navigator, java.io.Serializable
- public class PTBNavigator
- extends java.lang.Object
- implements org.jaxen.Navigator
This interfaces with the Jaxen XPath API.
For example the following produces the total number of nodes selected by an
xpath expression:
public int getCount(String ptbRoot, String xpathExpr) throws Exception{
PTBNavigator nav = new PTBNavigator(null);
PTBXPath xp = (PTBXPath)(nav.parseXPath(xpathExpr));
int count = 0;
for(PTBTask task = new PTBTask(ptbRoot);task.hasNext();){
PTBTreeNode root = task.next();
for(Enumeration children = root.children(); children.hasMoreElements();){
nav.setRoot((PTBTreeNode)(children.nextElement()));
count += ((List)xp.evaluate(nav.getRoot())).size();
}
}
return count;
}
Basically each node in the tree behaves like an Element node, with the QName
equivalent to getLabel().getType(). See the PTBAttribute interface for the
list of attributes associated with the element. See PTBXPath for examples and discussion,
and
XPath recommendation for further
info on XPath.
The Function classes give extensions with which LPath expressions (Bird et al)
can be written. See the PTBXPath class for details.
- Author:
- nikhild
- See Also:
PTBAttribute,
PTBXPath,
Serialized Form
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
root
protected PTBTreeNode root
doc
protected PTBNavigator.PTBMRGDocument doc
EmptyIterator
public static final java.util.Iterator EmptyIterator
EmptyString
public static final java.lang.String EmptyString
- See Also:
- Constant Field Values
PTBNavigator
public PTBNavigator(PTBTreeNode root)
- Creates a new instance of PTBMRGNavigator
setRoot
public void setRoot(PTBTreeNode root)
getRoot
public PTBTreeNode getRoot()
getDocument
public PTBNavigator.PTBMRGDocument 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)