hhreco.recognition
Class MSTrainingParser

java.lang.Object
  extended byhhreco.util.aelfred.HandlerBase
      extended byhhreco.recognition.MSTrainingParser
All Implemented Interfaces:
ModelParser, XmlHandler

public class MSTrainingParser
extends HandlerBase
implements ModelParser

MSTrainingParser (Multi-Stroke Training Parser) reads in an XML file and parses it into a MSTrainingModel. The XML file should conform to DTD_1 format so that it can be parsed correctly.


Field Summary
static java.lang.String DTD_1
          The DTD for sketch files.
static java.lang.String DTD_URL
          The URL where the DTD is stored.
static java.lang.String EXAMPLE_TAG
          Indicate an example.
static java.lang.String LABEL_TAG
          Indicate the label (positive or negative) for an example.
static java.lang.String MODEL_TAG
          Indicate that the file contains a training model.
static java.lang.String NAME_TAG
          Indicate the name of a type.
static java.lang.String NUM_STROKE_TAG
          Indicate the number of strokes in an example.
static java.lang.String POINTS_TAG
          Indicate a set of points in a stroke.
static java.lang.String PUBLIC_ID
          The public identity of the sketch dtd file.
static java.lang.String STROKE_TAG
          Indicate a stroke path.
static java.lang.String TYPE_TAG
          Indicate a type in the training model.
static java.lang.String VERSION_TAG
          Indicate the version of this training model.
 
Constructor Summary
MSTrainingParser()
           
 
Method Summary
 void attribute(java.lang.String name, java.lang.String value, boolean isSpecified)
          Handle an attribute value assignment.
 void endElement(java.lang.String name)
          Handle the end of an element.
 java.lang.Object parse(java.io.Reader reader)
          Create the full path string for the url and parses the file into a MSTrainingModel object.
static TimedStroke parsePoints(java.lang.String val)
          val is a stream of numbers representing the points in a pen stroke.
 java.lang.Object resolveEntity(java.lang.String publicID, java.lang.String systemID)
          Resolve an external entity.
 void startElement(java.lang.String name)
          Handle the start of an element.
 
Methods inherited from class hhreco.util.aelfred.HandlerBase
charData, doctypeDecl, endDocument, endExternalEntity, error, ignorableWhitespace, processingInstruction, startDocument, startExternalEntity
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PUBLIC_ID

public static final java.lang.String PUBLIC_ID
The public identity of the sketch dtd file.

See Also:
Constant Field Values

DTD_URL

public static final java.lang.String DTD_URL
The URL where the DTD is stored.

See Also:
Constant Field Values

DTD_1

public static final java.lang.String DTD_1
The DTD for sketch files.

See Also:
Constant Field Values

MODEL_TAG

public static final java.lang.String MODEL_TAG
Indicate that the file contains a training model.

See Also:
Constant Field Values

VERSION_TAG

public static final java.lang.String VERSION_TAG
Indicate the version of this training model.

See Also:
Constant Field Values

TYPE_TAG

public static final java.lang.String TYPE_TAG
Indicate a type in the training model.

See Also:
Constant Field Values

NAME_TAG

public static final java.lang.String NAME_TAG
Indicate the name of a type.

See Also:
Constant Field Values

EXAMPLE_TAG

public static final java.lang.String EXAMPLE_TAG
Indicate an example.

See Also:
Constant Field Values

LABEL_TAG

public static final java.lang.String LABEL_TAG
Indicate the label (positive or negative) for an example.

See Also:
Constant Field Values

NUM_STROKE_TAG

public static final java.lang.String NUM_STROKE_TAG
Indicate the number of strokes in an example.

See Also:
Constant Field Values

POINTS_TAG

public static final java.lang.String POINTS_TAG
Indicate a set of points in a stroke.

See Also:
Constant Field Values

STROKE_TAG

public static final java.lang.String STROKE_TAG
Indicate a stroke path.

See Also:
Constant Field Values
Constructor Detail

MSTrainingParser

public MSTrainingParser()
Method Detail

attribute

public void attribute(java.lang.String name,
                      java.lang.String value,
                      boolean isSpecified)
Handle an attribute value assignment.

Specified by:
attribute in interface XmlHandler
Overrides:
attribute in class HandlerBase
See Also:
XmlHandler.attribute(java.lang.String, java.lang.String, boolean)

startElement

public void startElement(java.lang.String name)
Handle the start of an element.

Specified by:
startElement in interface XmlHandler
Overrides:
startElement in class HandlerBase
See Also:
XmlHandler.endElement(java.lang.String)

endElement

public void endElement(java.lang.String name)
Handle the end of an element.

Specified by:
endElement in interface XmlHandler
Overrides:
endElement in class HandlerBase
See Also:
XmlHandler.endElement(java.lang.String)

parse

public java.lang.Object parse(java.io.Reader reader)
                       throws java.lang.Exception
Create the full path string for the url and parses the file into a MSTrainingModel object.

Specified by:
parse in interface ModelParser
Throws:
java.lang.Exception

parsePoints

public static TimedStroke parsePoints(java.lang.String val)
val is a stream of numbers representing the points in a pen stroke. The format of each point is .


resolveEntity

public java.lang.Object resolveEntity(java.lang.String publicID,
                                      java.lang.String systemID)
Resolve an external entity. If the first argument is the name of the MoML PUBLIC DTD ("-//UC Berkeley//DTD train 1//EN"), then return a StringReader that will read the locally cached version of this DTD (the public variable DTD_1). Otherwise, return null, which has the effect of deferring to Ælfred for resolution of the URI. Derived classes may return a modified URI (a string), an InputStream, or a Reader. In the latter two cases, the input character stream is provided.

Specified by:
resolveEntity in interface XmlHandler
Overrides:
resolveEntity in class HandlerBase
Returns:
Null, indicating to use the default system identifier.
See Also:
diva.util.aelfred.XmlHandler#resolveEntity