-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor code to put queries in their own file
- Loading branch information
1 parent
eb01e62
commit 4005d3b
Showing
2 changed files
with
133 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
class VP | ||
NAMESPACES = "PREFIX ejpold: <http://purl.org/ejp-rd/vocabulary/> | ||
PREFIX ejpnew: <https://w3id.org/ejp-rd/vocabulary#> | ||
PREFIX dcat: <http://www.w3.org/ns/dcat#> | ||
PREFIX dc: <http://purl.org/dc/terms/> | ||
".freeze | ||
# VPCONNECTION = "ejpold:vpConnection ejpnew:vpConnection dcat:theme dcat:themeTaxonomy".freeze | ||
# VPDISCOVERABLE = "ejpold:VPDiscoverable ejpnew:VPDiscoverable".freeze | ||
# VPANNOTATION = "dcat:theme".freeze | ||
VPCONNECTION = "ejpnew:vpConnection".freeze | ||
VPDISCOVERABLE = "ejpnew:VPDiscoverable".freeze | ||
VPANNOTATION = "dcat:theme".freeze | ||
|
||
def find_discoverables_query(graph:) | ||
SPARQL.parse(" | ||
#{NAMESPACES} | ||
SELECT DISTINCT ?s ?t ?title ?contact ?servicetype WHERE | ||
{ | ||
VALUES ?connection { #{VPCONNECTION} } | ||
VALUES ?discoverable { #{VPDISCOVERABLE} } | ||
?s ?connection ?discoverable ; | ||
dc:title ?title ; | ||
a ?t . | ||
OPTIONAL{?s dcat:contactPoint ?c . | ||
?c <http://www.w3.org/2006/vcard/ns#url> ?contact }. | ||
OPTIONAL{?s dc:type ?servicetype }. | ||
} | ||
") | ||
graph.query(vpd) | ||
end | ||
|
||
def keyword_search_query(graph:, keyword:) | ||
vpd = SPARQL.parse(" | ||
#{NAMESPACES} | ||
SELECT DISTINCT ?s ?t ?title ?contact WHERE | ||
{ | ||
VALUES ?connection { #{VPCONNECTION} } | ||
VALUES ?discoverable { #{VPDISCOVERABLE} } | ||
?s ?connection ?discoverable ; | ||
dc:title ?title ; | ||
a ?t . | ||
OPTIONAL{?s dcat:contactPoint ?c . | ||
?c <http://www.w3.org/2006/vcard/ns#url> ?contact } . | ||
{ | ||
VALUES ?searchfields { dc:title dc:description dc:keyword } | ||
?s ?searchfields ?kw | ||
FILTER(CONTAINS(lcase(?kw), '#{keyword}')) | ||
} | ||
}") | ||
# warn "keyword search query #{vpd.to_sparql}" | ||
# warn "graph is #{@graph.size}" | ||
graph.query(vpd) | ||
|
||
end | ||
|
||
def ontology_search_query(graph:, uri:) | ||
vpd = SPARQL.parse(" | ||
#{NAMESPACES} | ||
SELECT DISTINCT ?s ?t ?title ?contact WHERE | ||
{ | ||
VALUES ?connection { #{VPCONNECTION} } | ||
VALUES ?discoverable { #{VPDISCOVERABLE} } | ||
?s ?connection ?discoverable ; | ||
dc:title ?title ; | ||
a ?t . | ||
OPTIONAL{?s dcat:contactPoint ?c . | ||
?c <http://www.w3.org/2006/vcard/ns#url> ?contact } . | ||
{ | ||
?s dcat:theme ?theme . | ||
FILTER(CONTAINS(str(?theme), '#{uri}')) | ||
} | ||
}") | ||
|
||
graph.query(vpd) | ||
end | ||
|
||
def verbose_annotations_query(graph:) | ||
# TODO: This does not respect vpdiscoverable... | ||
vpd = SPARQL.parse(" | ||
#{NAMESPACES} | ||
SELECT DISTINCT ?annot WHERE | ||
{ VALUES ?annotation { dcat:theme dcat:themeTaxonomy } | ||
?s ?annotation ?annot . | ||
}") | ||
graph.query(vpd) | ||
end | ||
|
||
def keyword_annotations_query(graph:) | ||
vpd = SPARQL.parse(" | ||
#{NAMESPACES} | ||
select DISTINCT ?kw WHERE | ||
{ VALUES ?searchfields { dc:keyword } | ||
?s ?searchfields ?kw . | ||
}") | ||
graph.query(vpd) | ||
|
||
end | ||
|
||
def collect_data_services_query(graph:) | ||
vpd = SPARQL.parse(" | ||
#{NAMESPACES} | ||
SELECT DISTINCT ?type WHERE | ||
{ | ||
VALUES ?connection { #{VPCONNECTION} } | ||
VALUES ?discoverable { #{VPDISCOVERABLE} } | ||
?s ?connection ?discoverable ; | ||
a dcat:DataService . | ||
{ | ||
?s dc:type ?type . | ||
} | ||
}") | ||
graph.query(vpd) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters