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

feat: add support for query datasets #152

Merged
merged 3 commits into from
Jun 27, 2023

Conversation

noahgorstein
Copy link
Member

@noahgorstein noahgorstein commented Jun 23, 2023

Adds support for query datasets:

That is for SELECT/CONSTRUCT/PATHS/ASK SPARQL query types:

  • default-graph-uri - URI(s) to be used as the default graph (equivalent to FROM)
  • named-graph-uri - URI(s) to be used as named graphs (equivalent to FROM NAMED)

can now be supplied as a parameter to their respective methods.

   default_graph_dataset = ["http://graph1", "http://graph2"]

    response = conn.select(
        query="select * { ?s ?p ?o }",
        default_graph_uri=default_graph_dataset,
    )

For SPARQL Update queries, the following parameters are now available on the update method:

  • using-graph-uri - URI(s) to be used as the default graph (equivalent to USING)
  • using-named-graph-uri- URI(s) to be used as named graphs (equivalent to USING NAMED)
  • remove-graph-uri - URI of the graph to be inserted into
  • insert-graph-uri - URI of the graph to be removed from

For example, the following code will add the triples defined in the INSERT DATA clause to the_graph:

    the_graph = "http://my-graph"
    insert_data = """
    INSERT DATA {
        <ex:a> <ex:b> <ex:c> .
        <ex:d> <ex:e> <ex:f> .
    }
    """
    
    conn.begin()
    conn.update(query=insert_data, insert_graph_uri=the_graph)
    conn.commit()

    response = conn.select(
        query="select * { ?s ?p ?o }",
        default_graph_uri=[the_graph],
    )
    assert len(response["results"]["bindings"]) == 2

I added minimal tests for all the parameters above - more tests could probably be done for ASK/ CONSTRUCT / PATHS but I think these can come later.

All of the new parameters mentioned above are all documented in the Stardog HTTP API docs: https://stardog-union.github.io/http-docs/#tag/SPARQL/operation/updatePost

Closes #32

@noahgorstein noahgorstein merged commit 651c341 into main Jun 27, 2023
@noahgorstein noahgorstein deleted the feature/add-support-for-query-datasets branch June 27, 2023 01:22
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.

Add support for query datasets
2 participants