simphony / simphony-osp

A framework that aims to achieve interoperability between software such as simulation engines, databases and data repositories using a knowledge graph as the common language.
https://simphony.readthedocs.io
Other
16 stars 12 forks source link

Fetch datatypes from Sparql-Result #663

Closed MBueschelberger closed 3 years ago

MBueschelberger commented 3 years ago

closes #655

kysrpex commented 3 years ago

Thanks @MBueschelberger. I think this is almost ready except for one detail, that I noticed just after our conversation on Thursday. See the explanation below.


Imagine I execute the following code:

for citizen in result(age=int):
    print(type(citizen['age']) is int)
    break

Then the outcome is True as we want.

But if afterwards I execute this other code

for citizen in result:
    print(type(citizen['age']) is int)
    break

As a user I would expect the outcome to be False, but I get True, because no dictionary update happened. Before merging we should solve this little problem.


If you have any idea just feel free to commit. I'll consider this to be my task too, so if I come up with something I may commit as well.

MBueschelberger commented 3 years ago

Thanks @MBueschelberger. I think this is almost ready except for one detail, that I noticed just after our conversation on Thursday. See the explanation below.

Imagine I execute the following code:

for citizen in result(age=int):
    print(type(citizen['age']) is int)
    break

Then the outcome is True as we want.

But if afterwards I execute this other code

for citizen in result:
    print(type(citizen['age']) is int)
    break

As a user I would expect the outcome to be False, but I get True, because no dictionary update happened. Before merging we should solve this little problem.

If you have any idea just feel free to commit. I'll consider this to be my task too, so if I come up with something I may commit as well.

Yes, I can do so.

kysrpex commented 3 years ago

It passes the tests, so it works, but just to see how things would look in a real use case, I tried this with the UrWerk data.

[...]
        for row in result(series='cuds', literal=float):
            print(f"SPARQL result: {row['series'], row['literal']}.")
            break
        for row in result:
            print(f"SPARQL result: {row['series'], row['literal']}.")
            break    
SPARQL result: (<mechanical.Series: 7f0b79aa-0bac-4aaf-b90d-f2945c7acfaf,  AGraphSession: @0x7f9fdfad3940>, 161.011).
SPARQL result: (rdflib.term.URIRef('http://www.osp-core.com/cuds#4ae03ee7-b940-459e-9939-dd8db3c8e5c2'), rdflib.term.Literal('761.716', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#double'))).

Looks nice. Thanks @MBueschelberger.