diva.sketch.parser2d
Class ParsingSceneRecognizer

java.lang.Object
  extended by diva.sketch.parser2d.ParsingSceneRecognizer
All Implemented Interfaces:
SceneRecognizer

public class ParsingSceneRecognizer
extends Object
implements SceneRecognizer

A grammar-driven scene recognizer that incrementally parses the scene as new tokens are added. Unlike standard parsers, this parser understands the ambiguity in drawings that are imperfectly recognized and simultaneously considers all possible interpretations of the scene. This makes the parser less efficient than a typical string parser, but the parser utilizes incrementality and smart data structures help with the performance.

The grammar is expressed as an array of rules, and the rules are indexed inside the parser according to the types of tokens that they consume. This means that every time a token is added to the scene, the appropriate rules are retrieved from the index and the rest of the required tokens are searched for in the database. All permutations of possible matches are fed to a rule, and if the rule matches, the resulting token is fed back into the process.

Version:
$Revision: 1.13 $
Author:
Michael Shilman (michaels@eecs.berkeley.edu)
See Also:
Grammar2D

Constructor Summary
ParsingSceneRecognizer(SceneRecognizer child, Grammar2D grammar)
          Construct a new parser with the specified grammar rules, that uses the given child recognizer to perform lower-level recognition.
 
Method Summary
static void debug(String s)
          Debugging output.
 Grammar2D getGrammar()
          Return the grammar that is used to perform the parsing.
protected  SceneDeltaSet handleDeltas(SceneDeltaSet deltas, Scene db)
          Handle any deltas that may have occurred in the scene from the addition, modification, or completion of strokes/sessions to the scene database.
 SceneDeltaSet parse(CompositeElement e, Scene db)
          Perform a recursive, incremental parse of the element in the given scene, adding the results to the given delta set.
 SceneDeltaSet sessionCompleted(StrokeElement[] session, Scene db)
          Pass the "session started" information to the child recognizer and handle the results if there are changes in the scene.
 SceneDeltaSet strokeCompleted(StrokeElement stroke, Scene db)
          Pass the "stroke completed" information to the child recognizer and handle the results if there are changes in the scene.
 SceneDeltaSet strokeModified(StrokeElement stroke, Scene db)
          Pass the "stroke modified" information to the child recognizer and handle the results if there are changes in the scene.
 SceneDeltaSet strokeStarted(StrokeElement stroke, Scene db)
          Pass the "stroke started" information to the child recognizer and handle the results if there are changes in the scene.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParsingSceneRecognizer

public ParsingSceneRecognizer(SceneRecognizer child,
                              Grammar2D grammar)
Construct a new parser with the specified grammar rules, that uses the given child recognizer to perform lower-level recognition. The child recognizer can perform any type of recognition, ranging from single-stroke recognition to handwriting recognition to sub-languages defined in another parsing recognizer.

Method Detail

getGrammar

public Grammar2D getGrammar()
Return the grammar that is used to perform the parsing. The grammar consists of a set of rules and token types.


strokeStarted

public SceneDeltaSet strokeStarted(StrokeElement stroke,
                                   Scene db)
Pass the "stroke started" information to the child recognizer and handle the results if there are changes in the scene.

Specified by:
strokeStarted in interface SceneRecognizer

strokeModified

public SceneDeltaSet strokeModified(StrokeElement stroke,
                                    Scene db)
Pass the "stroke modified" information to the child recognizer and handle the results if there are changes in the scene.

Specified by:
strokeModified in interface SceneRecognizer

strokeCompleted

public SceneDeltaSet strokeCompleted(StrokeElement stroke,
                                     Scene db)
Pass the "stroke completed" information to the child recognizer and handle the results if there are changes in the scene.

Specified by:
strokeCompleted in interface SceneRecognizer

sessionCompleted

public SceneDeltaSet sessionCompleted(StrokeElement[] session,
                                      Scene db)
Pass the "session started" information to the child recognizer and handle the results if there are changes in the scene.

Specified by:
sessionCompleted in interface SceneRecognizer

handleDeltas

protected SceneDeltaSet handleDeltas(SceneDeltaSet deltas,
                                     Scene db)
Handle any deltas that may have occurred in the scene from the addition, modification, or completion of strokes/sessions to the scene database. The changes cause rules to fire, which are used to recursively compute more rules to fire, etc.


parse

public SceneDeltaSet parse(CompositeElement e,
                           Scene db)
Perform a recursive, incremental parse of the element in the given scene, adding the results to the given delta set.


debug

public static void debug(String s)
Debugging output.



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