Module: Krikri::ProvenanceQueryClient
- Defined in:
- lib/krikri/provenance_query_client.rb
Overview
Implements SPARQL queries for finding RDF Resources by their PROV-O history.
Constant Summary collapse
- SPARQL_CLIENT =
Repository.query_client
Class Method Summary collapse
-
.find_by_activity(activity_uri, include_invalidated = false) ⇒ RDF::SPARQL::Query
Finds all entities generated or revised by the activity whose URI is given.
Class Method Details
.find_by_activity(activity_uri, include_invalidated = false) ⇒ RDF::SPARQL::Query
Finds all entities generated or revised by the activity whose URI is given.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/krikri/provenance_query_client.rb', line 23 def find_by_activity(activity_uri, include_invalidated = false) raise ArgumentError, 'activity_uri must be an RDF::URI' unless activity_uri.respond_to? :to_term query = SPARQL_CLIENT.select(:record) .where([:record, [RDF::PROV.wasGeneratedBy, '|', RDF::DPLA.wasRevisedBy], activity_uri.to_term]) if include_invalidated query else # We need to say "and if RDF::PROV.invalidatedAtTime is not set." # # The SPARQL query should be: # # PREFIX prov: <http://www.w3.org/ns/prov#> # SELECT * WHERE { # ?subject prov:wasGeneratedBy <http://xampl.org/ldp/activity/n> . # FILTER NOT EXISTS { ?subject prov:invalidatedAtTime ?x } # } # # ... However there doesn't appear to be a way of constructing # 'FILTER NOT EXISTS' with SPARQL::Client. Instead, we've managed to # hack the following solution together. # # SPARQL::Client#filter is labeled @private in its YARD comment (and # has no other documentation) but it's not private, at least for # now. query.filter \ 'NOT EXISTS ' \ '{ ?record <http://www.w3.org/ns/prov#invalidatedAtTime> ?x }' end end |