The saibabml parser is a Java reference implementation of an XML parser for the Behavior Markup Language(BML). Since parsing BML and obtaining constraints between sync points in behaviors specified in BML is a non-trivial endeavor, it is useful to have such a standard implementation. saibabml is currently used as the BML parser in the AsapRealizer BML realizer.
The latest jar files for saibabml can be found at
http://hmirepo.ewi.utwente.nl/external/java/saiba/
The saibabml directory contains the library itself, saibabml-test contains a jar file with test utilities that can be employed in junit tests of ones own BML behaviors or extensions.
saibabml is compiled and built using apache ant. Use
ant compile
to compile;
ant dist
to generate the jar files for saibabml from source. The jar files are placed in the dist directory. Other useful ant targets are
doc: generate the javadoc (in the docs directory)
junitreport: run the testcases and generate a test report (in test/report)
SaibaBML Javadoc
SaibaBMLTest Javadoc
BMLParser parser = new BMLParser();
BehaviourBlock bb = new BehaviourBlock();
bb.readXML(...
parser.addBehaviourBlock(bb);
The result of the parse is a list of constraints and behaviours that can be obtained using the parser.getBehaviours() and parser.getConstraints() function. The parser may resolve constraints over multiple BehaviourBlocks (not tested very thoroughly), but typically it is cleaned using parser.clean() with each new block to parse.
BML behaviours may contain custom attributes.
For example:
<gesture id="g1"lexeme="BEAT"
xmlns:customattr="http://www.custom.com" customattr:amplitude="3">
Your custom amplitude attribute has to be registered as a gesture specific custom attribute as follows:
BMLInfo.addCustomFloatAttribute(GestureBehaviour.class,
"http://www.custom.com","amplitude");
Then you can use
float value =
behavior.getFloatParameterValue("http://www.custom.com:amplitude");
or
String value =
behavior.getStringParameterValue("http://www.custom.com:amplitude");
to obtain the value of the custom amplitude attribute.
Custom behaviours are constructed by creating a class for them that extends Behaviour.
The custom behaviour class should be registered as follows:
BMLInfo.addBehaviourType(CustomBehaviour.xmlTag(), CustomBehaviour.class);
saiba.bml.AbstractBehaviourTest (in saibabml-test.jar) provides a test set for such custom behaviours. See for example saiba.bml.ext.FaceFacsBehaviourTest for an example of its usage.
Description extensions are to be implemented as classes that extend Behaviour. They are registered as follows:
BMLInfo.addDescriptionExtension(CustomExtBehaviour.xmlTag(), CustomExt.class);
BML blocks may contain composition elements beyond those of core BML, and custom attributes may be used within a bml block (rather than within a behaviour). For example, AsapRealizer allows a preplan attribute to be used within bml, and provides the CHUNK-AFTER composition. Example:
<bml xmlns="http://www.bml-initiative.org/bml/bml-1.0" id="bml1"
composition="CHUNK-AFTER(bml2,bml3)" xmlns:bmlt="http://hmi.ewi.utwente.nl/bmlt"
bmlt:preplan="true">
To handle such elements, a BMLBehaviorAttributeExtension can be defined:
class BMLBBMLBehaviorAttributes implements BMLBehaviorAttributeExtension
{
void decodeAttributes(BehaviourBlock bb,
HashMap<String, String> attrMap, XMLTokenizer tok)
{
//handle custom attributes
//e.g.
boolean prePlan = bb.getOptionalBooleanAttribute(
"http://hmi.ewi.utwente.nl/bmlt:preplan", attrMap, false);
}
BMLBlockComposition handleComposition(String sm)
{
//Parse the composition mechanism. If this extension cannot parse it, return
//CoreSchedulingMechanism.UNKOWN, so that another extension may try to take it.
}
}
This BMLBehaviorAttributeExtension is then provided to the BehaviourBlock:
BMLBBMLBehaviorAttributes bbmlbExt = new BMLBBMLBehaviorAttributes();
BehaviourBlock block = new BehaviourBlock(bbmlbExt);