diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..5582bec938b09eabc3e630b7451b82419418267c --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +################################################################ +# Makefile +# +# LgEval +# Feb 8, 2022 - R. Zanibbi +################################################################# + +all: conda + +# Install python environment for LgEval +conda: + ./install + + +# 'make conda-remove' - remove LgEval conda environment +conda-remove: + conda env remove -n lgeval + + diff --git a/README.md b/README.md index 49bb423216dd7fcbdbe4b9aaf561cb42c91591f1..10a4936d33a95d2ed692721ea49671bfe69dca11 100644 --- a/README.md +++ b/README.md @@ -100,11 +100,31 @@ In addition to metrics, the library provides visualization of label graphs at th 2. perl (**with LibXML**) 3. python 3.x 4. Graphviz (for 'dot') -5. BeautifulSoup4 (`pip install beautifulsoup4`) (required for pretty printing output mathml) - -Make sure that *CROHMELibDir* and *LgEvalDir* are defined in - your shell enviroment, e.g. by including the following in your .bashrc initialization script for bash shell. The last line adds the - tools to your search path. +5. Conda (e.g., from Anaconda) and pip for Python environments + +**Conda LgEval Environment Install (preferred approach).** To install +the conda environment for lgeval, which will set up both Python packages and +necessary paths for LgEval command line tools, issue: +``` +make +``` + +After installation, the LgEval conda environment can be started by issuing: +``` +conda activate lgeval +``` +at which point all LgEval tools (e.g., `evaluate`) should be usable as commands at the command line. + +To stop using the lgeval conda environment, issue: +``` +conda deactivate +``` +Note: this will reset shell variables to their previous values. + +**Alternative: Bash shell modification (for LgEval and CROHMELib).** +To use the LgEval tools from the command anywhere on your system, make sure that *CROHMELibDir* and *LgEvalDir* are defined in +your shell enviroment, e.g. by including the following in your .bashrc initialization script for bash shell. The last line adds the +tools to your search path. export LgEvalDir=<path_to_LgEval> export CROHMELibDir=<path_to_CROHMELib> diff --git a/bin/lg2mml b/bin/lg2mml index 9cc56feab29312b46ac52e31eef0e5e68a0e12f3..e3d1fbe111e2f94faa677575f036f24349b1f845 100755 --- a/bin/lg2mml +++ b/bin/lg2mml @@ -22,6 +22,13 @@ then exit 0 fi +# RZ: Debug +#echo "" +#echo "[ lg2mml ]" +#echo " LgEvalDir $LgEvalDir" +#echo " PATH $PATH" +#echo " PYTHONPATH $PYTHONPATH" + BNAME=`basename $1 .lg` python $LgEvalDir/src/lg2txt.py $1 $LgEvalDir/translate/mathMLMap.csv $LgEvalDir/translate/infty_to_crohme.csv > $BNAME.mml diff --git a/bin/tests/.gitignore b/bin/tests/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..1e4bcac08585eebf6bbbbceebdd8d97945b59cd9 --- /dev/null +++ b/bin/tests/.gitignore @@ -0,0 +1 @@ +*.mml diff --git a/bin/tests/test-2-add-inside-relationship-mapping b/bin/tests/test-2-add-inside-relationship-mapping new file mode 100755 index 0000000000000000000000000000000000000000..9c916a48cf1d88b794b2fab8da347d4ba7b604b7 --- /dev/null +++ b/bin/tests/test-2-add-inside-relationship-mapping @@ -0,0 +1,41 @@ +#!/bin/bash +# This should be run from the top level directory (lgeval/) + +echo "Running test for issue 2 (inside relationship mapping)..." + +# NOTE: Assumes 'make' has been run, and lgeval conda env. built +# This provides necessary packages AND paths +source `conda info | grep 'base environment' | awk '{print $4}'`/etc/profile.d/conda.sh +conda activate lgeval + +# Show environment (for checking and debugging) +echo "Environment Variables:" +echo " LgEvalDir $LgEvalDir" +echo " PYTHONPATH $PYTHONPATH" +echo " PATH $PATH" +echo "" + +TEST_FILES=`ls tests/sqrt_lg/*.lg` +for file in $TEST_FILES +do + lg2mml $file + filename=`basename $file .lg` + echo Input:" "$file + echo ">> MathML: $filename.mml <<" + echo "" + cat $filename.mml + echo "" +done + +# Clean up MML files +# Delete ONLY the files that we created. +echo "Deleting .mml files..." +for file in $TEST_FILES +do + rm `basename $file .lg`.mml +done + +# Deactivate lgeval environment +conda deactivate + +echo "done." diff --git a/install b/install new file mode 100755 index 0000000000000000000000000000000000000000..2652ffe505c98b7149adc5455b0bff2534d04dc7 --- /dev/null +++ b/install @@ -0,0 +1,99 @@ +#!/bin/bash + +################################################################ +# Functions +################################################################ + +# Report message +mymsg () { + echo " >> $@" + echo "" +} + +# Pass number of arguments sent to outer script and success message to invoke. +testSuccess () { + if [ $? -ne 0 ] + then + echo "" + echo "** Installation error ** -- please review error messages above." + + # Pass any additional argument, program will not halt. + if [ $1 -eq 0 ] + then + exit $? + else + echo "** Continuing..." + echo "" + fi + else + # Success. + mymsg $2 + fi +} + + +################################################################ +# LgEval Conda Environment +################################################################ + +# Set up Conda environment +echo "[ Creating LgEval Python Environment ]" + +CENV=`conda info --envs` +if grep -w "lgeval" <<< "$CENV" +then + mymsg "Conda lgeval environment already created." +else + conda create -n lgeval python=3.6.9 + testSuccess $# "Environment (lgeval) created successfully." + CONDSH=`conda info | grep 'base environment' | awk '{print $4}'`/etc/profile.d/conda.sh + source $CONDSH + conda activate lgeval + + pip install -r requirements.txt + testSuccess $# "Additional packages installed successfully." + + # Set environment variables in scripts run by conda on start/end of activation + + # Define and record existing path definitions + LGEVALDIR=`pwd` + PARENTDIR=`cd ..;pwd` + + OLDPYTHONPATH=$PYTHONPATH + OLDPATH=$PATH + OLDLGEVALDIR=$LgEvalDir + + # Create shell files executed on lgeval conda env activate/deactivate + cd $CONDA_PREFIX + mkdir -p ./etc/conda/activate.d + mkdir -p ./etc/conda/deactivate.d + ACTIVE_ENV=./etc/conda/activate.d/env_vars.sh + DEACTIVE_ENV=./etc/conda/deactivate.d/end_vars.sh + + # Activation script + echo "#!/bin/bash" > $ACTIVE_ENV + echo export LgEvalDir="$LGEVALDIR" >> $ACTIVE_ENV + echo export PYTHONPATH="$PARENTDIR:$PYTHONPATH" >> $ACTIVE_ENV + echo export PATH="$LGEVALDIR/bin:$PATH" >> $ACTIVE_ENV + echo "" >> $ACTIVE_ENV + echo export OLDLGEVALDIR="$OLDLGEVALDIR" >> $ACTIVE_ENV + echo export OLDPYTHONPATH="$PYTHONPATH" >> $ACTIVE_ENV + echo export OLDPATH="$PATH" >> $ACTIVE_ENV + + # Deactivation script + echo "#!/bin/bash" > $DEACTIVE_ENV + echo export LgEvalDir=$OLDLGEVALDIR >> $DEACTIVE_ENV + echo export PYTHONPATH=$OLDPYTHONPATH >> $DEACTIVE_ENV + echo export PATH=$OLDPATH >> $DEACTIVE_ENV + echo "" >> $DEACTIVE_ENV + echo unset OLDLGEVALDIR >> $DEACTIVE_ENV + echo unset OLDPYTHONPATH >> $DEACTIVE_ENV + echo unset OLDPATH >> $DEACTIVE_ENV + + mymsg "Created environment variables for lgeval conda shell." + + conda deactivate +fi + + + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..85d57436a9652b53aeab586ba090aaaa64247269 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +beautifulsoup4==4.9.2 diff --git a/tests/sqrt_lg/ISICal19_1201_em_754.lg b/tests/sqrt_lg/ISICal19_1201_em_754.lg new file mode 100755 index 0000000000000000000000000000000000000000..c9b95319b8302ec35ff635fb5d236a1f5847ed4c --- /dev/null +++ b/tests/sqrt_lg/ISICal19_1201_em_754.lg @@ -0,0 +1,9 @@ +# IUD, CROHME19_754 +# Objects(3): +O, 2_1, 2, 1.0, 2 +O, _1, \sqrt, 1.0, 0 +O, x_1, x, 1.0, 1 + +# Relations from SRT: +R, _1, x_1, Inside, 1.0 +R, x_1, 2_1, Sup, 1.0 diff --git a/tests/sqrt_lg/UN19_1002_em_21.lg b/tests/sqrt_lg/UN19_1002_em_21.lg new file mode 100755 index 0000000000000000000000000000000000000000..8726f4d898c39fef64b8315ed0b7919b11c1d8a6 --- /dev/null +++ b/tests/sqrt_lg/UN19_1002_em_21.lg @@ -0,0 +1,15 @@ +# IUD, CROHME19_21 +# Objects(6): +O, _1, -, 1.0, 4 +O, c_1, c, 1.0, 6 +O, _2, \sqrt, 1.0, 5 +O, M_1, M, 1.0, 0 +O, rarr_1, \rightarrow, 1.0, 1, 2 +O, M_2, M, 1.0, 3 + +# Relations from SRT: +R, M_1, rarr_1, Right, 1.0 +R, _1, M_2, Above, 1.0 +R, _1, _2, Below, 1.0 +R, _2, c_1, Inside, 1.0 +R, rarr_1, _1, Right, 1.0 diff --git a/tests/sqrt_lg/UN19wb_1121_em_1189.lg b/tests/sqrt_lg/UN19wb_1121_em_1189.lg new file mode 100755 index 0000000000000000000000000000000000000000..6180c4ff2024b14750abbb6cb5905809d6f0190b --- /dev/null +++ b/tests/sqrt_lg/UN19wb_1121_em_1189.lg @@ -0,0 +1,55 @@ +# IUD, CROHME19_1189 +# Objects(25): +O, -_1, -, 1.0, 0 +O, 4_3, 4, 1.0, 18, 19 +O, 4_2, 4, 1.0, 10, 11 +O, (_1, (, 1.0, 3 +O, gamma_1, \gamma, 1.0, 4 +O, +_1, +, 1.0, 5, 6 +O, b_1, b, 1.0, 15 +O, log_1, \log, 1.0, 7, 8, 9 +O, 4_1, 4, 1.0, 1, 2 +O, _1, -, 1.0, 31 +O, _2, \sqrt, 1.0, 26, 25 +O, 1_1, 1, 1.0, 27 +O, 1_2, 1, 1.0, 34 +O, 3_1, 3, 1.0, 37 +O, -_2, -, 1.0, 28 +O, +_3, +, 1.0, 16, 17 +O, )_1, ), 1.0, 12 +O, _3, \sqrt, 1.0, 32, 33 +O, +_2, +, 1.0, 13, 14 +O, B_1, B, 1.0, 20 +O, x_2, x, 1.0, 38, 39 +O, pi_1, \pi, 1.0, 21, 23, 22 +O, 2_1, 2, 1.0, 24 +O, +_4, +, 1.0, 35, 36 +O, x_1, x, 1.0, 29, 30 + +# Relations from SRT: +R, (_1, gamma_1, Right, 1.0 +R, )_1, +_2, Right, 1.0 +R, +_1, log_1, Right, 1.0 +R, +_2, b_1, Right, 1.0 +R, +_3, _1, Right, 1.0 +R, +_4, 3_1, Right, 1.0 +R, -_1, 4_1, Right, 1.0 +R, -_2, x_1, Right, 1.0 +R, 1_1, -_2, Right, 1.0 +R, 1_2, +_4, Right, 1.0 +R, 3_1, x_2, Right, 1.0 +R, 4_1, (_1, Right, 1.0 +R, 4_2, )_1, Right, 1.0 +R, 4_3, B_1, Right, 1.0 +R, B_1, pi_1, Right, 1.0 +R, _1, 4_3, Above, 1.0 +R, _1, _3, Below, 1.0 +R, _2, -_2, Inside, 1.0 +R, _2, 1_1, Inside, 1.0 +R, _3, +_4, Inside, 1.0 +R, _3, 1_2, Inside, 1.0 +R, b_1, +_3, Right, 1.0 +R, gamma_1, +_1, Right, 1.0 +R, log_1, 4_2, Right, 1.0 +R, pi_1, 2_1, Sup, 1.0 +R, pi_1, _2, Right, 1.0 diff --git a/translate/mathMLMap.csv b/translate/mathMLMap.csv index 7e63e3f0ee0a10d986745be126d9d4303ae44c4e..8cfd21733b9b10c5bc51ccd3b7edabc7b857b053 100644 --- a/translate/mathMLMap.csv +++ b/translate/mathMLMap.csv @@ -366,6 +366,7 @@ ANY,SUBSC,SUPER,->,<msubsup>,PARENT,SUBSC,SUPER,</msubsup> Right,->,<mrow>,PARENT,CHILD,</mrow> R,->,<mrow>,PARENT,CHILD,</mrow> r,->,<mrow>,PARENT,CHILD,</mrow> +Inside,->,<mrow>,PARENT,CHILD,</mrow> HOR,->,<mrow>,PARENT,CHILD,</mrow> ^,->,<msup>,PARENT,CHILD,</msup> _,->,<msub>,PARENT,CHILD,</msub>