This page tests the SPARQL utility functions found in sparqlLangUtil.js. The default language preferences for this page are the following:
Recall that we let a language with no extension match the first language found with the same base. (i.e. <English-us does not match English-uk>, but <English matches English-uk> and <English matches English-us>) The "empty-extension rule" only applies to the preferences list - not the data. That is, vanilla English in the preferences will match any English in the data, but vanilla English in the data will only be matched by vanilla English in the preferences.
We can get the set of laguage tags that are found on triples matching a
specified pattern.
getLangs(':s3',
'rdfs:label',
'http://localhost:2030/sparql/read',
function(){ alert('failure function') },
function(json){
var returnString = '';
for ( var i=0; i<json.results.bindings.length; i++ ){
returnString += json.results.bindings[i].lang.value + ', ';
}
returnString = returnString.substring(0, returnString.length - 1);
});
This function filters out bad triples, leaving the programmer with the best triple as specified in the language preferences. The programmer specifies a subject and a predicate and is returned the object of the best matching triple.
query_BestLanguageMatch(':s3',
'rdfs:label',
'http://localhost:2030/sparql/read',
function(){ alert('failure function') },
function(json){
if ( json.length == 0 ) { alert('No available langauges match your
preferences'); }
else{
alert( json.results.bindings[0].aa.value );
}