Skip to content

Commit

Permalink
Merge branch 'feature/refactor-endpoint-services' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
leipert committed May 12, 2014
2 parents aad8a33 + 83f705f commit 21b7306
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 109 deletions.
11 changes: 11 additions & 0 deletions app/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,14 @@ div.subjectCSS div.inversePropertyCSS div.inversePropertyHeadCSS i {
color: #ffffff;
text-underline: none;
}

.ui-select-bootstrap > .ui-select-choices {
width:400px;
max-height: 600px;
}

.dropdown-menu {
width: 400px;
right:0;
left:auto;
}
9 changes: 7 additions & 2 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ <h1>Graphical SPARQL Builder</h1>
<!-- IMPORTANT: it has to be item in 'repeat="item in...',
as ui-select defines it internally. Anything else wont work! -->
<choices repeat="item in availableSubjectClasses | filter: $select.search | limitTo: 10">
<div ng-bind-html="item.alias | highlight: $select.search"></div>
<small ng-bind-html="item.uri | highlight: $select.search"></small>
<p>
<span class="h4" ng-bind-html="item.alias | highlight: $select.search"></span>
<small ng-bind-html="item.uri | highlight: $select.search"></small>
</p>
<p style="white-space:normal;">
<small ng-bind-html="item.comment | highlight: $select.search"></small>
</p>
</choices>
</ui-select>
<span class="input-group-btn">
Expand Down
38 changes: 25 additions & 13 deletions app/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ angular.module('GSB.config', [])
},
resultURL: 'http://dbpedia-live.openlinksw.com/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&format=text%2Fhtml&timeout=5000&debug=on&query=',
queryURL: 'http://dbpedia-live.openlinksw.com/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&format=json&timeout=5000&debug=on&query=',
baseURL: 'http://' + (location.host + location.pathname).substring(0,(location.host + location.pathname).lastIndexOf('app/') + 4),
allowedLanguages : ['*','de','en','pl'],
propertyOperators : [
{
Expand Down Expand Up @@ -72,28 +71,41 @@ angular.module('GSB.config', [])
}
],
getPropertiesSPARQLQuery:
'SELECT DISTINCT ?u ?i (STR(?ct) AS ?c) ?r (STR(?at) AS ?a)' +
'SELECT DISTINCT ?uri ?inverse (STR(?comment_temp) AS ?comment) ?range (STR(?alias_temp) AS ?alias)' +
'WHERE {' +
' {' +
' <%uri%> rdfs:subClassOf* ?class.' +
' {' +
' ?u rdfs:domain ?class . ' +
' BIND("D" as ?i)' +
' OPTIONAL { ?u rdfs:range ?r}' +
' ?uri rdfs:domain ?class . ' +
' BIND("D" as ?inverse)' +
' OPTIONAL { ?uri rdfs:range ?range}' +
' } UNION {' +
' ?u rdfs:range ?class .' +
' BIND("I" as ?i)' +
' OPTIONAL { ?u rdfs:domain ?r}' +
' ?uri rdfs:range ?class .' +
' BIND("I" as ?inverse)' +
' OPTIONAL { ?uri rdfs:domain ?range}' +
' }' +
' }' +
' OPTIONAL {' +
' ?u rdfs:comment ?ct .' +
' FILTER(LANGMATCHES(LANG(?ct), "%lang%"))' +
' ?uri rdfs:comment ?comment_temp .' +
' FILTER(LANGMATCHES(LANG(?comment_temp), "%lang%"))' +
' }' +
' OPTIONAL {' +
' ?u rdfs:label ?at .' +
' FILTER(LANGMATCHES(LANG(?at), "%lang%"))' +
' ?uri rdfs:label ?alias_temp .' +
' FILTER(LANGMATCHES(LANG(?alias_temp), "%lang%"))' +
' }' +
'}',
standardLang: "en"
standardLang: "en",
getClassesSPARQLQuery:
'SELECT DISTINCT ?uri (STR(?comment_temp) as ?comment) (STR(?alias_temp) AS ?alias)' +
'WHERE {' +
' ?uri a owl:Class .' +
' OPTIONAL {' +
' ?uri rdfs:comment ?comment_temp .' +
' FILTER(LANG(?comment_temp) = "" || LANGMATCHES(LANG(?comment_temp), "%lang%"))' +
' }' +
' OPTIONAL {' +
' ?uri rdfs:label ?alias_temp .' +
' FILTER(LANGMATCHES(LANG(?alias_temp), "%lang%"))' +
' }' +
'}'
});
6 changes: 3 additions & 3 deletions app/js/controllers/propertyCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

