diff --git a/ontopy/ontologenius/ConversionClient.py b/ontopy/ontologenius/ConversionClient.py index 654c5d63..eb3ffbb6 100644 --- a/ontopy/ontologenius/ConversionClient.py +++ b/ontopy/ontologenius/ConversionClient.py @@ -1,4 +1,4 @@ -import rospy +from compat.ros import Ontoros, OntoService from ontologenius.srv import OntologeniusConversion from ontologenius.srv import OntologeniusConversionRequest @@ -12,7 +12,7 @@ def __init__(self, name): if name != '': self._name = self._name + name self._verbose = False - self._client = rospy.ServiceProxy(self._name, OntologeniusConversion, True) + self._client = Ontoros.createService(self._name, OntologeniusConversion) def setVerbose(self, verbose): """If verbose(bool) is set to True, the clients will post messages about @@ -112,19 +112,5 @@ def _id2Index(self, id, source): return None def _call(self, source, values_str, values_int): - try: - response = self._client(source, values_str, values_int) - return response - except (rospy.ServiceException, rospy.exceptions.TransportTerminated) as e: - if self._verbose == True: - print("Failure to call " + self._name) - self._client = rospy.ServiceProxy(self._name, OntologeniusConversion, True) - try: - response = self._client(source, values_str, values_int) - if self._verbose == True: - print("Restored " + self._name) - return response - except (rospy.ServiceException, rospy.exceptions.TransportTerminated) as e: - if self._verbose == True: - print("Failure of service restoration") - return None \ No newline at end of file + request = OntologeniusConversionRequest(source, values_str, values_int) + return self._client.call(request, self._verbose) \ No newline at end of file diff --git a/ontopy/ontologenius/clients/SparqlClient.py b/ontopy/ontologenius/clients/SparqlClient.py index b94b6ec9..deefece8 100644 --- a/ontopy/ontologenius/clients/SparqlClient.py +++ b/ontopy/ontologenius/clients/SparqlClient.py @@ -1,6 +1,6 @@ -import rospy +from compat.ros import Ontoros, OntoService -from ontologenius.srv import OntologeniusSparqlService +from ontologenius.srv import OntologeniusSparqlService, OntologeniusSparqlServiceRequest class SparqlClient: """The SparqlClient class provides a ROS service to explore ontologenius with SPARQL-like queries. @@ -14,17 +14,12 @@ def __init__(self, name): self._name = 'sparql' if name != '': self._name = self._name + '/' + name - self._client = rospy.ServiceProxy('ontologenius/' + self._name, OntologeniusSparqlService, True) - + self._client = Ontoros.createService('ontologenius/' + self._name, OntologeniusSparqlService) def call(self, query): - try: - response = self._client(query) + request = OntologeniusSparqlServiceRequest(query) + response = self._client.call(request) + if(response is None): + return None + else: return (response.names, response.results) - except rospy.ServiceException as e: - self._client = rospy.ServiceProxy('ontologenius/' + self._name, OntologeniusSparqlService, True) - try: - response = self._client(query) - return (response.names, response.results) - except rospy.ServiceException as e: - return None diff --git a/ontopy/ontologenius/clientsIndex/SparqlIndexClient.py b/ontopy/ontologenius/clientsIndex/SparqlIndexClient.py index 53815390..4ee66124 100644 --- a/ontopy/ontologenius/clientsIndex/SparqlIndexClient.py +++ b/ontopy/ontologenius/clientsIndex/SparqlIndexClient.py @@ -1,6 +1,6 @@ -import rospy +from compat.ros import Ontoros, OntoService -from ontologenius.srv import OntologeniusSparqlIndexService +from ontologenius.srv import OntologeniusSparqlIndexService, OntologeniusSparqlIndexServiceRequest class SparqlIndexClient: """The SparqlIndexClient class provides a ROS service to explore ontologenius with SPARQL-like queries based on indexes. @@ -14,17 +14,13 @@ def __init__(self, name): self._name = 'sparql_index' if name != '': self._name = self._name + '/' + name - self._client = rospy.ServiceProxy('ontologenius/' + self._name, OntologeniusSparqlIndexService, True) + self._client = Ontoros.createService('ontologenius/' + self._name, OntologeniusSparqlIndexService, True) def call(self, query): - try: - response = self._client(query) + request = OntologeniusSparqlIndexServiceRequest(query) + response = self._client.call(request) + if(response is None): + return None + else: return (response.names, response.results) - except rospy.ServiceException as e: - self._client = rospy.ServiceProxy('ontologenius/' + self._name, OntologeniusSparqlIndexService, True) - try: - response = self._client(query) - return (response.names, response.results) - except rospy.ServiceException as e: - return None