Nantes Université
Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
L
Lgeval
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneur
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Service d'assistance
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
CROHME
Lgeval
Validations
610ad00f
Valider
610ad00f
rédigé
il y a 3 ans
par
ayushkumarshah
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Add translation to support lg2mml for infty
parent
4a9eb3aa
Aucune branche associée trouvée
Branches contenant la validation
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
3
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
3 fichiers modifiés
bin/lg2mml
+1
-1
1 ajout, 1 suppression
bin/lg2mml
src/lg2txt.py
+68
-30
68 ajouts, 30 suppressions
src/lg2txt.py
translate/infty_to_crohme.csv
+1
-1
1 ajout, 1 suppression
translate/infty_to_crohme.csv
avec
70 ajouts
et
32 suppressions
bin/lg2mml
+
1
−
1
Voir le fichier @
610ad00f
...
...
@@ -24,4 +24,4 @@ fi
BNAME
=
`
basename
$1
.lg
`
python
$LgEvalDir
/src/lg2txt.py
$1
$LgEvalDir
/translate/mathMLMap.csv
>
$BNAME
.mml
python
$LgEvalDir
/src/lg2txt.py
$1
$LgEvalDir
/translate/mathMLMap.csv
$LgEvalDir
/translate/infty_to_crohme.csv
>
$BNAME
.mml
This diff is collapsed.
Cliquez pour l'agrandir.
src/lg2txt.py
+
68
−
30
Voir le fichier @
610ad00f
...
...
@@ -11,11 +11,41 @@
# Copyright (c) 2012-2014 Richard Zanibbi and Harold Mouchere
################################################################
import
os
import
re
import
sys
import
csv
from
bs4
import
BeautifulSoup
from
lg
import
*
def
readtranslateFile
(
mapFile
):
"""
Read in symbol and structure mappings from a file.
"""
try
:
fileReader
=
csv
.
reader
(
open
(
mapFile
))
except
:
sys
.
stderr
.
write
(
'
!! IO Error (cannot open):
'
+
mapFile
+
'
\n
'
)
return
symbolsMap
=
{}
relationsMap
=
{}
readingSymbols
=
True
for
row
in
fileReader
:
# Skip blank lines and comments.
if
len
(
row
)
==
0
:
continue
elif
row
[
0
].
strip
()[
0
]
==
'
#
'
:
continue
elif
row
[
0
].
strip
()
==
'
SYMBOLS
'
:
readingSymbols
=
True
elif
row
[
0
].
strip
()
==
'
RELATIONSHIPS
'
:
readingSymbols
=
False
else
:
if
readingSymbols
:
symbolsMap
[
row
[
0
]]
=
row
[
1
]
else
:
relationsMap
[
row
[
0
]]
=
row
[
1
]
return
symbolsMap
,
relationsMap
def
readMapFile
(
fileName
):
"""
Read in symbol and structure mappings from a file.
"""
try
:
...
...
@@ -286,33 +316,7 @@ def cleanRows( mmlFile ):
return
rowSoup
.
prettify
()
# def postprocess(mml_out):
# # Add linebreaks for tags expect for mi, mo, mn
# mml_out = mml_out.replace("><", ">\n<")
# mml_out = mml_out.replace("</", "\n</")
# mml_out = mml_out.replace("\n</mi", "</mi")
# mml_out = mml_out.replace("\n</mo", "</mo")
# mml_out = mml_out.replace("\n</mn", "</mn")
# # tags with no indentation
# constant_tags = ["mi", "mo", "mn"]
# # Counts number of tab sapces
# tab = 0
# out = []
# for line in mml_out.split("\n"):
# if not line:
# continue
# # if re.match(r"<\w", line):
# if line.startswith("<m"):
# out.append(tab * "\t" + line)
# if not line[1:3] in constant_tags:
# tab += 1
# elif line.startswith("</"):
# tab -= 1
# out.append(tab * "\t" + line)
# return "\n".join(out)
def
main
(
lg_file
,
mapFile
):
def
lg2mml
(
lg_file
,
mapFile
):
lg
=
Lg
(
lg_file
)
...
...
@@ -360,18 +364,52 @@ def main(lg_file, mapFile):
mml_out
=
cleanRows
(
"
\n
"
.
join
(
mml_out_raw
))
return
mml_out
def
preprocess
(
filename
,
translateFile
,
translate
=
True
):
lg
=
Lg
(
filename
)
print
(
lg
)
lg_NE_string
=
lg
.
csv
()
if
translate
:
symbolsMap
,
relationsMap
=
readtranslateFile
(
translateFile
)
edge_pattern
=
re
.
compile
(
r
'
^E,
'
)
node_pattern
=
re
.
compile
(
r
'
(^N,)|#
'
)
symbol_temp
=
relabel
(
lg_NE_string
,
symbolsMap
,
node_pattern
)
edge_temp
=
relabel
(
lg_NE_string
,
dict
(
**
symbolsMap
,
**
relationsMap
),
edge_pattern
)
lg_NE_string
=
symbol_temp
+
"
\n
"
+
edge_temp
temp_file
=
"
temp.lg
"
with
open
(
temp_file
,
'
w
'
)
as
f
:
f
.
writelines
(
lg_NE_string
)
return
temp_file
def
relabel
(
lg_NE_string
,
Map
,
pattern
):
temp
=
'
\n
'
.
join
([
line
for
line
in
lg_NE_string
.
split
(
'
\n
'
)
if
re
.
match
(
pattern
,
line
)])
for
source_label
,
mapped_label
in
Map
.
items
():
temp
=
temp
.
replace
(
"
,
"
+
source_label
+
"
,
"
,
"
,
"
+
mapped_label
+
"
,
"
)
return
temp
def
main
(
lg_file
,
mapFile
,
translateFile
):
temp_lg_file
=
preprocess
(
lg_file
,
translateFile
)
mml_out
=
lg2mml
(
temp_lg_file
,
mapFile
)
os
.
remove
(
temp_lg_file
)
return
mml_out
if
__name__
==
'
__main__
'
:
if
len
(
sys
.
argv
)
<
2
:
print
(
"
Usage: [[python]] lg2txt.py <infile.lg> [mapfile.csv]
"
)
print
(
"
Usage: [[python]] lg2txt.py <infile.lg> [mapfile.csv]
[translatefile.csv]
"
)
print
(
""
)
print
(
"
Produces a text file for label graph file
"
)
print
(
"
<infile.lg>. A symbol and structure map file (mapfile.csv)
"
)
print
(
"
may be provided to override default (latex) mappings.
"
)
sys
.
exit
()
lg_file
=
sys
.
argv
[
1
]
if
len
(
sys
.
argv
)
>
2
:
if
len
(
sys
.
argv
)
>
3
:
mapFile
=
sys
.
argv
[
2
]
translateFile
=
sys
.
argv
[
3
]
elif
len
(
sys
.
argv
)
>
2
:
mapFile
=
sys
.
argv
[
2
]
translateFile
=
None
else
:
mapFile
=
None
mml_out
=
main
(
lg_file
,
mapFile
)
mml_out
=
main
(
lg_file
,
mapFile
,
translateFile
)
print
(
mml_out
)
This diff is collapsed.
Cliquez pour l'agrandir.
translate/infty_to_crohme.csv
+
1
−
1
Voir le fichier @
610ad00f
...
...
@@ -177,4 +177,4 @@ UNDER,Below
LSUB,Sub
UPPER,Above
LSUP,Sup
PUNC,
Right
PUNC,
Sub
This diff is collapsed.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter