On 09/21/10 02:50 PM, Nathann Cohen wrote:
Hello !!!

Nathann and I started a few months ago to make such a list for graph theory:

I don't remember if we discussed it already Minh, but what about
putting all these informations INSIDE of the docstrings instead ? We
could then generate the list of corespondances... It would be way
easier to maintain, and users could find the Sage equivalents to the
commands they know though search_doc (?)...

Nathann


If it was possible to put the equivalent commands in the docstrings, and then use some code to extract them in a logical way, it would be helpful.

If it was done done in a very consistent way, then generating a list from grep and awk would be trivial:

Let's say one always had equivalent entries of the format:

sage_command Nearest Mathematica equivalent: MathematicaCommand[]. Anything else in the doc files was ignored, since we only bother searching for the text "Nearest Mathematica equivalent:"


drkir...@hawk:~$ cat test.txt
factor() Nearest Mathematica equivalent: Factor[] FactorInteger[]
tan() Nearest Mathematica equivalent: Tan[]
Some other stuff, unrelated to Mathematica
cos() Nearest Mathematica equivalent: Cos[]
Some other stuff, about birds and bees
sin() Nearest Mathematica equivalent: Sin[]

drkir...@hawk:~$ grep awk "Nearest Mathematica equivalent:" | awk '{print $5, $1}' | sort | grep -v "^ "

Cos[] cos()
Factor[] factor()
Sin[] sin()
Tan[] tan()

We would then search for lines where's there is a 6th entry too, as there might be two different commands needed in Mathematica, as there is for factor().


drkir...@hawk:~$ grep "Nearest Mathematica equivalent" test.txt | awk '{print $6, $1}' | sort | grep -v "^ "
FactorInteger[] factor()

Combining the two, we now have a complete list of Mathematica vs Sage commands, sorted by the Mathematica name. (We don't need to sort each time - only at the end)

drkir...@hawk:~$ grep "Nearest Mathematica equivalent" test.txt | awk '{print $5, $1}' | grep -v "^ " > tmpfile drkir...@hawk:~$ grep "Nearest Mathematica equivalent" test.txt | awk '{print $6, $1}' | grep -v "^ " >> tmpfile

Now sort them.

drkir...@hawk:~$ sort tmpfile
Cos[] cos()
Factor[] factor()
FactorInteger[] factor()
Sin[] sin()
Tan[] tan()

I expect:

1) Someone will tell me there's a way to do it in Python.

2) There's better ways of doing it with shell scripts (one would want to recursive search files for example), but that's trivial (-R option on GNU grep, or with 'find' command).

3) There might be a better way of doing it in the dostrings.

But if all else fails, then grabbing the data via a shell script and sorting it in order would be trivial as long as a consistent format was used. i.e. was always use ""Nearest Mathematica equivalent" or something like that, and people do not mis-spell it, swap the case of characters, or anything else that gets away from a rigid agreed structure.

PS, it would also be trial to create an HTML web page from such a shell script!

Dave

--
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to