Set of Plugins for Yasgui / YASR useful in conjunction with Sparnatural
For integration with Sparnatural, there is a dedicated documentation page
This is an adaptation of the original YaSR Table plugin. Its main enhancement is that it can hide URI columns "behind" a correspondig label column, thus hiding technical URIs for end-users. The link URLs can also be customzed to navigate to another URL than the original URI.
For every column ?xxx_label
, the plugin will look for a column ?xxx
having a literal property (for example ?Person_1
and ?Person_1_label
), and merge these columns. The merge is done on the SPARQL result set itself, by creating a new kind of result x-labelled-uri
containing both the URI and its label. Only the ?xxx
column will be shown.
Instead of this:
You would get this:
The Grid plugin works only in conjunction with Sparnatural, not for any SPARQL query. It needs to be notified of the Sparnatural original query, and the Sparnatural original configuration.
The Grid plugin:
.png
or .jpg
)Here is how it looks like with an image column selected:
The original query was the following: (All chairmans of EU political groups, with dates of chair and image, based on the European Parliament Open Data Portal datasets)
The original result set was the following - note how each person is duplicated as many times as it was a chairman of a group, with different dates:
Here is a focus on one card, note how the lines corresponding to the same entity have been merged, and how the original query structure is replicated inside the card:
The Stats plugin can:
COUNT
+ GROUP BY
queryThe map plugin:
geo:wktLiteral
Here is an exampe:
TODO
<script type="text/javascript" src="https://github.com/sparna-git/Sparnatural-yasgui-plugins/raw/main/sparnatural-yasgui-plugins.js"></script>
Yasr.registerPlugin("TableX",SparnaturalYasguiPlugins.TableX);
Yasr.registerPlugin("Grid",SparnaturalYasguiPlugins.GridPlugin);
Yasr.registerPlugin("Stats",SparnaturalYasguiPlugins.StatsPlugin);
Yasr.registerPlugin("Map",SparnaturalYasguiPlugins.MapPlugin);
delete Yasr.plugins['table'];
delete Yasr.plugins['response'];
const yasr = new Yasr(document.getElementById("yasr"), {
pluginOrder: ["TableX", "Grid", "Stats", "Map"],
defaultPlugin: "TableX",
// disable persistency
persistencyExpire: 0,
maxPersistentResponseSize: 0
});
if(lang == "fr") {
yasr.plugins["Grid"].config.lang = "fr";
yasr.plugins["Stats"].config.lang = "fr";
} else {
yasr.plugins["Grid"].config.lang = "en";
yasr.plugins["Stats"].config.lang = "en";
}
yasr.plugins["TableX"].config.uriHrefAdapter = function(uri) {
if(uri.startsWith("http://fr.dbpedia.org/resource/")) {
return "http://fr.wikipedia.org/wiki/" + uri.substring("http://fr.dbpedia.org/resource/".length);
} else {
return uri;
}
};
// binds Sparnatural with the YasR plugins
bindSparnaturalWithYasrPlugins(sparnatural, yasr);
These plugins require a specific integration with Sparnatural to work. See the Sparnatural documentation page. See the file sparnatural-bindings.js
in Sparnatural releases.
These plugins have the following methods:
notifyQuery(query)
: expects the Sparnatural query structure, to be notified of the original query structure that was executed.notifyConfig(specProvider)
: expects the Sparnatural configuration, to be aware of the labels and icons of the properties and classes in the config.export interface PluginConfig {
openIriInNewWindow: boolean;
tableConfig: DataTables.Settings;
includeControls: boolean;
uriHrefAdapter?: (uri: string) => string;
bindingSetAdapter?: (binding: Parser.Binding) => Parser.Binding;
}
interface PluginConfig {
lang: "en" | "fr";
}
interface PluginConfig {
lang: "en" | "fr";
}
interface PluginConfig {
baseLayers: Array<{
urlTemplate: string,
options?: L.TileLayerOptions
}>
polylineOptions: L.PolylineOptions | null,
markerOptions: L.MarkerOptions | null,
geoDataType: Array<string>,
polygonDefaultColor: string,
polygonColors: Array<string>,
searchedPolygon: {
fillColor: string,
weight: number,
opacity: number,
color: string,
dashArray: string,
fillOpacity: number
},
mapSize: {
width:string,
height:string
}
setView: {
center: L.LatLngExpression,
zoom?: number,
options?: L.ZoomPanOptions
}
parsingFunction: (literalValue:string)=> Geometry,
L18n: {
warnFindNoCoordinate: string, // use "<count>" pattern to replace with count of results with no geo coordinates
warnFindNoCoordinateBtn: string // Link label for plugin table display on warnig message
}
}
npm install
npm run start