Skip to content

Commit

Permalink
Merge branch 'feature/R3-3-String-Properties' into develop
Browse files Browse the repository at this point in the history
Conflicts:
	app/js/services/translatorToSPARQL.js
  • Loading branch information
leipert committed May 5, 2014
2 parents b0c7532 + 3374b9d commit 11ba619
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 20 deletions.
2 changes: 2 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,12 @@ <h3>Results</h3>
<script src="js/controllers/propertyInstance.js"></script>
<script src="js/controllers/propertyType/object.js"></script>
<script src="js/controllers/propertyType/number.js"></script>
<script src="js/controllers/propertyType/string.js"></script>
<script src="js/directives/subject.js"></script>
<script src="js/directives/property.js"></script>
<script src="js/directives/propertyType/object.js"></script>
<script src="js/directives/propertyType/number.js"></script>
<script src="js/directives/propertyType/string.js"></script>
<script src="js/directives/startPoint.js"></script>
</body>
</html>
2 changes: 2 additions & 0 deletions app/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ angular.module('GSB', [
'GSB.controllers.propertyInstance',
'GSB.controllers.propertyType.object',
'GSB.controllers.propertyType.number',
'GSB.controllers.propertyType.string',
'GSB.directives.subject',
'GSB.directives.property',
'GSB.directives.startPoint',
'GSB.directives.propertyType.object',
'GSB.directives.propertyType.number',
'GSB.directives.propertyType.string',
'GSB.services.availableClasses',
'GSB.services.translatorManager',
'GSB.services.translatorToJSON',
Expand Down
5 changes: 5 additions & 0 deletions app/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ angular.module('GSB.config', [])
'NUMBER_PROPERTY' : [
/http:\/\/www\.w3\.org\/2001\/XMLSchema#(integer|float|double)/,
'http://www.w3.org/2001/XMLSchema#decimal'
],
'STRING_PROPERTY' : [
'http://www.w3.org/2001/XMLSchema#string',
'http://www.w3.org/2001/XMLSchema#literal'
]
},
queryURL: 'http://dbpedia.org/sparql?format=text%2Fhtml&timeout=5000&debug=on&query=',
testURLstart: 'http://dbpedia-live.openlinksw.com/sparql/?default-graph-uri=http%3A%2F%2Fdbpedia.org&format=json&timeout=30000&debug=on&query=',
testURLend: '',
baseURL: 'http://' + (location.host + location.pathname).substring(0,(location.host + location.pathname).lastIndexOf('app/') + 4),
allowedLanguages : ['*','de','en','pl'],
propertyOperators : [
{
label: 'must',
Expand Down
86 changes: 86 additions & 0 deletions app/js/controllers/propertyType/string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
'use strict';

/**
* PropertyInstanceCtrl
* Controller for a single property.
*/

angular.module('GSB.controllers.propertyType.string', ['GSB.config'])
//Inject $scope, $http, $log and globalConfig (see @ js/config.js) into controller
.controller('StringPropertyCtrl', ['$scope', '$http', '$log', 'globalConfig', function($scope, $http, $log, globalConfig) {

$scope.allowedStringComparisons = [
{
label: "contains",
f : 'regex(%after_arithmetic%, "%input%", "i")'
},
{
label: "equals",
f : '%after_arithmetic%^^xsd:string="%input%"^^xsd:string'
},
{
label: "equals not",
f : '%after_arithmetic%^^xsd:string!="%input%"^^xsd:string'
},
{
label: "starts with",
f : 'regex(%after_arithmetic%, "^%input%", "i")'
},
{
label: "ends with",
f : 'regex(%after_arithmetic%, "%input%$", "i")'
},
{
label: "REGEX",
f : 'regex(%after_arithmetic%, "%input%", "%flags%")'
}
];

$scope.allowedLanguages = globalConfig['allowedLanguages'];

$scope.stringComparison = null;

$scope.$watch('stringComparison',function (newValue){
renderComparison(newValue.f,$scope.comparisonInput,$scope.comparisonRegexFlags);
});

$scope.comparisonInput = "";

$scope.$watch('comparisonInput',function (newValue){
renderComparison($scope.stringComparison.f,newValue,$scope.comparisonRegexFlags)
});

$scope.comparisonRegexFlags = "";

$scope.$watch('comparisonRegexFlags',function (newValue){
renderComparison($scope.stringComparison.f,$scope.comparisonInput,newValue)
});

function renderComparison(f,input,flags)
{
if(input === null || input=== undefined || input === '' ||f === undefined || f === null){
$scope.compare = null
renderLangCompare();
return;
}
$scope.compare = f.replace(/%input%/,input).replace(/%flags%/,flags);
renderLangCompare();
}

$scope.selectedLanguage = null;

$scope.$watch('selectedLanguage',function (newValue){
renderLangCompare();
});

function renderLangCompare(){
if($scope.selectedLanguage === null || $scope.selectedLanguage === undefined ||$scope.selectedLanguage === ''){
$scope.propertyInst.compare = $scope.compare;
} else if($scope.compare===null){
$scope.propertyInst.compare = 'langMatches(lang(%after_arithmetic%), "'+$scope.selectedLanguage+'")'
} else {
$scope.propertyInst.compare = 'langMatches(lang(%after_arithmetic%), "' + $scope.selectedLanguage + '") && ' + $scope.compare;
}
}

}]);
17 changes: 17 additions & 0 deletions app/js/directives/propertyType/string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

/**
* Property directive
* Creates the possibility to use a <property> element,
* which will be replaced with the contents of template/property.html
*/

angular.module('GSB.directives.propertyType.string', [])
.directive('stringPropertyDir', function () {
return {
restrict: "A",
replace: true,
controller: 'StringPropertyCtrl',
templateUrl: 'template/propertyType/string.html'
}
});
77 changes: 57 additions & 20 deletions app/js/services/translatorToSPARQL.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,40 @@ angular.module('GSB.services.translatorToSPARQL', ['GSB.config'])
}
}

return factory.translateStartpoint(json, shownValues) + "\nwhere {\n" + SPARQL + "\n}";
};


