KnowledgeCaptureAndDiscovery / OBA

Ontology based APIs
Apache License 2.0
37 stars 11 forks source link

Broken examples #165

Open DougalW opened 2 years ago

DougalW commented 2 years ago

Hi

The DBPedia Music example is now broken - it returns this error if I search for the Beatles

2022-07-06 07:14:49,310 - werkzeug - INFO - 172.17.0.1 - - [06/Jul/2022 07:14:49] "GET /v1.3.0/bands?label=Beatles&page=1&per_page=100 HTTP/1.1" 200 - 2022-07-06 07:15:11,329 - oba - INFO - #+ summary: Return the query to a resource by the resource_iri PREFIX rdfs: http://www.w3.org/2000/01/rdf-schema# CONSTRUCT { http://dbpedia.org/resource/beatles ?predicate ?prop . ?prop a ?type . ?prop rdfs:label ?label } WHERE { http://dbpedia.org/resource/beatles ?predicate ?prop OPTIONAL { ?prop a ?type OPTIONAL { ?prop rdfs:label ?label } } } 2022-07-06 07:16:20,671 - grlc - ERROR - json serialize failed Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/obasparql/query_manager.py", line 455, in frame_results response_dict = json.loads(response) File "/usr/local/lib/python3.10/json/init.py", line 339, in loads raise TypeError(f'the JSON object must be str, bytes or bytearray, ' TypeError: the JSON object must be str, bytes or bytearray, not tuple 2022-07-06 07:16:20,672 - werkzeug - INFO - 172.17.0.1 - - [06/Jul/2022 07:16:20] "GET /v1.3.0/bands/beatles HTTP/1.1" 200 -

Also Model Catalog fails to generate an OpenAPI server docker image.

cheers

Dougal

dgarijo commented 2 years ago

I will have a look when I have the chance. At least the generation of the API should work. The server generation is a little more tricky, with a lot of changing dependencies.

DougalW commented 2 years ago

Thanks. The API generation works fine.

DougalW commented 2 years ago

