[om] OM class
Cédric Vidrequin
Cedric.Vidrequin at avignon.inra.fr
Tue Apr 20 10:56:30 CEST 2004
Hello,
thanks for you reply ... I'll think about it (but I hope I'll not have
to develop it)
To be continued ...
Cédric VIDREQUIN
INRA Avignon (France)
Alberto González Palomo a écrit :
>On Mon, 19 Apr 2004 15:01:40 +0100
>Mike Dewar <miked at nag.co.uk> wrote:
>
>
>
>>On Mon, Apr 19, 2004 at 10:03:12AM +0200, Cédric Vidrequin wrote:
>>
>>
>>>Hello,
>>>I'm looking for a class (or a set of classes) that allows me to generate
>>>an XML file (or XML tree object) from an input string.
>>>
>>>For example : I have the string y = a*x+b
>>>I'm looking for something like that :
>>>String str = "y=a*x+b";
>>>// in the next line, types are imaginated to explain better what I'm
>>>looking for
>>>OpenMathObject omo = nex OpenMathObjetc(str);
>>>omo.writeXML(new outputStream("myFile.xml"));
>>>[...]
>>>
>>>
>>What you are asking for isn't really practical since it requires
>>knowledge of the syntax of your string, and that probably depends to the
>>application area that you are working in.
>>[...]
>>
>>
>
> This point is very important, but easy to overlook.
> Just look at the variety of ways of doing even elementary tasks
>among CAS systems:
>
>http://www.univ-orleans.fr/EXT/ASTEX/astex/doc/fr/rosetta/htmla/roseta.htm
>
> And this is within a single class of software that shares many
>conventions, such as using a dot as decimal separator instead of comma,
>and covers more or less the same concepts.
>
>
>
>>You can find a class library for creating and manipulating OpenMath
>>objects by following the links from www.openmath.org/software to "the
>>RIACA OpenMath Library". Alternativey, if your string uses the syntax
>>of a mathematical package such as GAP, Maple or Mathematica, you might
>>want to look at the phrasebooks for those systems. I believe that those
>>from RIACA (linked from the above page) are written in Java.
>>
>>
>
> As a part of the new exercise system in ActiveMath [1], I've
>written a parser library that produces a JDOM [2] XML tree with the
>OpenMath representation from a string written in a selectable syntax.
> The parser creation is like this:
>
>parser = CasParser.newCasParser(userInput, userInputSyntax);
>
> Where "userInput" is the input string, and "userInputSyntax"
>the identifier for the grammar you want to use. So far, there are 10
>parsers, that allow the user to choose among the syntaxes of the
>CAS systems Yacas, Maxima, Axiom, Maple(tm), Mathematica(R), MuPAD,
>Derive and REDUCE, and then a custom grammar for a specific application
>(that uses comma as decimal separator), and XML-encoded OpenMath.
> They only deal with the symbols we expect users to employ in their
>answers, not things like "for" loops, procedure or pattern definitions,
>etc.
> The parsers are made by the parser generator JavaCC. The article
>I used for learning how to use it is at:
>
>http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-cooltools.html
>
> Instead of operating on the parsed objects, you build the OM
>tree. For example, instead of the rule for <NUMBER> (second page, bottom):
>
> t=<NUMBER> { return Double.parseDouble(t.toString()); }
>
> I have this (once split NUMBER into DOUBLE and INTEGER):
>
> t=<INTEGER> { return omi(t.image); }
>| t=<DOUBLE> { return omf(t.image); }
>
> The function "omi()", for example, could be as follows:
>
>static Element omi(String n)
>{
> return (new Element("OMI", omNamespaceUri)).addContent(n);
>}
>
> Similarly, the line for "*" (arith1.times) is:
>
> | "*" exp=exprPrec3() { om = oma(oms("*"), om, exp); }
>
> The only special thing here is that oms() uses a dictionary
>for translating the abbreviated name of the symbol into the "cd" and
>"name" needed for building the "OMS" element, for convenience. It
>also works as 'om = oma(oms("arith1", "times"), om, exp)'.
>
> So I would advise you (Cédric) to write your own parser.
> It's going to give you much more flexibility than the existing
>software, and it's really quick to do, without having to care about
>licences or bloating your code with functionality you don't need. Unless
>you really want to connect to, say, Maple or Mathematica, in which case
>using for example the RIACA libraries (written in Java, as Mike noted),
>would make sense. But for quick building of OpenMath from linear syntax,
>it's being so far a good solution for us.
>
>[1] http://www.activemath.org
>[2] http://www.jdom.org
>
> Cheers,
>
>
--
om at openmath.org - general discussion on OpenMath
Post public announcements to om-announce at openmath.org
Automatic list maintenance software at majordomo at openmath.org
Mail om-owner at openmath.org for assistance with any problems
More information about the Om
mailing list