return factory.translateStartpoint(json, shownValues) + "\nwhere {\n" + SPARQL + "\n} LIMIT 200";
};






/**
* Function to translate the header of a SPARQL query, including the shown values
* @param json
* @param shownValues
*/
factory.translateStartpoint = function (json, shownValues) {

var SPARQLStart = "";

if(json.START.type === "LIST_ALL") {
SPARQLStart = "SELECT DISTINCT ";
}
else {
SPARQLStart = "SELECT ";
}

for(var i = 0; i < shownValues.length; i++) {
SPARQLStart += "?" + shownValues[i] + " ";
}

return SPARQLStart;
};




/**
* Function to translate the header of a SPARQL query, including the shown values
* @param json
Expand All @@ -68,7 +98,7 @@ angular.module('GSB.services.translatorToSPARQL', ['GSB.config'])

var spePro = false;
//Search for specialProperty in the JSON
for(var i = 0; i < json.SUBJECTS.length; i++){
for(i = 0; i < json.SUBJECTS.length; i++){

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

for(var i = 0; i < json.SUBJECTS.length; i++) {
for(i = 0; i < json.SUBJECTS.length; i++) {
if(json.SUBJECTS[i].alias === eigenschaft.link.linkPartner) {
SPARQL += factory.translateSubject(json.SUBJECTS[i], shownValues, translated, json);
}
}
} else {
SPARQL += eigenschaft.alias + " .\n"; ;
SPARQL += eigenschaft.alias + " .\n";
if(eigenschaft.optional) {
SPARQL += "}\n";
}
Expand All @@ -160,7 +190,7 @@ angular.module('GSB.services.translatorToSPARQL', ['GSB.config'])

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

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

if(eigenschaft.optional) {
if (eigenschaft.optional) {
SPARQL += "OPTIONAL { \n";
}

if(eigenschaft.arithmetic !== null && eigenschaft.arithmetic != "x") {
if (eigenschaft.arithmetic !== null && eigenschaft.arithmetic != "x") {
x = y + "_temp";
SPARQL += "?" + itsSubject.alias + " <" + eigenschaft.uri + "> " + x + ".\n";
SPARQL += "BIND ((" + eigenschaft.arithmetic.replace(/x/g,x) + ") as " + y + ") .\n";
SPARQL += "BIND ((" + eigenschaft.arithmetic.replace(/x/g, x) + ") as " + y + ") .\n";
}
else {

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

}

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

SPARQL += "?" + itsSubject.alias + " " + tailoredURI + " " + y + " .\n";
SPARQL += "?" + itsSubject.alias + " " + tailoredURI + " " + y + " .\n";
}

if (eigenschaft.compare !== null) {

SPARQL += "FILTER ( "
+ eigenschaft.compare
.replace(/%before_arithmetic%/g, x)
.replace(/%after_arithmetic%/g, y)
+ " ) .\n";

if(eigenschaft.compare !== null) {

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

if(eigenschaft.optional) {
if (eigenschaft.optional) {
SPARQL += "}\n";
}

}


Expand Down
3 changes: 3 additions & 0 deletions app/template/property.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
<div ng-switch-when="NUMBER_PROPERTY">
<div number-property-dir></div>
</div>
<div ng-switch-when="STRING_PROPERTY">
<div string-property-dir></div>
</div>

<div ng-switch-default></div>
</div>
Expand Down
15 changes: 15 additions & 0 deletions app/template/propertyType/string.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div >
<!-- if a property is selected, it will be linked with the subject -->
<select ng-model="selectedLanguage"
ng-options="x as x for x in allowedLanguages"
title="Select">
<option value="">LANG</option>
</select>
<select ng-model="stringComparison"
ng-options="x as x.label for x in allowedStringComparisons"
title="Compare this string">
<option value="">exists</option>
</select>
<input ng-show="stringComparison" ng-model="comparisonInput">
<input ng-show="stringComparison && stringComparison.label === 'REGEX'" ng-model="comparisonRegexFlags">
</div>

0 comments on commit 11ba619

Please sign in to comment.