Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using "describe" in a comment leads to error #211

Open
WolfgangFahl opened this issue Mar 14, 2022 · 12 comments
Open

using "describe" in a comment leads to error #211

WolfgangFahl opened this issue Mar 14, 2022 · 12 comments

Comments

@WolfgangFahl
Copy link

# Count all academic conference(Q2020153) https://www.wikidata.org/wiki/Q2020153 items
# with the given described at URL(P973) https://www.wikidata.org/wiki/Property:P973 
SELECT ?item (COUNT (?value) AS ?count)
WHERE
{
  # instance of academic conference
  ?item wdt:P31 wd:Q2020153.
  # described at URL
  ?item wdt:P973 ?value.
} GROUP by ?item
HAVING (COUNT (?value) > 1)
ORDER BY DESC(?count)

will fail.

.. lib/python/site-packages/SPARQLWrapper/Wrapper.py:979: RuntimeWarning: Sending Accept header '/' because unexpected returned format 'json' in a 'DESCRIBE' SPARQL query form
warnings.warn("Sending Accept header '/' because unexpected returned format '%s' in a '%s' SPARQL query form" % (self.returnFormat, self.queryType), RuntimeWarning)

@WolfgangFahl
Copy link
Author

WolfgangFahl commented Mar 14, 2022

query

# Count all academic conference(Q2020153) https://www.wikidata.org/wiki/Q2020153 items
# with the given describ'd at URL(P973) https://www.wikidata.org/wiki/Property:P973 
SELECT ?item (COUNT (?value) AS ?count)
WHERE
{
  # instance of academic conference
  ?item wdt:P31 wd:Q2020153.
  # describ'd at URL
  ?item wdt:P973 ?value.
} GROUP by ?item
HAVING (COUNT (?value) > 1)
ORDER BY DESC(?count)

result

item count
http://www.wikidata.org/entity/Q106540635 3
http://www.wikidata.org/entity/Q106331820 2

@eggplants
Copy link
Contributor

eggplants commented Mar 14, 2022

$ rqw --version
rqw 2.0.0
$ cat query.rq
# Count all academic conference(Q2020153) https://www.wikidata.org/wiki/Q2020153 items
# with the given described at URL(P973) https://www.wikidata.org/wiki/Property:P973 
SELECT ?item (COUNT (?value) AS ?count)
WHERE
{
  # instance of academic conference
  ?item wdt:P31 wd:Q2020153.
  # described at URL
  ?item wdt:P973 ?value.
} GROUP by ?item
HAVING (COUNT (?value) > 1)
ORDER BY DESC(?count)

$ rqw -e 'https://query.wikidata.org/sparql' -f query.rq
/Users/eggplants/.pyenv/versions/3.9.10/lib/python3.9/site-packages/SPARQLWrapper/Wrapper.py:794: RuntimeWarning: Sending Accept header '*/*' because unexpected returned format 'json' in a 'DESCRIBE' SPARQL query form
  warnings.warn(
{
    "head": {
        "vars": [
            "item",
            "count"
        ]
    },
    "results": {
        "bindings": [
            {
                "item": {
                    "type": "uri",
                    "value": "http://www.wikidata.org/entity/Q106540635"
                },
                "count": {
                    "datatype": "http://www.w3.org/2001/XMLSchema#integer",
                    "type": "literal",
                    "value": "3"
                }
            },
            {
                "item": {
                    "type": "uri",
                    "value": "http://www.wikidata.org/entity/Q106331820"
                },
                "count": {
                    "datatype": "http://www.w3.org/2001/XMLSchema#integer",
                    "type": "literal",
                    "value": "2"
                }
            }
        ]
    }
}

@WolfgangFahl What version are you using?

@WolfgangFahl
Copy link
Author

WolfgangFahl commented Mar 14, 2022

pip list | grep -i sparqlwrapper
SPARQLWrapper                 1.8.5

since this seems not to be the most recent i did

pip install sparqlwrapper -U
rqw --version
rqw 2.0.0
python --version
Python 3.9.10
rqw -e 'https://query.wikidata.org/sparql' -f query.rq
/Users/wf/Library/Python/3.9/lib/python/site-packages/SPARQLWrapper/Wrapper.py:794: RuntimeWarning: Sending Accept header '*/*' because unexpected returned format 'json' in a 'DESCRIBE' SPARQL query form
  warnings.warn(
{
    "head": {
        "vars": [
            "item",
            "count"
        ]
    },
    "results": {
        "bindings": [
            {
                "item": {
                    "type": "uri",
                    "value": "http://www.wikidata.org/entity/Q106540635"
                },
                "count": {
                    "datatype": "http://www.w3.org/2001/XMLSchema#integer",
                    "type": "literal",
                    "value": "3"
                }
            },
            {
                "item": {
                    "type": "uri",
                    "value": "http://www.wikidata.org/entity/Q106331820"
                },
                "count": {
                    "datatype": "http://www.w3.org/2001/XMLSchema#integer",
                    "type": "literal",
                    "value": "2"
                }
            }
        ]
    }
}

@WolfgangFahl
Copy link
Author

Why does the runtime warning lead to a failure in the programmatic access?

@eggplants
Copy link
Contributor

What do you mean a failure in the programmatic access? the query seems to be successful.

@WolfgangFahl
Copy link
Author

In the debugger:
grafik
grafik
The query type is detected as "DESCRIBE" so there is no binding resolution.

@WolfgangFahl
Copy link
Author

Oh 2.0.0 was just release today - now i get it. The pyLodStorage unit tests seem to fail with this see https://github.com/WolfgangFahl/pyLoDStorage/actions.

@eggplants
Copy link
Contributor

The query type is detected as "DESCRIBE" so there is no binding resolution.

This apparently mismatch of query type maybe causes:

query = self._cleanComments(query)
query_for_queryType = re.sub(self.prefix_pattern, "", query.strip())
# type error: Item "None" of "Optional[Match[str]]" has no attribute "group"
r_queryType = (
self.pattern.search(query_for_queryType).group("queryType").upper() # type: ignore[union-attr]
)

The pyLodStorage unit tests seem to fail with this see

2.0.0 has huge breaking changes.
If you find any errors it would be great if you could send a fixture PR to sparqlwrapper as well as your project.

@eggplants
Copy link
Contributor

eggplants commented Mar 14, 2022

@WolfgangFahl Rdflib members seems to be under-resourced.
So I think it would be better if you create a PR that resolves this issue (and also your other Issues) rather than waiting for others.

@WolfgangFahl
Copy link
Author

Just did a 0.1.19 release for pyLodStorage pinning sparqlwrapper to 1.8.5 i am now working on the 0.2.0 release intending to use the newer version of SPARQLWrapper. I'll have to work around the "described" issue for the time being in my downstream projects until things are fixed here. No i don't really have time to help with PRs - pyLodStorage was created as a separate project after #160 was not incorporated directly here. We could merge things again but that would be some major refactoring effort. I would love to have the named query and query result documentation support being integrated here for instance see WolfgangFahl/pyLoDStorage#78.

@eggplants
Copy link
Contributor

eggplants commented Mar 14, 2022

Sparqlwrapper uses regular expressions for uncommenting queries and extracting types, which is a bad point and problematic. It may be better to use rdflib.plugins.sparql.parser.parseQuery(q) at SPARQLWrapper._parseQueryType(q). I'll try to do it later, and it will be deal with this issue.

@WolfgangFahl
Copy link
Author

WolfgangFahl commented Mar 15, 2022

@eggplants - thx for your current engagement. When i wrote " No i don't really have time to help with PRs" - this means that currently i am busy. I have already closed one of the issues you mentioned and intend to do more in the future. I suggest to open the discussions here in github for being able to have some communication about ideas and other aspects that are not directly issue related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants