sparql-faceter
v1.11.0
Published
Faceted search using AngularJS and SPARQL
Downloads
1
Readme
SPARQL Faceter
A paper describing SPARQL Faceter can be found here, although as of version 1.0.0 the implementation is quite different. Most importantly, rather than there being one SPARQL query to get the state of all the facets, each facet makes its own query.
Installation
Install via Bower:
bower install sparql-faceter
or
npm install sparql-faceter
Include seco.facetedSearch
in your module dependencies:
angular.module('myApp', ['seco.facetedSearch'])
Include the script in your HTML:
<script src="bower_components/sparql-faceter/dist/semantic-faceted-search.js></script>
And additionally the dependencies defined in bower.json before the above script.
You can also include the stylesheet in the header:
<link rel="stylesheet" href="bower_components/angular-semantic-faceted-search/dist/semantic-faceted-search.css">
Then you're good to go!
Configuration and Usage
See the documentation.
Setup in the controller:
var vm = this;
// Define facets
vm.facets = {
// Text facet
name: {
name: 'Name',
facetId: 'name',
predicate: '<http://www.w3.org/2004/02/skos/core#prefLabel>',
enabled: true
},
// Date facet
deathDate: {
name: 'Time of Death',
facetId: 'death',
startPredicate: '<http://ldf.fi/schema/narc-menehtyneet1939-45/kuolinaika>',
endPredicate: '<http://ldf.fi/schema/narc-menehtyneet1939-45/kuolinaika>',
min: '1939-10-01',
max: '1989-12-31',
enabled: true
},
// Basic facet
profession: {
name: 'Ammatti',
facetId: 'occupation',
predicate: '<http://ldf.fi/schema/narc-menehtyneet1939-45/ammatti>',
enabled: true
},
// Basic facet with property path
source: {
name: 'Source',
facetId: 'source',
predicate: '^<http://www.cidoc-crm.org/cidoc-crm/P70i_is_documented_in>/<http://purl.org/dc/elements/1.1/source>',
enabled: true
},
// Basic facet with labels in another service.
birthMunicipality: {
name: 'Birth Municipality',
services: ['<http://ldf.fi/pnr/sparql>'],
facetId: 'birthplace',
predicate: '<http://ldf.fi/schema/narc-menehtyneet1939-45/synnyinkunta>',
enabled: false
},
// Hierarchical facet
rank: {
name: 'Rank',
facetId: 'rank',
predicate: '<http://ldf.fi/schema/narc-menehtyneet1939-45/sotilasarvo>',
hierarchy: '<http://purl.org/dc/terms/isPartOf>',
enabled: true,
depth: 3
}
};
// Define common options
vm.options = {
scope: $scope,
endpointUrl: 'http://ldf.fi/warsa/sparql',
rdfClass: '<http://ldf.fi/schema/narc-menehtyneet1939-45/DeathRecord>',
constraint: '?id skos:prefLabel ?name .',
preferredLang : 'fi'
};
// Define a function that handles updates.
// 'dataService' is some service that fetches results based on the facet selections.
function updateResults(event, facetState) {
dataService.getResults(facetState.constraints).then(function(results) {
vm.results = results;
}
}
// Listen for the update event
$scope.$on('sf-facet-constraints', updateResults);
// Listen for initial state
var initListener = $scope.$on('sf-initial-constraints', function(event, state) {
updateResults(event, state);
// Only listen once for the init event
initListener();
});
// Initialize the facet handler:
vm.handler = new FacetHandler(vm.options);
Then, in the template:
<seco-text-facet
data-options="vm.facets.name">
</seco-text-facet>
<seco-timespan-facet
data-options="vm.facets.deathDate">
</seco-timespan-facet>
<seco-basic-facet
data-options="vm.facets.source">
</seco-basic-facet>
<seco-basic-facet
data-options="vm.facets.profession">
</seco-basic-facet>
<seco-basic-facet
data-options="vm.facets.birthMunicipality">
</seco-basic-facet>
<seco-basic-facet
data-options="vm.facets.principalAbode">
</seco-basic-facet>
<seco-hierarchy-facet
data-options="vm.facets.rank">
</seco-hierarchy-facet>
Examples
Simplistic demo using DBpedia (the code in the repository contains helpful comments)
The WarSampo casualties demo uses SPARQL Faceter.
You can also see the tool in action in the WarSampo photograph perspective.