Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider e8f665a7 rédigé par R's avatar R
Parcourir les fichiers

Made unknown symbol error messages optional for get_MML.

parent 4ed941d2
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -112,6 +112,7 @@ def translateStructure(
symbolMap,
segId,
nodeString,
warnings = True
):
"""Generate a string for a given structure."""
strString = ""
......@@ -150,7 +151,8 @@ def translateStructure(
(childId, relation) = nodeRelationPairs[j]
if relation == nextRelation:
strString += translate(
lg, childId, segPrimMap, edgeMap, symbolMap, structureMap
lg, childId, segPrimMap, edgeMap, symbolMap,
structureMap, warnings
)
match = True
break
......@@ -177,7 +179,8 @@ def translateStructure(
(childId, relation) = nodeRelationPairs[j]
if relation == nextRelation:
strString += translate(
lg, childId, segPrimMap, edgeMap, symbolMap, structureMap
lg, childId, segPrimMap, edgeMap, symbolMap,
structureMap, warnings
)
match = True
break
......@@ -198,7 +201,7 @@ def translateStructure(
def translateRelation(
lg, relation, nextChildId, structureMap, segPrimMap, edgeMap, symbolMap, nodeString
lg, relation, nextChildId, structureMap, segPrimMap, edgeMap, symbolMap, nodeString, warnings=True
):
"""Translate an individual spatial relation."""
relString = ""
......@@ -227,7 +230,8 @@ def translateRelation(
relString += nodeString
elif nextEntry == "CHILD":
relString += translate(
lg, nextChildId, segPrimMap, edgeMap, symbolMap, structureMap
lg, nextChildId, segPrimMap, edgeMap, symbolMap, structureMap,
warnings
)
else:
relString += replacementTuple[i]
......@@ -235,7 +239,8 @@ def translateRelation(
return relString
def translate(lg, segId, segPrimMap, edgeMap, symbolMap, structureMap):
def translate(lg, segId, segPrimMap, edgeMap, symbolMap, structureMap,
warnings = True):
"""Recursively create output for an expression at the object level."""
byValue = lambda pair: pair[1]
byRel = lambda pair: pair[0]
......@@ -260,7 +265,8 @@ def translate(lg, segId, segPrimMap, edgeMap, symbolMap, structureMap):
.replace("_I_", '"' + primListString + '"')
.replace("_L_", label)
)
sys.stderr.write(" !! lg2txt Warning: Unknown object label " + label + "\n")
if warnings:
sys.stderr.write(" !! lg2txt Warning: Unknown object label " + label + "\n")
if segId in edgeMap:
# This node has children - lookup replacement based on sorted labels
......@@ -311,6 +317,7 @@ def translate(lg, segId, segPrimMap, edgeMap, symbolMap, structureMap):
symbolMap,
segId,
nodeString,
warnings
)
if not strString == "":
nodeString = strString
......@@ -326,6 +333,7 @@ def translate(lg, segId, segPrimMap, edgeMap, symbolMap, structureMap):
symbolMap,
segId,
nodeString,
warnings
)
if not strString == "":
nodeString = strString
......@@ -339,6 +347,7 @@ def translate(lg, segId, segPrimMap, edgeMap, symbolMap, structureMap):
edgeMap,
symbolMap,
nodeString,
warnings
)
# nodeString += translateRelation(lg, (relation, nextChildId),\
......@@ -355,6 +364,7 @@ def translate(lg, segId, segPrimMap, edgeMap, symbolMap, structureMap):
edgeMap,
symbolMap,
nodeString,
warnings
)
# Lastly, generate string for adjacent symbols on the baseline.
......@@ -369,6 +379,7 @@ def translate(lg, segId, segPrimMap, edgeMap, symbolMap, structureMap):
edgeMap,
symbolMap,
nodeString,
warnings
)
return nodeString
......@@ -389,7 +400,7 @@ def cleanRows(mmlFile):
return rowSoup.prettify()
def lg2mml(lg_file, mapFile):
def lg2mml(lg_file, mapFile, warnings=True):
# RZ: lg_file may actually be a StringIO object
lg = Lg(lg_file)
......@@ -444,7 +455,9 @@ def lg2mml(lg_file, mapFile):
# symbolMap, structureMap))
mml_out_raw.append(
translate(
lg, root, segmentPrimitiveMap, treeEdgeMap, symbolMap, structureMap
lg, root, segmentPrimitiveMap, treeEdgeMap, symbolMap,
structureMap,
warnings
)
)
# mml_out = postprocess("\n".join(mml_out_raw))
......@@ -483,7 +496,7 @@ def relabel(lg_NE_string, Map, pattern):
temp = temp.replace("," + source_label + ",", "," + mapped_label + ",")
return temp
def get_MML( lgString, mapFile, translateFile):
def get_MML( lgString, mapFile, translateFile, warnings=True):
# RZ: add ability to use StringIO and avoid writing temp file.
# Create StringIO object
......@@ -491,7 +504,7 @@ def get_MML( lgString, mapFile, translateFile):
intermString = preprocess( stringIO, translateFile )
intermStringIO = StringIO( intermString )
mml_out = lg2mml( intermStringIO, mapFile )
mml_out = lg2mml( intermStringIO, mapFile, warnings )
return mml_out
def main(lg_file, mapFile, translateFile):
......
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