Skip to content

Commit 11ba619

Browse files
committed
Merge branch 'feature/R3-3-String-Properties' into develop
Conflicts: app/js/services/translatorToSPARQL.js
2 parents b0c7532 + 3374b9d commit 11ba619

File tree

8 files changed

+187
-20
lines changed

8 files changed

+187
-20
lines changed

app/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,12 @@ <h3>Results</h3>
126126
<script src="js/controllers/propertyInstance.js"></script>
127127
<script src="js/controllers/propertyType/object.js"></script>
128128
<script src="js/controllers/propertyType/number.js"></script>
129+
<script src="js/controllers/propertyType/string.js"></script>
129130
<script src="js/directives/subject.js"></script>
130131
<script src="js/directives/property.js"></script>
131132
<script src="js/directives/propertyType/object.js"></script>
132133
<script src="js/directives/propertyType/number.js"></script>
134+
<script src="js/directives/propertyType/string.js"></script>
133135
<script src="js/directives/startPoint.js"></script>
134136
</body>
135137
</html>

app/js/app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ angular.module('GSB', [
1111
'GSB.controllers.propertyInstance',
1212
'GSB.controllers.propertyType.object',
1313
'GSB.controllers.propertyType.number',
14+
'GSB.controllers.propertyType.string',
1415
'GSB.directives.subject',
1516
'GSB.directives.property',
1617
'GSB.directives.startPoint',
1718
'GSB.directives.propertyType.object',
1819
'GSB.directives.propertyType.number',
20+
'GSB.directives.propertyType.string',
1921
'GSB.services.availableClasses',
2022
'GSB.services.translatorManager',
2123
'GSB.services.translatorToJSON',

app/js/config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ angular.module('GSB.config', [])
99
'NUMBER_PROPERTY' : [
1010
/http:\/\/www\.w3\.org\/2001\/XMLSchema#(integer|float|double)/,
1111
'http://www.w3.org/2001/XMLSchema#decimal'
12+
],
13+
'STRING_PROPERTY' : [
14+
'http://www.w3.org/2001/XMLSchema#string',
15+
'http://www.w3.org/2001/XMLSchema#literal'
1216
]
1317
},
1418
queryURL: 'http://dbpedia.org/sparql?format=text%2Fhtml&timeout=5000&debug=on&query=',
1519
testURLstart: 'http://dbpedia-live.openlinksw.com/sparql/?default-graph-uri=http%3A%2F%2Fdbpedia.org&format=json&timeout=30000&debug=on&query=',
1620
testURLend: '',
1721
baseURL: 'http://' + (location.host + location.pathname).substring(0,(location.host + location.pathname).lastIndexOf('app/') + 4),
22+
allowedLanguages : ['*','de','en','pl'],
1823
propertyOperators : [
1924
{
2025
label: 'must',
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
'use strict';
2+
3+
/**
4+
* PropertyInstanceCtrl
5+
* Controller for a single property.
6+
*/
7+
8+
angular.module('GSB.controllers.propertyType.string', ['GSB.config'])
9+
//Inject $scope, $http, $log and globalConfig (see @ js/config.js) into controller
10+
.controller('StringPropertyCtrl', ['$scope', '$http', '$log', 'globalConfig', function($scope, $http, $log, globalConfig) {
11+
12+
$scope.allowedStringComparisons = [
13+
{
14+
label: "contains",
15+
f : 'regex(%after_arithmetic%, "%input%", "i")'
16+
},
17+
{
18+
label: "equals",
19+
f : '%after_arithmetic%^^xsd:string="%input%"^^xsd:string'
20+
},
21+
{
22+
label: "equals not",
23+
f : '%after_arithmetic%^^xsd:string!="%input%"^^xsd:string'
24+
},
25+
{
26+
label: "starts with",
27+
f : 'regex(%after_arithmetic%, "^%input%", "i")'
28+
},
29+
{
30+
label: "ends with",
31+
f : 'regex(%after_arithmetic%, "%input%$", "i")'
32+
},
33+
{
34+
label: "REGEX",
35+
f : 'regex(%after_arithmetic%, "%input%", "%flags%")'
36+
}
37+
];
38+
39+
$scope.allowedLanguages = globalConfig['allowedLanguages'];
40+
41+
$scope.stringComparison = null;
42+
43+
$scope.$watch('stringComparison',function (newValue){
44+
renderComparison(newValue.f,$scope.comparisonInput,$scope.comparisonRegexFlags);
45+
});
46+
47+
$scope.comparisonInput = "";
48+
49+
$scope.$watch('comparisonInput',function (newValue){
50+
renderComparison($scope.stringComparison.f,newValue,$scope.comparisonRegexFlags)
51+
});
52+
53+
$scope.comparisonRegexFlags = "";
54+
55+
$scope.$watch('comparisonRegexFlags',function (newValue){
56+
renderComparison($scope.stringComparison.f,$scope.comparisonInput,newValue)
57+
});
58+
59+
function renderComparison(f,input,flags)
60+
{
61+
if(input === null || input=== undefined || input === '' ||f === undefined || f === null){
62+
$scope.compare = null
63+
renderLangCompare();
64+
return;
65+
}
66+
$scope.compare = f.replace(/%input%/,input).replace(/%flags%/,flags);
67+
renderLangCompare();
68+
}
69+
70+
$scope.selectedLanguage = null;
71+
72+
$scope.$watch('selectedLanguage',function (newValue){
73+
renderLangCompare();
74+
});
75+
76+
function renderLangCompare(){
77+
if($scope.selectedLanguage === null || $scope.selectedLanguage === undefined ||$scope.selectedLanguage === ''){
78+
$scope.propertyInst.compare = $scope.compare;
79+
} else if($scope.compare===null){
80+
$scope.propertyInst.compare = 'langMatches(lang(%after_arithmetic%), "'+$scope.selectedLanguage+'")'
81+
} else {
82+
$scope.propertyInst.compare = 'langMatches(lang(%after_arithmetic%), "' + $scope.selectedLanguage + '") && ' + $scope.compare;
83+
}
84+
}
85+
86+
}]);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
/**
4+
* Property directive
5+
* Creates the possibility to use a <property> element,
6+
* which will be replaced with the contents of template/property.html
7+
*/
8+
9+
angular.module('GSB.directives.propertyType.string', [])
10+
.directive('stringPropertyDir', function () {
11+
return {
12+
restrict: "A",
13+
replace: true,
14+
controller: 'StringPropertyCtrl',
15+
templateUrl: 'template/propertyType/string.html'
16+
}
17+
});

app/js/services/translatorToSPARQL.js

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,40 @@ angular.module('GSB.services.translatorToSPARQL', ['GSB.config'])
4343
}
4444
}
4545

46-
return factory.translateStartpoint(json, shownValues) + "\nwhere {\n" + SPARQL + "\n}";
47-
};
48-
49-
46+
return factory.translateStartpoint(json, shownValues) + "\nwhere {\n" + SPARQL + "\n} LIMIT 200";
47+
};
48+
49+
50+
51+
52+
53+
54+
/**
55+
* Function to translate the header of a SPARQL query, including the shown values
56+
* @param json
57+
* @param shownValues
58+
*/
59+
factory.translateStartpoint = function (json, shownValues) {
60+
61+
var SPARQLStart = "";
62+
63+
if(json.START.type === "LIST_ALL") {
64+
SPARQLStart = "SELECT DISTINCT ";
65+
}
66+
else {
67+
SPARQLStart = "SELECT ";
68+
}
69+
70+
for(var i = 0; i < shownValues.length; i++) {
71+
SPARQLStart += "?" + shownValues[i] + " ";
72+
}
73+
74+
return SPARQLStart;
75+
};
76+
77+
78+
79+
5080
/**
5181
* Function to translate the header of a SPARQL query, including the shown values
5282
* @param json
@@ -68,7 +98,7 @@ angular.module('GSB.services.translatorToSPARQL', ['GSB.config'])
6898

6999
var spePro = false;
70100
//Search for specialProperty in the JSON
71-
for(var i = 0; i < json.SUBJECTS.length; i++){
101+
for(i = 0; i < json.SUBJECTS.length; i++){
72102

73103
for(var j = 0; j < json.SUBJECTS[i].properties.length; j++){
74104
if(json.SUBJECTS[i].properties[j].uri == 'test/specialObjectProperty' || json.SUBJECTS[i].properties[j].uri == 'test/specialDatatypeProperty') {spePro = true;}
@@ -144,13 +174,13 @@ angular.module('GSB.services.translatorToSPARQL', ['GSB.config'])
144174
if(typeof eigenschaft.link.linkPartner != "undefined") {
145175
SPARQL += eigenschaft.link.linkPartner + " .\n";
146176

147-
for(var i = 0; i < json.SUBJECTS.length; i++) {
177+
for(i = 0; i < json.SUBJECTS.length; i++) {
148178
if(json.SUBJECTS[i].alias === eigenschaft.link.linkPartner) {
149179
SPARQL += factory.translateSubject(json.SUBJECTS[i], shownValues, translated, json);
150180
}
151181
}
152182
} else {
153-
SPARQL += eigenschaft.alias + " .\n"; ;
183+
SPARQL += eigenschaft.alias + " .\n";
154184
if(eigenschaft.optional) {
155185
SPARQL += "}\n";
156186
}
@@ -160,7 +190,7 @@ angular.module('GSB.services.translatorToSPARQL', ['GSB.config'])
160190

161191
if(eigenschaft.operator === "MUST_NOT") {
162192
if(typeof eigenschaft.link.linkPartner != "undefined") {
163-
for(var i = 0; i < json.SUBJECTS.length; i++) {
193+
for(i = 0; i < json.SUBJECTS.length; i++) {
164194
if(json.SUBJECTS[i].alias === eigenschaft.link.linkPartner) {
165195
SPARQL += factory.translateSubject(json.SUBJECTS[i], shownValues, translated, json);
166196
}
@@ -174,7 +204,7 @@ angular.module('GSB.services.translatorToSPARQL', ['GSB.config'])
174204

175205
if(eigenschaft.operator === "IS_OF") {
176206
SPARQL += "?" + itsSubject.alias + " ^<" + eigenschaft.uri + "> ?" + eigenschaft.link.linkPartner + " .\n";
177-
for(var i = 0; i < json.SUBJECTS.length; i++) {
207+
for(i = 0; i < json.SUBJECTS.length; i++) {
178208
if(json.SUBJECTS[i].alias === eigenschaft.link.linkPartner) {
179209
SPARQL += factory.translateSubject(json.SUBJECTS[i], shownValues, translated, json);
180210
}
@@ -214,44 +244,51 @@ angular.module('GSB.services.translatorToSPARQL', ['GSB.config'])
214244
y = x;
215245
if(eigenschaft.operator === "MUST") {
216246

217-
if(eigenschaft.optional) {
247+
if (eigenschaft.optional) {
218248
SPARQL += "OPTIONAL { \n";
219249
}
220250

221-
if(eigenschaft.arithmetic !== null && eigenschaft.arithmetic != "x") {
251+
if (eigenschaft.arithmetic !== null && eigenschaft.arithmetic != "x") {
222252
x = y + "_temp";
223253
SPARQL += "?" + itsSubject.alias + " <" + eigenschaft.uri + "> " + x + ".\n";
224-
SPARQL += "BIND ((" + eigenschaft.arithmetic.replace(/x/g,x) + ") as " + y + ") .\n";
254+
SPARQL += "BIND ((" + eigenschaft.arithmetic.replace(/x/g, x) + ") as " + y + ") .\n";
225255
}
226256
else {
227257

228258
//Tailors the uri if the subject is thing.
229259
// Necessary because Properties have URIs like: <http://dbpedia.org/ontology/Person/weight> but <http://dbpedia.org/ontology/weight> is needed
230260
var tailoredURI = eigenschaft.uri;
231-
if(itsSubject.uri == 'test/Thing' && eigenschaft.uri!=='test/specialDatatypeProperty')
232-
{
233-
var prop = tailoredURI.substr(tailoredURI.lastIndexOf('/'), tailoredURI.length-1)
261+
if (itsSubject.uri == 'test/Thing' && eigenschaft.uri !== 'test/specialDatatypeProperty') {
262+
var prop = tailoredURI.substr(tailoredURI.lastIndexOf('/'), tailoredURI.length - 1);
234263
tailoredURI = tailoredURI.substr(0, tailoredURI.lastIndexOf('/'));
235264
tailoredURI = tailoredURI.substr(0, tailoredURI.lastIndexOf('/')) + prop;
236265

237266
}
238267

239268
//Special-property has to be translated with ?alias instead of it's URI
240269
tailoredURI = '<' + tailoredURI + '>';
241-
if(eigenschaft.uri == 'test/specialDatatypeProperty') {tailoredURI = '?' + eigenschaft.alias;}
270+
if (eigenschaft.uri == 'test/specialDatatypeProperty') {
271+
tailoredURI = '?' + eigenschaft.alias;
272+
}
242273

243-
SPARQL += "?" + itsSubject.alias + " " + tailoredURI + " " + y + " .\n";
274+
SPARQL += "?" + itsSubject.alias + " " + tailoredURI + " " + y + " .\n";
244275
}
245276

277+
if (eigenschaft.compare !== null) {
278+
279+
SPARQL += "FILTER ( "
280+
+ eigenschaft.compare
281+
.replace(/%before_arithmetic%/g, x)
282+
.replace(/%after_arithmetic%/g, y)
283+
+ " ) .\n";
246284

247-
if(eigenschaft.compare !== null) {
248285

249-
SPARQL += "FILTER ( " + eigenschaft.compare.replace(/x/g,x).replace(/y/g,y) + " ) .\n";
250286
}
251287

252-
if(eigenschaft.optional) {
288+
if (eigenschaft.optional) {
253289
SPARQL += "}\n";
254290
}
291+
255292
}
256293

257294

app/template/property.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
<div ng-switch-when="NUMBER_PROPERTY">
6969
<div number-property-dir></div>
7070
</div>
71+
<div ng-switch-when="STRING_PROPERTY">
72+
<div string-property-dir></div>
73+
</div>
7174

7275
<div ng-switch-default></div>
7376
</div>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<div >
2+
<!-- if a property is selected, it will be linked with the subject -->
3+
<select ng-model="selectedLanguage"
4+
ng-options="x as x for x in allowedLanguages"
5+
title="Select">
6+
<option value="">LANG</option>
7+
</select>
8+
<select ng-model="stringComparison"
9+
ng-options="x as x.label for x in allowedStringComparisons"
10+
title="Compare this string">
11+
<option value="">exists</option>
12+
</select>
13+
<input ng-show="stringComparison" ng-model="comparisonInput">
14+
<input ng-show="stringComparison && stringComparison.label === 'REGEX'" ng-model="comparisonRegexFlags">
15+
</div>

0 commit comments

Comments
 (0)