diva.sketch.recognition
Class TrainingParser

java.lang.Object
  |
  +--diva.util.aelfred.HandlerBase
        |
        +--diva.sketch.recognition.TrainingParser
All Implemented Interfaces:
ModelParser, XmlHandler

public class TrainingParser
extends HandlerBase
implements ModelParser

TrainingParser reads in an XML file and parses it into a TrainingModel data structure. The XML file should conform to train.dtd 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 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 TYPE_TAG
          Indicate a type in the training model.
static java.lang.String VERSION_TAG
          Indicate the version of this training model.
 
Constructor Summary
TrainingParser()
           
 
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 TrainingModel object.
 TrainingModel parse(java.io.Reader[] readers)
          Parses the training files into one training model and return the model.
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.
 
Methods inherited from class diva.util.aelfred.HandlerBase
charData, doctypeDecl, endDocument, endExternalEntity, error, ignorableWhitespace, processingInstruction, startDocument, startElement, 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.

DTD_URL

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

DTD_1

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

MODEL_TAG

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

VERSION_TAG

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

TYPE_TAG

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

NAME_TAG

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

EXAMPLE_TAG

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

LABEL_TAG

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

POINTS_TAG

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

TrainingParser

public TrainingParser()
Method Detail

attribute

public void attribute(java.lang.String name,
                      java.lang.String value,
                      boolean isSpecified)
Handle an attribute value assignment.
Overrides:
attribute in class HandlerBase
See Also:
com.microstar.xml.XmlHandler#attribute

endElement

public void endElement(java.lang.String name)
Handle the end of an element.
Overrides:
endElement in class HandlerBase
See Also:
com.microstar.xml.XmlHandler#endElement

parse

public TrainingModel parse(java.io.Reader[] readers)
                    throws java.lang.Exception
Parses the training files into one training model and return the model. The classes in the training files are combined. For exmple, if the "circle" class appears in several files, the examples for the "circle" class from these files are combined.

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 TrainingModel object.
Specified by:
parse in interface ModelParser

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 a modified URI (a string), an InputStream, or a Reader. In the latter two cases, the input character stream is provided.
Overrides:
resolveEntity in class HandlerBase
Parameters:
publicId - The public identifier, or null if none was supplied.
systemId - The system identifier.
Returns:
Null, indicating to use the default system identifier.


Contact 
©2002-2018 U.C. Regents