OWL based configuration : datasources - sparna-git/Sparnatural Wiki


Datasources basics

As indicated in the OWL-based configuration reference, lists and autocomplete properties in Sparnatural require a ds:datasource annotation to populate respectively the list of values or the values proposed by autocompletion. In its simplest and most common form a datasource is basically a SPARQL query that returns the expected columns to be used to populate the list/autocomplete values.

The datasource annotation configuration can be either:

  1. A reference to a pre-configured datasource;
  2. A reference to a pre-configured SPARQL query, plus a property URI to be injected in this query;
  3. Your own SPARQL query;

These 3 solutions are described below.

Preconfigured datasources

Preconfigured datasources for a ListProperty

Sparnatural comes preconfigured with datasources that can populate lists based on rdfs:label, skos:prefLabel, foaf:name, dcterms:title, schema:name or the URI of the entity (which is the default behavior). For each of these properties, 3 flavors of datasource exist : either with an alphabetical ordering, an alphabetical ordering plus the count shown in parenthesis, or a descending count ordering.

Use one of these datasources if your RDF data relies on one of these properties.

The preconfigured datasource identifiers for a ListProperty are :

  1. datasources:list_URI_alpha and datasources:list_URI_count
  2. datasources:list_rdfslabel_alpha and datasources:list_rdfslabel_count and datasources:list_rdfslabel_alpha_with_count
  3. datasources:list_skospreflabel_alpha and datasources:list_skospreflabel_count and datasources:list_skospreflabel_alpha_with_count
  4. datasources:list_foafname_alpha and datasources:list_foafname_count and datasources:list_foafname_alpha_with_count
  5. datasources:list_dctermstitle_alpha and datasources:list_dctermstitle_count and datasources:list_dctermstitle_alpha_with_count
  6. datasources:list_schemaname_alpha and datasources:list_schemaname_count and datasources:list_schemaname_alpha_with_count

You can find these identifiers in Protégé when you create the ds:datasource](http://data.sparna.fr/ontologies/sparnatural-config-datasources#datasource) annotation under the tabs "Entity IRI", then "Individuals" :

Screenshot Protégé datasources

Preconfigured datasources for an AutocompleteProperty

Sparnatural comes preconfigured with datasources that can populate autocomplete fields based on rdfs:label, skos:prefLabel, foaf:name, dcterms:title, schema:name or the URI of the entity (which is the default behavior). For each of these properties, 3 flavors of datasource exist : either searching by the beginning of the value with strstarts(), anywhere in the value with contains() or using Virtuoso-specific bif:contains() function. Additionnally, a search datasource can search on the URI using the contains() function, which is the default behavior.

The preconfigured datasource identifiers for an AutocompleteProperty are :

  1. datasources:search_URI_contains
  2. datasources:search_rdfslabel_strstarts
  3. datasources:search_rdfslabel_contains
  4. datasources:search_rdfslabel_bifcontains
  5. datasources:search_foafname_strstarts
  6. datasources:search_foafname_contains
  7. datasources:search_foafname_bifcontains
  8. datasources:search_dctermstitle_strstarts
  9. datasources:search_dctermstitle_contains
  10. datasources:search_dctermstitle_bifcontains
  11. datasources:search_skospreflabel_strstarts
  12. datasources:search_skospreflabel_contains
  13. datasources:search_skospreflabel_bifcontains
  14. datasources:search_schemaname_strstarts
  15. datasources:search_schemaname_contains
  16. datasources:search_schemaname_bifcontains

Similarly to list datasources, you find these under the "Entity IRI" > "Individuals" tab of Protégé when you edit the ds:datasource annotation :

Screenshot Protégé datasources

Preconfigured SPARQL query with another property

How-to create your own datasource with an existing SPARQL query but using another property

If the preconfigured datasources do not fit the data model to be queried, you have the ability to refer to the same SPARQL queries used by these datasources, but adjust the property to be searched or used as a label. To do so, you need to create a new individual in Protégé, of type SparqlDatasource, and provide 2 information:

  1. in the "Object property assertion" field of Protégé, a queryTemplate reference to one of the preconfigured SPARQL query template, namely:
    1. datasources:query_list_label_alpha
    2. datasources:query_list_label_count
    3. datasources:query_list_label_alpha_with_count
    4. datasources:query_list_label_with_range_alpha
    5. datasources:query_list_label_with_range_count
    6. datasources:query_list_label_with_range_alpha_with_count
    7. datasources:query_search_label_strstarts
    8. datasources:query_search_label_bifcontains
  2. And one of those 2 Annotations (in the "Annotations" section of Protégé):
    1. datasources:labelProperty with the IRI of the label property to use
    2. datasources:labelPath with the SPARQL property path to use (using angle brackets, no prefixes) to fetch the label of entities. In particular this allows to deal with situations where the labels are reified as separate entities.

For example to create a new custom datasource that will use dc:title as the label, and use an alphabetical ordering, do the following:

Screenshot Protégé custom datasource

Queries without range / queries with range

The provided queries to populate the lists do not use the range of the value as a criteria in the query. In other words, all the values of the given property in the given domain are returned, independantly of their type. This is usually sufficient and more performant but this can be a problem if the same property in the same domain can refer to entities of different type in the Sparnatural configuration. For example "Document > creator > Person or Organization". To use the range as a criteria in the query and filter the list based on the type of the value, create a datasource based on a query including "...with_range..." in its identifier. This will garantee that only values of the selected type will appear in the list.

Your own SPARQL query

You can provide your own SPARQL queries to populate lists or autocomplete suggestions. To do so, attach a queryString data property assertion on your datasource object, holding the SPARQL query that should be used to populate the list/autocomplete.

The SPARQL query MUST return 2 variables : ?uri and ?label, populated anyway you like.

In this SPARQL query, the following replacements will happen:

Take a look at the preconfigured SPARQL queries in the Sparnatural datasources ontology to get you started.