Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider db7dc1b8 rédigé par Harold MOUCHERE's avatar Harold MOUCHERE
Parcourir les fichiers

Add normalization mn tags in mml

parent 92411053
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -9,7 +9,7 @@ no warnings;
if($#ARGV < 0 or $#ARGV > 2){
print "CROHMELib CROHME .inkml to Label Graph (.lg) Converter
Copyright (c) H. Mouchère and R. Zanibbi, 2012-2014
Copyright (c) H. Mouchère and R. Zanibbi, 2012-2023
Usage: mml2lg.pl [-s] fileIn.inkml [fileOut.lg]
......@@ -18,7 +18,7 @@ standard output (STDOUT).
The option -s produces the short format with 'O' and 'OE' lines
instead of 'N' and 'E' lines.
Version : 1.4
Version : 1.5
Authors: Harold Mouchère (LUNAM/University of Nantes/IRCCyN/IVC)
R. Zanibbi (DPRL Lab, RIT, USA)
";
......@@ -46,7 +46,7 @@ my %tagToSRT = (
"msup" => [[0,1,'Sup']],
"msub" => [[0,1,'Sub']],
"mfrac" => [[-1,0,'Above'],[-1,1,'Below']],
"msqrt" => [[-1,0,'Inside'],[-1,1,'Inside'],[0,1,'Right']],
"msqrt" => [[-1,0,'Inside'],[0,1,'Right']],
"mroot" => [[-1,0,'Inside'],[-1,1,'Above']],
"munder" => [[0,1,'Below']],
"munderover" => [[0,1,'Below'], [0,2,'Above']],
......
......@@ -53,6 +53,29 @@ def add_ID(mml):
subtree['xml:id']='_'+str(count)
return mml
# normalize multi-character mn tags inserting mrow tags
def norm_mn(mml):
soup = BeautifulSoup(open(mmlPath),'lxml')
for subtree in mml.findAll('mn'):
if len(subtree.text) > 1 :
#print ("mn tag with more than one character is found:", subtree)
d1 = subtree.text[0]
d2 = subtree.text[1:]
# rename as mrow tag
subtree.string = ""
subtree.name = 'mrow'
# add new tags mn for first digit and one for next digits
mnd1 = soup.new_tag('mn')
mnd1.string = d1
subtree.insert(0,mnd1)
next = soup.new_tag('mn')
next.string = d2
subtree.insert(1,next)
# recursive call to normalize the new mn tag
norm_mn(subtree)
#print(" => new tree :", subtree)
return mml
#return mathml unicodes into latex labels
def normalizeSymbol(label):
if label in ['rightarrow', 'sum', 'int', 'pi', 'leq', 'sin','cos','tan', 'lim',
......@@ -181,6 +204,7 @@ if __name__=='__main__':
if soup('math'):
body=soup('math')[0]
clean_mml=remove_unknown_tags(body)
clean_mml = norm_mn(clean_mml)
id_mml=add_ID(clean_mml)
write_mml(id_mml,name,outDir)
......
$\sqrt{24+1234}$
\ No newline at end of file
$\frac{15}{xy} \sin \theta ^{23}$
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter