Skip to content

Add option to change URI link to faceted browser #3

@MathiasVDA

Description

@MathiasVDA

When URI's are URL's, they can be clicked on and a new page will open. However, sometimes they are not dereferencable and you will get a 404. So you want to open a faceted browser instead.

  • User should be able to configure a prefix link. The
  • Developer should be abel to configure the same, but also be able to add a specialised adapter function
  • Configuration in the table plugin
  • Persistent
  • Make sure all UI elements adapt colors depending on theme
  • Add tests
  • Add documentation, a user guide and a developer guide

For inspiration, sparnatural has a good implementation of the adapter function: https://docs.sparnatural.eu/YasGUI-plugins-integration.html#tablex-plugin

Adapting the URL of the link
Sometimes the URI of the entities is not directly dereferenceable and clicking on it would lead to a 404 error. For this reason, the TableX plugin can be customized with functions that can pre-process the result before it is being printed. The 2 functions are uriHrefAdapter and bindingSetAdapter.

The uriHrefAdapter function enables you to change an input URI to another output URL. It is configured like so:

Yasr.plugins.LabelledUriTable.defaults.uriHrefAdapter = function(uri) {
	console.log("adapter called on uri "+uri);
	// return anything you like that will used instead of the input uri
	return uri;
};

It is called for every URI in the result set, in every column. For example it can be used to modify input DBPedia URI to the corresponding Wikipedia article:

Yasr.plugins.LabelledUriTable.defaults.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;
	}
};

The bindingSetAdapter function enables you to process an entire binding set, that is an entire line in the result table, including literal values. It is configured like so :

Yasr.plugins.LabelledUriTable.defaults.bindingSetAdapter = function(bindingSet) {
	console.log("binding set adapter called on "+bindingSet);
	return bindingSet;
};

For example it can be used to generate a clickable link from a literal value in the binding set:


Yasr.plugins.LabelledUriTable.defaults.bindingSetAdapter = function(bindingSet) {
	var newBindingSet = {};
	for (var key in bindingSet) {
		// if we are on a column starting with "code"...
	    if(key.startsWith("code")) {
	    	// then insert a new value that is a URI based on the code literal value    
	        newBindingSet[key] = {
	            type: "uri",
	            value: "http://fake.uri/"+bindingSet[key].value
	        };
	        // and set the code as the "xxx_label" column so that it is picked up
	        // as a label to display
	        newBindingSet[key+"_label"] = bindingSet[key];
	    } else {
	        // default, don't change anything
	        newBindingSet[key] = bindingSet[key];
	    }
	}
	return newBindingSet;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions