Skip to content

Commit

Permalink
Add filters in vocabulary pages
Browse files Browse the repository at this point in the history
  • Loading branch information
ehrhart committed Oct 14, 2022
1 parent 8ed62b8 commit 990c7c7
Show file tree
Hide file tree
Showing 5 changed files with 391 additions and 52 deletions.
65 changes: 54 additions & 11 deletions config/routes/fragrant-spaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,73 @@ module.exports = {
$langTag: 'hide',
}),
},
query: ({ language }) => ({
query: ({ language, params }) => ({
$from: 'http://www.ontotext.com/disable-sameAs', // Prevent returning Wikidata entities
'@graph': [
{
'@id': '?id',
label: '?sourceLabel',
items: {
'@id': '?id',
label: '?bestLabel',
count: '?count',
},
dates: '?date',
},
],
$where: [
`
{
SELECT DISTINCT ?id WHERE {
?place crm:P2_has_type ?id .
?emission crm:P7_took_place_at ?place .
?emission od:F1_generated ?smell .
{
SELECT DISTINCT ?emission ?id WHERE {
?place crm:P2_has_type ?id .
?emission crm:P7_took_place_at ?place .
${
params.date
? `
?emission_source crm:P67_refers_to ?emission .
?emission_source schema:dateCreated/time:hasBeginning ${JSON.stringify(
params.date
)}^^xsd:gYear .
`
: ''
}
}
}
{
OPTIONAL {
SELECT DISTINCT ?id (COUNT(?object) AS ?count) WHERE {
?object crm:P137_exemplifies ?id .
}
GROUP BY ?id
}
}
{
OPTIONAL { ?id skos:prefLabel ?label_fr . FILTER(LANGMATCHES(LANG(?label_fr), "${language}")) }
OPTIONAL { ?id skos:prefLabel ?label_unk . FILTER(LANGMATCHES(LANG(?label_unk), "")) }
OPTIONAL { ?id skos:prefLabel ?label_en . FILTER(LANGMATCHES(LANG(?label_en), "en")) }
BIND(COALESCE(?label_fr, ?label_unk, ?label_en) AS ?bestKnownLabel)
OPTIONAL {
SELECT ?label_default WHERE {
?id skos:prefLabel ?label_default
}
ORDER BY ASC(?label_default)
LIMIT 1
}
BIND(COALESCE(?bestKnownLabel, ?label_default) AS ?bestLabel)
}
}
UNION
{
?id skos:prefLabel ?sourceLabel .
FILTER(LANG(?sourceLabel) = "${language}" || LANG(?sourceLabel) = "")
SELECT DISTINCT ?emission ?date WHERE {
?place crm:P2_has_type ?id .
?emission crm:P7_took_place_at ?place .
?source crm:P67_refers_to ?emission .
?source schema:dateCreated/time:hasBeginning ?date .
}
}
`,
],
$orderby: 'ASC(?sourceLabel)',
$orderby: params.order === 'count' ? 'DESC(?count)' : 'ASC(?bestLabel)',
$langTag: 'hide',
}),
plugins: {
Expand Down Expand Up @@ -137,7 +180,7 @@ module.exports = {
],
$where: [
`
?place crm:P2_has_type ?id .
?place crm:P137_exemplifies ?id .
?emission crm:P7_took_place_at ?place .
?emission od:F1_generated ?smell .
Expand Down
62 changes: 53 additions & 9 deletions config/routes/odour-carriers.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,73 @@ module.exports = {
$langTag: 'hide',
}),
},
query: ({ language }) => ({
query: ({ language, params }) => ({
$from: 'http://www.ontotext.com/disable-sameAs', // Prevent returning Wikidata entities
'@graph': [
{
'@id': '?id',
label: '?sourceLabel',
items: {
'@id': '?id',
label: '?bestLabel',
count: '?count',
},
dates: '?date',
},
],
$where: [
`
{
SELECT DISTINCT ?id WHERE {
olfactory-objects:carrier skos:member ?id .
?source crm:P2_has_type ?id .
{
SELECT DISTINCT ?emission ?id WHERE {
olfactory-objects:carrier skos:member ?id .
?emission od:F3_had_source / crm:P137_exemplifies ?id .
${
params.date
? `
?emission_source crm:P67_refers_to ?emission .
?emission_source schema:dateCreated/time:hasBeginning ${JSON.stringify(
params.date
)}^^xsd:gYear .
`
: ''
}
}
}
{
OPTIONAL {
SELECT DISTINCT ?id (COUNT(?object) AS ?count) WHERE {
?object crm:P137_exemplifies ?id .
}
GROUP BY ?id
}
}
{
OPTIONAL { ?id skos:prefLabel ?label_fr . FILTER(LANGMATCHES(LANG(?label_fr), "${language}")) }
OPTIONAL { ?id skos:prefLabel ?label_unk . FILTER(LANGMATCHES(LANG(?label_unk), "")) }
OPTIONAL { ?id skos:prefLabel ?label_en . FILTER(LANGMATCHES(LANG(?label_en), "en")) }
BIND(COALESCE(?label_fr, ?label_unk, ?label_en) AS ?bestKnownLabel)
OPTIONAL {
SELECT ?label_default WHERE {
?id skos:prefLabel ?label_default
}
ORDER BY ASC(?label_default)
LIMIT 1
}
BIND(COALESCE(?bestKnownLabel, ?label_default) AS ?bestLabel)
}
}
UNION
{
?id skos:prefLabel ?sourceLabel .
FILTER(LANG(?sourceLabel) = "${language}" || LANG(?sourceLabel) = "")
SELECT DISTINCT ?emission ?date WHERE {
olfactory-objects:carrier skos:member ?id .
?emission od:F3_had_source / crm:P137_exemplifies ?id .
?source crm:P67_refers_to ?emission .
?source schema:dateCreated/time:hasBeginning ?date .
}
}
`,
],
$orderby: 'ASC(?sourceLabel)',
$orderby: params.order === 'count' ? 'DESC(?count)' : 'ASC(?bestLabel)',
$langTag: 'hide',
}),
plugins: {
Expand Down
59 changes: 51 additions & 8 deletions config/routes/smell-sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,71 @@ module.exports = {
$langTag: 'hide',
}),
},
query: ({ language }) => ({
query: ({ language, params }) => ({
$from: 'http://www.ontotext.com/disable-sameAs', // Prevent returning Wikidata entities
'@graph': [
{
'@id': '?id',
label: '?sourceLabel',
items: {
'@id': '?id',
label: '?bestLabel',
count: '?count',
},
dates: '?date',
},
],
$where: [
`
{
SELECT DISTINCT ?id WHERE {
?emission od:F3_had_source / crm:P137_exemplifies ?id .
{
SELECT DISTINCT ?emission ?id WHERE {
?emission od:F3_had_source / crm:P137_exemplifies ?id .
${
params.date
? `
?emission_source crm:P67_refers_to ?emission .
?emission_source schema:dateCreated/time:hasBeginning ${JSON.stringify(
params.date
)}^^xsd:gYear .
`
: ''
}
}
}
{
OPTIONAL {
SELECT DISTINCT ?id (COUNT(?object) AS ?count) WHERE {
?object crm:P137_exemplifies ?id .
}
GROUP BY ?id
}
}
{
OPTIONAL { ?id skos:prefLabel ?label_fr . FILTER(LANGMATCHES(LANG(?label_fr), "${language}")) }
OPTIONAL { ?id skos:prefLabel ?label_unk . FILTER(LANGMATCHES(LANG(?label_unk), "")) }
OPTIONAL { ?id skos:prefLabel ?label_en . FILTER(LANGMATCHES(LANG(?label_en), "en")) }
BIND(COALESCE(?label_fr, ?label_unk, ?label_en) AS ?bestKnownLabel)
OPTIONAL {
SELECT ?label_default WHERE {
?id skos:prefLabel ?label_default
}
ORDER BY ASC(?label_default)
LIMIT 1
}
BIND(COALESCE(?bestKnownLabel, ?label_default) AS ?bestLabel)
}
}
UNION
{
?id skos:prefLabel ?sourceLabel .
FILTER(LANG(?sourceLabel) = "${language}" || LANG(?sourceLabel) = "")
SELECT DISTINCT ?emission ?date WHERE {
?emission od:F3_had_source / crm:P137_exemplifies ?id .
?source crm:P67_refers_to ?emission .
?source schema:dateCreated/time:hasBeginning ?date .
}
}
`,
],
$orderby: 'ASC(?sourceLabel)',
$orderby: params.order === 'count' ? 'DESC(?count)' : 'ASC(?bestLabel)',
$langTag: 'hide',
}),
plugins: {
Expand Down
21 changes: 21 additions & 0 deletions config/routes/texts.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,5 +569,26 @@ module.exports = {
],
filterFunc: (val) => `STR(?language) = ${JSON.stringify(val)}`,
},
{
id: 'museum',
isMulti: true,
isSortable: false,
query: () => ({
'@graph': [
{
'@id': '?location',
label: '?locationName',
},
],
$where: [
'?id crm:P53_has_former_or_current_location ?location',
'?location a gn:Feature',
'?location gn:name ?locationName',
],
$langTag: 'hide',
}),
whereFunc: () => ['?id crm:P53_has_former_or_current_location ?location'],
filterFunc: (val) => `?location = <${val}>`,
},
],
};
Loading

0 comments on commit 990c7c7

Please sign in to comment.