diva.sketch.recognition
Class SSTrainingParser

java.lang.Object
  extended by diva.util.aelfred.HandlerBase
      extended by diva.sketch.recognition.SSTrainingParser
All Implemented Interfaces:
XmlHandler, ModelParser

public class SSTrainingParser
extends HandlerBase
implements ModelParser

SSTrainingParser (Single Stroke Training Parser) reads in an XML file and parses it into a SSTrainingModel. The XML file should conform to singleStrokeTrain.dtd format so that it can be parsed correctly.

Version:
$Revision: 1.1 $
Author:
Heloise Hse (hwawen@eecs.berkeley.edu), Michael Shilman (michaels@eecs.berkeley.edu)

Field Summary
static String DTD_1
          The DTD for sketch files.
static String DTD_URL
          The URL where the DTD is stored.
static String EXAMPLE_TAG
          Indicate an example.
static String LABEL_TAG
          Indicate the label (positive or negative) for an example.
static String MODEL_TAG
          Indicate that the file contains a training model.
static String NAME_TAG
          Indicate the name of a type.
static String POINTS_TAG
          Indicate a set of points in a stroke.
static String PUBLIC_ID
          The public identity of the sketch dtd file.
static String TYPE_TAG
          Indicate a type in the training model.
static String VERSION_TAG
          Indicate the version of this training model.
 
Constructor Summary
SSTrainingParser()
           
 
Method Summary
 void attribute(String name, String value, boolean isSpecified)
          Handle an attribute value assignment.
 void endElement(String name)
          Handle the end of an element.
 Object parse(Reader reader)
          Create the full path string for the url and parses the file into a SSTrainingModel object.
 SSTrainingModel parse(Reader[] readers)
          Parses the training files into one training model and return the model.
static TimedStroke parsePoints(String val)
          val is a stream of numbers representing the points in a pen stroke.
 Object resolveEntity(String publicID, 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 String PUBLIC_ID
The public identity of the sketch dtd file.

See Also:
Constant Field Values

DTD_URL

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

See Also:
Constant Field Values

DTD_1

public static final String DTD_1
The DTD for sketch files.

See Also:
Constant Field Values

MODEL_TAG

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

See Also:
Constant Field Values

VERSION_TAG

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

See Also:
Constant Field Values

TYPE_TAG

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

See Also:
Constant Field Values

NAME_TAG

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

See Also:
Constant Field Values

EXAMPLE_TAG

public static final String EXAMPLE_TAG
Indicate an example.

See Also:
Constant Field Values

LABEL_TAG

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

See Also:
Constant Field Values

POINTS_TAG

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

See Also:
Constant Field Values
Constructor Detail

SSTrainingParser

public SSTrainingParser()
Method Detail

attribute

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

Specified by:
attribute in interface XmlHandler
Overrides:
attribute in class HandlerBase
value - The value of the attribute, or null if the attribute is #IMPLIED.
isSpecified - True if the value was specified, false if it was defaulted from the DTD.
See Also:
com.microstar.xml.XmlHandler#attribute

endElement

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

Specified by:
endElement in interface XmlHandler
Overrides:
endElement in class HandlerBase
Parameters:
name - The element type name.
See Also:
com.microstar.xml.XmlHandler#endElement

parse

public SSTrainingModel parse(Reader[] readers)
                      throws 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.

Throws:
Exception

parse

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

Specified by:
parse in interface ModelParser
Throws:
Exception

parsePoints

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


resolveEntity

public Object resolveEntity(String publicID,
                            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.

Specified by:
resolveEntity in interface XmlHandler
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.
See Also:
XmlHandler.resolveEntity(java.lang.String, java.lang.String)


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.