Skip to content

Conversation

@WhiteGobo
Copy link
Contributor

This script doesnt support update methods like INSERT or DELETE.
Try handling to mirror that of rdfpipe. Choosing argparse over optargs as described in documentation of optargs.

support for multiple local files, single remote and stdin. remote support auth. Access to different remote storetype.

Output will controlled by --format. Will either choose ResultParser or Parser plugins. Help will show extra help to the selected Parser.

added test_sparqlquery for DESCRIBE ASK SELECT and CONSTRUCT query. Also testing for sparql endpoint with mock endpoint. Test for BerkeleyDB.

Summary of changes

Checklist

  • Default to readable output

  • Testing for

    • works on local files from command line
    • on local files
    • on sparql remotes
    • on berkeleydb
    • SELECT
    • ASK
    • DESCRIBE
    • CONSTRUCT
    • authentication
  • Checked that all tests and type checking passes.

  • If the change adds new features or changes the RDFLib public API:

  • If the change has a potential impact on users of this project:

    • Added or updated tests that fail without the change.
    • Updated relevant documentation to avoid inaccuracies.(correct description in rdflib.tools)
    • Considered adding additional documentation.
    • produces documentation in rdflib.tools.sparqlquery
    • has functional help output
  • Considered granting push permissions to the PR branch,
    so maintainers can fix minor issues and keep your PR up to date.

Try handling to mirror that of rdfpipe. Choosing argparse over optargs as described in documentation of optargs.

support for multiple local files, single remote and stdin. remote support auth.
Access to different remote storetype.

Output will controlled by --format. Will either choose ResultParser or
Parser plugins. Help will show extra help to the selected Parser.

added test_sparqlquery for DESCRIBE ASK SELECT and CONSTRUCT query. Also
testing for sparql endpoint with mock endpoint. Test for BerkeleyDB.
@WhiteGobo
Copy link
Contributor Author

example help output:

>>>python -m rdflib.tools.sparqlquery
usage: sparqlquery [-q QUERY] [--queryfile QUERYFILE] [--format FORMAT] [-w]
                   [--help] [--username USERNAME] [--password PASSWORD]
                   [--remote-storetype REMOTE_STORETYPE]
                   endpoint [endpoint ...]

A commandline tool for querying with sparql
on local files and remote sparql endpoints with custom serialization.

example usage:
'''bash
    sparqlquery path/to/data.ttl -q "SELECT ?x WHERE {?x a foaf:Person. }"
    rdfpipe test.ttl | sparqlquery - -q "SELECT ?x WHERE {?x a foaf:Person. }" --format json
    sparqlquery data.ttl -q "ASK {:john a foaf:Person}" --format xml | grep true
    sparqlquery path/to/data.ttl --query-file query.rq
    sparqlquery data1.ttl data2.ttl -q "DESCRIBE <http://example.com/john>" --format turtle:+spacious
    sparqlquery http://example.com/sparqlendpoint --query-file query.rq
    sparqlquery http://example.com/sparqlendpoint --query-file query.rq --username user --password secret
    sparqlquery /pyth/to/berkeley.db -q "SELECT ?x WHERE {?x a foaf:Person. }" --remote-storetype BerkeleyDB
'''

Tip: You can check the truth value for an ASK query, by regex in stdout for 'true'
or 'false'.

positional arguments:
  endpoint              Endpoints for sparql query. Can be set to multiple files.
                        Reads from stdin if '-' is given.

options:
  -q, --query QUERY     Sparql query. Cannot be set together with --queryfile.
  --queryfile QUERYFILE
                        File from where the sparql query is read. Cannot be set
                        together with -q/--query
  --format FORMAT       Print sparql result in given format. Defaults to 'json' on
                        SELECT, to 'xml' on ASK and to 'turtle' on DESCRIBE and
                        CONSTRUCT. Keywords as described in epilog can be given
                        after format like: FORMAT:(+)KW1,-KW2,KW3=VALUE.
  -w, --warn            Output warnings to stderr (by default only critical
                        errors).
  --help                show help message and exit. Also prints information about
                        given format.
  --username USERNAME   Username used during authentication.
  --password PASSWORD   Password used during authentication.
  --remote-storetype REMOTE_STORETYPE
                        You can specify which storetype should be used. Can only be
                        set, when using a single endpoint and not stdin. Will
                        default to 'SparqlStore' when endpoint is an
                        internetaddress.

For more customization for format 'json' use `pydoc rdflib.plugins.sparql.results.jsonresults.JSONResultSerializer.serialize`.  Further keywords might be valid.
the following arguments are required: endpoint

@WhiteGobo
Copy link
Contributor Author

Im not sure, why validation fails on windows.

@edmondchuc
Copy link
Contributor

I've pushed a couple of commits to fix some of the failing tests @WhiteGobo.

I think windows absolute paths were being interpreted as valid URLs. Fixed in 624dbcf

There was also a separate import error with pyparsing. For v7 of RDFLib, the minimum pyparsing version we support is 2.1.0 as indicated by

pyparsing==2.1.0

In pyparsing v2, it has a different package structure. I've added handling for it now in 380bbe5

@WhiteGobo
Copy link
Contributor Author

Thx, the _dest_is_local isnt exactly the best function i ever wrote. I believe, i could just remove it completly and catch the error when the graph tries to parse the file. But i guess i first want to get my hands on a windows setup.
All in all the automatic handling if something is a remote sparql access point or a file, i'm not really very happy about my work here.

Try handling to mirror that of rdfpipe. Choosing argparse over optargs as described in documentation of optargs.

support for multiple local files, single remote and stdin. remote support auth.
Access to different remote storetype.

Output will controlled by --format. Will either choose ResultParser or
Parser plugins. Help will show extra help to the selected Parser.

added test_sparqlquery for DESCRIBE ASK SELECT and CONSTRUCT query. Also
testing for sparql endpoint with mock endpoint. Test for BerkeleyDB.
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 this pull request may close these issues.

2 participants