Another quick question egarding the design of OBA and how it constructs paths and queries on those paths.... (I sent you an email a few minutes ago but not sure if you're at that address any more)

When OBA generates the openapi.yaml file, are these query parameters (in bold below) reserved words?

paths: /accountcategorys: get: description: Gets a list of all instances of AccountCategory (more information in https://businessontology.com/ontology/AccountCategory) parameters:

It sort of looks like ‘label’ corresponds to rdfs:label class annotations, but I want to be able to query on skos:label so how would I set that?

Also, how would I construct an API that can query based on the name of an instance? e.g. I have an instance _creditcard123213213 a creditcard so I want to be able to search on the actual name of the instance.

dgarijo commented 2 years ago

Hello, yes, from what I remember these are reserved words.

To query on skos labels, you would have to modify the get_one.rq and get_one_user.rq files to expand rdfs:label with skos:label For the credit card case, I think the easiest way forward is to add a label with the name, so you can reuse the existing API calls.

DougalW commented 2 years ago

Thanks for your reply.

Another quick question - reading through Rhys commit: https://github.com/KnowledgeCaptureAndDiscovery/OBA/pull/161/commits/6686b8c100fc404820c54e854c5ca173572e2273

The query manager has been updated to use ' named_graph_base=ENDPOINT_GRAPH_BASE' instead of the old 'graph_base=ENDPOINT_GRAPH_BASE'

Does this mean that for graph databases using a named graph, that the config.yaml file should now use the Endpoint option like this?

endpoint: url: http://localhost:7200/sparql prefix: https://www.mygraph.org/ named_graph_base: http://www.mygraph.org/data/

dgarijo commented 2 years ago

It looks like it's how you are suggesting. However, I haven't run OBA for a while. Maybe @mosoriob knows better these options (I know best the mapping part)

DougalW commented 2 years ago

Thanks Daniel. BTW, is there an option to turn on detailed logging in OBA to see submitted URL's?

I'm trying to access GraphDB at this endpoint address:

endpoint: url: http://localhost:7200/repositories/test prefix: https://businessontology.com/ontology graph_base: https://businessontology.com/ontology

But when I submit something in my OBA generated API it returns this error:

2022-07-07 01:59:53,387 - oba - INFO - #+ summary: Given a rdf type, returns all the resources related to the type CONSTRUCT { ?item ?predicate ?prop . ?prop a ?type } WHERE { GRAPH https://businessontology.com/ontology/None { { SELECT DISTINCT ?item where { ?item a https://businessontology.com/ontology/AccountCategory . } LIMIT 100 OFFSET 0 } ?item ?predicate ?prop OPTIONAL { ?prop a ?type } } } 2022-07-07 01:59:53,387 - oba - ERROR - <urlopen error [Errno 99] Address not available> Traceback (most recent call last): File "/usr/local/lib/python3.10/urllib/request.py", line 1348, in do_open h.request(req.get_method(), req.selector, req.data, headers, File "/usr/local/lib/python3.10/http/client.py", line 1282, in request self._send_request(method, url, body, headers, encode_chunked) File "/usr/local/lib/python3.10/http/client.py", line 1328, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/usr/local/lib/python3.10/http/client.py", line 1277, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/usr/local/lib/python3.10/http/client.py", line 1037, in _send_output self.send(msg) File "/usr/local/lib/python3.10/http/client.py", line 975, in send self.connect() File "/usr/local/lib/python3.10/http/client.py", line 941, in connect self.sock = self._create_connection( File "/usr/local/lib/python3.10/socket.py", line 845, in create_connection raise err File "/usr/local/lib/python3.10/socket.py", line 833, in create_connection sock.connect(sa) OSError: [Errno 99] Address not available

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/obasparql/query_manager.py", line 286, in request_all return self.obtain_query(query_directory=owl_class_name, File "/usr/local/lib/python3.10/site-packages/obasparql/query_manager.py", line 422, in obtain_query raise e File "/usr/local/lib/python3.10/site-packages/obasparql/query_manager.py", line 419, in obtain_query result = self.dispatch_sparql_query( File "/usr/local/lib/python3.10/site-packages/obasparql/query_manager.py", line 784, in dispatch_sparql_query return self.sparql.query(rewritten_query) File "/usr/local/lib/python3.10/site-packages/obasparql/sparqlconnector.py", line 115, in query res = urlopen( File "/usr/local/lib/python3.10/urllib/request.py", line 216, in urlopen return opener.open(url, data, timeout) File "/usr/local/lib/python3.10/urllib/request.py", line 519, in open response = self._open(req, data) File "/usr/local/lib/python3.10/urllib/request.py", line 536, in _open result = self._call_chain(self.handle_open, protocol, protocol + File "/usr/local/lib/python3.10/urllib/request.py", line 496, in _call_chain result = func(*args) File "/usr/local/lib/python3.10/urllib/request.py", line 1377, in http_open return self.do_open(http.client.HTTPConnection, req) File "/usr/local/lib/python3.10/urllib/request.py", line 1351, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [Errno 99] Address not available> 2022-07-07 01:59:53,388 - werkzeug - INFO - 172.17.0.1 - - [07/Jul/2022 01:59:53] "GET /accountcategorys?label=account123&page=1&per_page=100 HTTP/1.1" 500 -

dgarijo commented 2 years ago

Hmm, I do not think so, as far as I remember. We do have logging, but I don't think we enabled detailed logging :(

DougalW commented 2 years ago

Hi - this issue

I will have a look when I have the chance. At least the generation of the API should work. The server generation is a little more tricky, with a lot of changing dependencies.

This seems to be caused in OBA Sparql Query Manager not handling the JSON-LD @Content processing correctly for payloads returned from a graph in JSON-LD Expanded format. I've raised an issue in https://github.com/KnowledgeCaptureAndDiscovery/OBA_sparql/issues/43