Projects/Nepomuk/SparqlQueries

    From KDE TechBase

    Depending on the needs of your application you may need to directly run sparql queries.

    Sparql Prefixes

    When writing SPARQL queries, according to the standard one needs to prepend the queries with the prefixes that have been used. For example -

    PREFIX nco: <http://www.semanticdesktop.org/ontologies/2007/03/22/nco#> .
    select ?r ?name where { ?r a nco:Contact . ?r nco:fullname ?name . }
    


    When running queries in Nepomuk, you do not need to explicitly add the prefix. The prefix will automatically be added by the storage service.

    Full Text Indexing

    Nepomuk depends on Virtuoso for data storage. Virtuoso brings a lot of nice extensions to SPARQL. Most importantly the full text search which is used through the artificial bif:contains property.

    This allows to combine graph queries with full text queries in a nice way:

    select ?r where { ?r nao:prefLabel ?label .
                      ?label bif:contains 'nepomuk' . }
    

    The query above will find any resources that contain nepomuk in their label.

    Of course wildcards are supported, too. However, be aware that when using wildcards the expression itself needs to be enclosed in quotes as follows:

    select ?r where { ?r nao:prefLabel ?label .
                      ?label bif:contains "'nepomuk*'" . }
    


    Please note the virtuoso requires a minimum of 4 leading characters in order to use wildcards.