22 from os.path
import expanduser
23 from app_error_exception
import AppError
24 from rapp_platform_ros_communications.srv
import (
25 ontologyClassBridgeSrv,
26 ontologyClassBridgeSrvResponse
40 res=ontologyClassBridgeSrvResponse()
41 mapFile = home = expanduser(
"~")+rospy.get_param(
"ontology_class_bridge_file")
43 if (req.caffeClass
in caffeToOntologyClassesDict):
44 res.ontologyClass=caffeToOntologyClassesDict[req.caffeClass]
45 res.existsInOntology=
True
47 res.existsInOntology=
False
48 res.ontologyClass=
"SpatialThing-Localized-Unspecified"
53 res.trace.append(
'"KeyError, probably caffe class does not exist or no ontology equivalent exists for "%s"' % str(e))
54 res.error=
'"KeyError, probably caffe class does not exist or no ontology equivalent exists for "%s"' % str(e)
62 with open(mapFilePath)
as f:
63 lines = f.read().splitlines()
64 caffeToOntologyClassesDict=dict()
66 currentList=s.split(
"\t")
67 if(len(currentList)>=3):
68 caffeToOntologyClassesDict[currentList[1]]=currentList[2]
69 return caffeToOntologyClassesDict
Contains the necessary functions for translating caffe classes to ontology classes.
def loadMappingIntoDictionary
Loads the caffeToOntologyClasses file into a dictionary.
def getOntologyClassEquivalent
Implements the getOntologyClassEquivalent service main function.