Skip to content

Commit

Permalink
Add SPARQL queries
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekSuchanek committed Oct 13, 2020
1 parent 773a239 commit aeb1a3a
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
env/
venv/
_build/
__pycache__/

107 changes: 107 additions & 0 deletions docs/about/usage-scenarios.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,110 @@ Submit FIP
4. Press :guilabel:`Create` (optionally, you can change the document name, e.g. "My community - v0.1")
5. Press three dots on the right for the new document and press :guilabel:`Submit`
6. Select the triple store you want to use and press :guilabel:`Submit`

FAIR Matrix SPARQL Queries
--------------------------

Once you have submitted FIPs in the triple store, you can use various SPARQL queries to explore its contents based on your specific needs. We recommend the `Wikidata's SPARQL tutorial <https://www.wikidata.org/wiki/Wikidata:SPARQL_tutorial>`_.

List declarations for Community
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For a specific Community, e.g. `ENVRI <http://purl.org/np/RAbJisTAUu82wSY_FQ4CrFyA_kPd_0Jvyu2JrNZmO1jPo#ENVRI>`_, you can list all the declarations about current use of a Resource with respect to a FIP Question.

.. code-block:: sparql
PREFIX fip: <https://w3id.org/fair/fip/terms/>
SELECT ?decl ?question ?resource
WHERE {
?decl a fip:FIP-Declaration ;
fip:declared-by <http://purl.org/np/RAbJisTAUu82wSY_FQ4CrFyA_kPd_0Jvyu2JrNZmO1jPo#ENVRI> ;
fip:refers-to-question ?question ;
fip:declares-current-use-of ?resource .
}
List usages of Resource
~~~~~~~~~~~~~~~~~~~~~~~

For a specific Resource, e.g. `Digital Object Identifier <http://www.wikidata.org/entity/Q25670>`_, you can list which communities use (or plan to use) it. You can easily filter our Resources for a specific Community.

.. code-block:: sparql
PREFIX fip: <https://w3id.org/fair/fip/terms/>
SELECT DISTINCT ?community
WHERE {
{
?decl a fip:FIP-Declaration ;
fip:declared-by ?community ;
fip:declares-current-use-of <http://www.wikidata.org/entity/Q25670> .
}
UNION
{
?decl a fip:FIP-Declaration ;
fip:declared-by ?community ;
fip:declares-planned-use-of <http://www.wikidata.org/entity/Q25670> .
}
}
Count usages of Resource
~~~~~~~~~~~~~~~~~~~~~~~~

You can also count, for example, how many communities use (currently) a specific Resource.

.. code-block:: sparql
PREFIX fip: <https://w3id.org/fair/fip/terms/>
SELECT (COUNT(DISTINCT ?community) as ?count)
WHERE {
?decl a fip:FIP-Declaration ;
fip:declared-by ?community ;
fip:declares-current-use-of <http://purl.org/np/RAiyPQd01Y1u-qo3HG3PDVgpHiIuNO9YngYlju1WTyzRI#DOI> .
}
FAIR Matrix query
~~~~~~~~~~~~~~~~~

This query prepares a table for building FAIR Matrix. You can further limit it by including Community, Question, type of relation (use or planned), or Resource directly in the query.

.. code-block:: text
PREFIX fip: <https://w3id.org/fair/fip/terms/>
SELECT ?community ?question ?rel ?resource ?resource_label ?resource_type
WHERE {
?decl a fip:FIP-Declaration ;
fip:refers-to-question ?question ;
fip:declared-by ?community ;
?rel ?resource .
VALUES ?rel {
fip:declares-current-use-of
fip:declares-planned-use-of
}
OPTIONAL {
?resource rdfs:label ?resource_label
}
OPTIONAL {
VALUES ?resource_type {
fip:Available-FAIR-Enabling-Resource
fip:FAIR-Enabling-Resource-to-be-Developed
}
?resource a ?resource_type
}
}
In FAIR Matrix (or FIP Fingerprint), use of a Resource by a Community can be:

- ``0`` = Resource is not used by Community (cannot be queried, need to compare the list of all possible resources with used resources)
- ``1`` = Resource is currently used by Community (limit only to ``fip:declares-current-use-of``)
- ``2`` = Resource is planned to be used by Community (limit only to ``fip:declares-planned-use-of``)

This query uses `SPARQL 1.1 <https://www.w3.org/TR/sparql11-query/>`_ with keywords ``VALUES`` and ``OPTIONAL``. You need to pre-fill your triple store with the Resources (with type and label at minimum).


0 comments on commit aeb1a3a

Please sign in to comment.