I am using angular to bind the results of a SPARQL query.
It works nicely until I attempt to bind data returned from queries using the SPARQL "STRAFTER" or "REPLACE" functions (code below) which returns blank data in $scope. But the same query works fine if I run it directly from Fuseki control panel with output set to json.
I am using Fuseki Server 1-1.1.2 endpoint (SPARQL 1.1).
Here is the query that returns expected data in Fuseki server:
SELECT (strafter(str(?class),"#") AS ?className) (COUNT(?s) AS ?count )
{ ?s a ?class }
GROUP BY ?class ORDER BY DESC(?count)
Here is the HTML/angular code using the same query in a "$http.get" call with response to be bound in angular coming back as blank:
<div ng-app="myApp" ng-controller="queryCtrl"><table>
<tr ng-repeat="x in results">
<td>{{x.class.value}}</td>
<td>{{x.count.value}}</td>
</tr>
</table></div>
<script>
var app = angular.module('myApp', []);
app.controller('queryCtrl', function($scope, $http) {
var query = encodeURIComponent("SELECT (strafter(str(?class), "#") AS ? className) (COUNT(?s) AS ?count) {?s a ?class} GROUP BY ?class ORDER BY DESC(? count)");
var endpoint = "http://localhost:3030/dataset/query";
$scope.results = [];
$http.get("http://localhost:3030/dataset/query? query="+query+"&output=json")
.success(function (response) {
$scope.results = response.results.bindings;
/* for debugging*/
if ( window.console && window.console.log ) {
// console is available, write message if something has happened
console.log(response.results);
}
});
});
</script>
Any ideas why this is happening please?
Is this maybe a string quote problem as you
"
string is terminated by the"
in front of#
. So try: