|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.alicebot.server.core.parser.GenericParser
public abstract class GenericParser
A generic parser.
Field Summary | |
---|---|
protected static java.lang.String |
ATOMIC_MARKER_END
The end of a tag marker for an "atomic" tag. |
protected static java.lang.String |
CLOSE_MARKER_START
The start of a tag marker for an element close tag. |
protected static java.lang.String |
COLON
A colon, for convenience. |
protected static java.lang.String |
COMMA
A comma, for convenience. |
protected static java.lang.String |
EMPTY_STRING
An empty string, for convenience. |
protected static java.lang.String |
INDEX
The word "index", for convenience. |
protected static java.lang.String |
NONATOMIC_MARKER_END
The end of a tag marker for a "non-atomic" tag. |
protected static java.lang.String |
OPEN_MARKER_START
The start of a tag marker for an element open tag. |
protected ClassRegistry |
processorRegistry
Each subclass should set this. |
Constructor Summary | |
---|---|
GenericParser()
|
Method Summary | |
---|---|
java.lang.String |
evaluate(int level,
java.util.LinkedList list)
Recursively evaluates an XML trie.; Both the level and the client id
are carried through recursion. |
java.lang.String |
formatTag(int level,
XMLNode tag)
Formats a tag from an XML node into "pure" ????. |
XMLNode |
getNode(java.lang.String tagname,
java.util.LinkedList list,
int ordernode)
Retrieves the ordernode-th node of a given tag at a particular level of the XML trie. |
static int |
getValid1dIndex(XMLNode tag)
Corrects a tag to use a valid 1-dimensional index, and returns the index. |
static int[] |
getValid2dIndex(XMLNode tag)
Corrects a tag to use a valid 2-dimensional index, and returns the indices. |
int |
nodeCount(java.lang.String tagname,
java.util.LinkedList list,
boolean allnodes)
Counts the number of nodes of a given type at a particular level of the XML trie. |
java.lang.String |
processResponse(java.lang.String content)
Processes a given XML content string for a given identifier. |
java.lang.String |
processTag(int level,
XMLNode tag)
Processes a given XML node for a given identifier. |
java.lang.String |
shortcutTag(int level,
java.lang.String rootTag,
int rootType,
java.lang.String rootAttr,
java.lang.String childTag,
int childType)
Creates a "mini-template" with a given tag and an optional child tag, then evaluates it recursively. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected ClassRegistry processorRegistry
protected static final java.lang.String EMPTY_STRING
protected static final java.lang.String OPEN_MARKER_START
protected static final java.lang.String CLOSE_MARKER_START
protected static final java.lang.String NONATOMIC_MARKER_END
protected static final java.lang.String ATOMIC_MARKER_END
protected static final java.lang.String INDEX
protected static final java.lang.String COMMA
protected static final java.lang.String COLON
Constructor Detail |
---|
public GenericParser()
Method Detail |
---|
public java.lang.String processResponse(java.lang.String content) throws ProcessorException
Processes a given XML content string for a given identifier.
This is the general access method for external classes.
content
- the XML content
id
ProcessorException
- if the content cannot be processedpublic java.lang.String processTag(int level, XMLNode tag) throws ProcessorException
level
- the current level in the XML trietag
- the tag being evaluated
ProcessorException
- if the content cannot be processedpublic java.lang.String evaluate(int level, java.util.LinkedList list)
Recursively evaluates an XML trie.;
Both the level
and the client id
are carried through recursion.
Depending on whether the engine is at load-time or run time, determines whether or not to process the tag. When the tag is processed, returns the result of processing it.
level
- the current level in the XML trielist
- the XML trie to parse
public java.lang.String formatTag(int level, XMLNode tag)
Formats a tag from an XML node into "pure" ????. Mostly used when a tag cannot be evaluated and then literally included in the input.
THIS WORDING NEEDS TO BE CLARIFIED.
level
- index of the current level in the XML trie (just passed through)tag
- the tag to format
public int nodeCount(java.lang.String tagname, java.util.LinkedList list, boolean allnodes)
Counts the number of nodes of a given type at a particular level of the XML trie.
Used mostly in connection with the <random/> tag in order to see how many candidate listItem structures are beneath it and to set the upper limit on the random number roll.
tagname
- the name of the tag soughtlist
- the XML trieallnodes
- if false, only count one of the desired type (just see if any are there)
1
if at least one node is present and allnodes
is falsepublic XMLNode getNode(java.lang.String tagname, java.util.LinkedList list, int ordernode)
Retrieves the ordernode-th node of a given tag at a particular level of the XML trie.
Typically used to find specific tags beneath a given tag being evaluated (e.g., an <li/> beneath a <random/>).
tagname
- the name of the tag soughtlist
- the XML trieordernode
- index of the node we sought
public java.lang.String shortcutTag(int level, java.lang.String rootTag, int rootType, java.lang.String rootAttr, java.lang.String childTag, int childType)
Creates a "mini-template" with a given tag and an optional child tag, then evaluates it recursively.
This method is used mostly to map certain tags as combinations of other tags (as in short-cut elements), as well as various "AIML 0.9" tags.
level
- the current level in the XML trierootTag
- the name of the root tagrootType
- the type of the root tagrootAttr
- an optional attribute on the root tag (use "" if no attribute)childTag
- the name of the child tagchildType
- the type of the child tag
public static int[] getValid2dIndex(XMLNode tag)
tag
- the tag whose 2-dimensional index we want
public static int getValid1dIndex(XMLNode tag)
tag
- the element whose 1-dimensional index we want
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |