I'd like to use Seshat—a handwritten math expression parser—for a project I'm working on, but I'm having some trouble understanding how to provide the program its proper input, an InkML or SCG Ink file.
I've taken a long look at an online example that exists here, and I see that they get a Javascript array of stroke information from an HTML Canvas field with this JS library applied, but I don't know what happens that array after it gets POSTed to their server.
I've read the SCG Ink spec, and I think it might be relatively easy to parse the array into the format, but I'm hoping there's something obvious I'm missing that would make this trivial. Any help would be greatly appreciated.
I emailed the Seshat author and he suggested I convert the input to SCG Ink, which turned out to be pretty easy if you take the JavaScript libraries used at http://cat.prhlt.upv.es/mer/. Specifically, you want
jquery.sketchable.memento.min.js
,jquery.sketchable.min.js
, andjsketch.min.js
in addition to regular old jQuery. Here's what I did in case anyone else is interested in Seshat.Notice from the same page that in
main.js
they apply the Sketchable library to the HTML canvas area with this block of code:Now we can take a look at their
submitStrokes()
function to see how to take the strokes from Sketchable and convert to SCG Ink. The linevar strokes = $canvas.sketchable('strokes');
gets the strokes, and then the linestrokes = transform(strokes);
applies a quick transformation to extract only the data they need. Here's thetransform()
function for reference:The value returned fro
transform()
is a three-dimensional array of strokes and points. (Each element of the first dimension is a stroke, each element of the second dimension is a point, and the third dimension is x-, y-coordinates.) On that site they go ahead and POST that array to the server which must handle the final conversion to SCG Ink. I wrote a JavaScript function to handle it:And that's it. The value returned from
strokesToScg()
is a string describing a series of strokes in the SCG Ink format.