angular.module('GSB.controllers.propertyCollection', ['GSB.config', 'GSB.services.endPoint'])
//Inject $scope, $http, $log and globalConfig (see @js/config.js, @js/services/endPoint.js) into controller
.controller('PropertyCollectionCtrl', ['$scope', '$http', '$q', '$log', 'globalConfig', 'AvailablePropertiesService', function($scope, $http, $q, $log, globalConfig, AvailablePropertiesService) {
.controller('PropertyCollectionCtrl', ['$scope', '$http', '$q', '$log', 'globalConfig', 'EndPointService', function($scope, $http, $q, $log, globalConfig, EndPointService) {

var selectedProperties = $scope.subjectInst.selectedProperties;
AvailablePropertiesService.availableProperties = '';
AvailablePropertiesService.getProperties($scope.subjectInst.uri)
EndPointService.availableProperties = [];
EndPointService.getProperties($scope.subjectInst.uri)
.then(function(data) {
$scope.subjectInst.availableProperties = data;
}, function(error) {
Expand Down
14 changes: 7 additions & 7 deletions app/js/controllers/subjectCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ angular.module('GSB.controllers.subjectCollection', ['ngSanitize','ui.select','G
*/
var addSubject = function (uri, alias, comment) {
$log.info('Subject added');
alias = createUniqueAlias(alias, uri);
$scope.subjects.push(
{
alias: alias,
alias: createUniqueAlias(alias, uri),
label: alias,
uri: uri,
comment: comment,
Expand Down Expand Up @@ -83,11 +82,11 @@ angular.module('GSB.controllers.subjectCollection', ['ngSanitize','ui.select','G
if ($scope.subjects[key].alias === newAlias) {
aliasUnique = false;
newAlias = alias + "_" + c;
c += 1;
break;
}
aliasUnique = true;
}
c += 1;
}
} while (!aliasUnique);
return newAlias;
Expand Down Expand Up @@ -146,12 +145,13 @@ angular.module('GSB.controllers.subjectCollection', ['ngSanitize','ui.select','G

$scope.availableSubjectClasses = [];
$scope.subjects = [];
EndPointService.getAvailableClasses($scope.availableSubjectClasses)
.then(function() {
$log.info('Available classes loaded', $scope.availableSubjectClasses)
EndPointService.getAvailableClasses()
.then(function(data) {
$scope.availableSubjectClasses = data;
}, function(error) {
$log.error('Error loading Classes.')
$log.error(error);
});

addSubject('http://dbpedia.org/ontology/Person', "Person", "Ein Individuum der Spezies Mensch.");


Expand Down
156 changes: 72 additions & 84 deletions app/js/services/endPoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,89 +8,109 @@
*/

angular.module('GSB.services.endPoint', ['GSB.config'])
.factory('EndPointService', ['$http', '$log', 'globalConfig', function ($http, $log, globalConfig) {
.factory('EndPointService', ['$http', '$q', '$log', 'globalConfig', function ($http, $q, $log, globalConfig) {
var factory = {};

/**
* Writes available SPARQL-Classes into a given array.
*
* @param asc the array into which the endPoint will be written
*/
factory.getAvailableClasses = function (asc) {
factory.getAvailableClasses = function () {

// Get Available Subject Classes from Server

return $http.get(globalConfig.queryURL + encodeURIComponent('select ?class where {?class a owl:Class .}'))
return $http.get(
globalConfig.queryURL + encodeURIComponent(
globalConfig.getClassesSPARQLQuery.replace(/%lang%/g,globalConfig.standardLang)
)
)
.then(function (response) {

$log.info('Available Classes loaded from server.');
if(typeof response.data === 'object') {
$log.info(' Available Classes loaded from server');
return createAvailableClassesObject(response.data.results.bindings);
}else{
return $q.reject(response)
}

var availClasses = response.data.results.bindings;

for (var key in availClasses) {
if (availClasses.hasOwnProperty(key)) {
asc.push(
{
alias: availClasses[key].class.value.substr(availClasses[key].class.value.lastIndexOf('/') + 1, availClasses[key].class.value.length - (availClasses[key].class.value.lastIndexOf('/') + 1)),
uri: availClasses[key].class.value,
comment: availClasses[key].comment ? availClasses[key].comment.value : 'No description available.'
}
);
}
}, function (response) {
$log.error( 'Available Classes could not be loaded from server.');
return $q.reject(response)
});
};

factory.availableProperties = '';

var createAvailableClassesObject = function(availClasses){
var ret = [];
for (var key in availClasses) {
if (availClasses.hasOwnProperty(key)) {
var tClass = availClasses[key], alias,
comment = 'No description available.',
uri = tClass.uri.value;

if(tClass.hasOwnProperty("alias")){
alias = tClass.alias.value;
} else{
alias = uri.substr(uri.lastIndexOf('/') + 1)
}

//Adding special class 'Thing' to the array of available classes
asc.push(
if(tClass.hasOwnProperty("comment")){
comment = tClass.comment.value;
}

ret.push(
{
alias: 'Thing',
uri: 'test/Thing',
comment: 'The class Thing is an anonymous class for searching without knowing the subjects class.'
alias: alias ,
uri: uri,
comment: comment
}
);
}

}

}, function (error) {
$log.error(error, 'Available Classes could not be loaded from server.');
});
//Adding special class 'Thing' to the array of available classes
ret.push(
{
alias: 'Thing',
uri: 'test/Thing',
comment: 'The class Thing is an anonymous class for searching without knowing the subjects class.'
}
);
return ret;
};

return factory;

}])
.factory('AvailablePropertiesService', ['$http', '$log', 'globalConfig', function ($http, $log, globalConfig) {
var factory = {};

factory.availableProperties = '';

var createAvailablePropertyObject = function (data) {
var ret = {};
for (var key in data) {
if (data.hasOwnProperty(key)) {
var property = data[key],
propertyURI = property.u.value,
propertyURI = property.uri.value,
propertyRange,
propertyType = "STANDARD_PROPERTY",
propertyComment = "",
propertyAlias = "";

/* Check whether the propertyAlias is undefined and if so, fill it with last part of the URI.*/
if (property.hasOwnProperty("a")) {
propertyAlias = property.a.value;
if (property.hasOwnProperty("alias")) {
propertyAlias = property.alias.value;
} else {
propertyAlias = propertyURI.substr(propertyURI.lastIndexOf('/') + 1, propertyURI.length - (propertyURI.lastIndexOf('/') + 1));
propertyAlias = propertyURI.substr(propertyURI.lastIndexOf('/') + 1);
}

if (property.hasOwnProperty("c")) {
propertyComment = property.c.value;
if (property.hasOwnProperty("comment")) {
propertyComment = property.comment.value;
}

if (property.hasOwnProperty("r")) {
propertyRange = property.r.value;
if (property.hasOwnProperty("range")) {
propertyRange = property.range.value;
}

/* Check whether a propertyRange is given.*/
if (property.i.value === "I") {
if (property.inverse.value === "I") {
propertyType = "INVERSE_PROPERTY";
propertyAlias = "is " + propertyAlias + " of"
} else {
Expand All @@ -113,39 +133,21 @@ angular.module('GSB.services.endPoint', ['GSB.config'])
optional: false,
operator: null,
link: {direction: null, linkPartner: null},
arithmetic: "x", //Vorprojekt leave empty
compare: null //Vorprojekt leave empty
arithmetic: "x",
compare: null
};

}
}
}


return ret;
};


/**
* Returns the classes URIs.
*/
factory.createSpeciProps = function () {
$log.info('Start creating URI-list.');

//Retrieve Properties from Server and add them to availableProperties
return $http.get(globalConfig.queryURL + encodeURIComponent('select ?class where {?class a owl:Class .}'))
.then(function (response) {
var pro = createAvailableURIs(response.data.results.bindings);
$log.info('Done getting all classes.');

return pro;

}, function (response) {
$log.error('Error preparing URI-list')
});
return ret;
};


//TODO: get it to woek again.
var createAvailableURIs = function (data) {
var ret = {};

Expand Down Expand Up @@ -220,13 +222,16 @@ angular.module('GSB.services.endPoint', ['GSB.config'])
return $http.get(factory.buildAllPropertyQuery(uri))
.then(function (response) {

$log.info(' Properties loaded from: ' + uri, response);

//factory.availableProperties = factory.mergeTwoObjects(factory.createSpeciProps(), factory.availableProperties);
return createAvailablePropertyObject(response.data.results.bindings);

if(typeof response.data === 'object') {
$log.info(' Properties loaded from: ' + uri, response);
return createAvailablePropertyObject(response.data.results.bindings);
}else{
return $q.reject(response)
}
}, function (response) {
$log.error('Error loading properties from: ' + uri)
return $q.reject(response)

}
)
};
Expand All @@ -253,23 +258,6 @@ angular.module('GSB.services.endPoint', ['GSB.config'])
}
return query;
};

/**
* Helper function to merge two objects
*
* @param o1 the merged Object
*/
factory.mergeTwoObjects = function (o1, o2) {

for (var key in o2) {

o1[key] = o2[key];
}
return o1;


return o1;
};

return factory;

Expand Down

0 comments on commit 21b7306

Please sign in to comment.