Skip to content

Commit

Permalink
[ontopy] use compat layer for sparql and convertion
Browse files Browse the repository at this point in the history
  • Loading branch information
sarthou committed Jan 12, 2024
1 parent f6f468b commit 0eb83ab
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 43 deletions.
22 changes: 4 additions & 18 deletions ontopy/ontologenius/ConversionClient.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import rospy
from compat.ros import Ontoros, OntoService

from ontologenius.srv import OntologeniusConversion
from ontologenius.srv import OntologeniusConversionRequest
Expand All @@ -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
Expand Down Expand Up @@ -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
request = OntologeniusConversionRequest(source, values_str, values_int)
return self._client.call(request, self._verbose)
21 changes: 8 additions & 13 deletions ontopy/ontologenius/clients/SparqlClient.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
20 changes: 8 additions & 12 deletions ontopy/ontologenius/clientsIndex/SparqlIndexClient.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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

0 comments on commit 0eb83ab

Please sign in to comment.