You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2011/12/15 12:13:32 UTC
svn commit: r1214701 [2/2] - in /incubator/stanbol/trunk:
commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/impl/
entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/query/
entityhub/generic/servicesapi/src/m...
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource/inc_ldpath.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource/inc_ldpath.ftl?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource/inc_ldpath.ftl (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource/inc_ldpath.ftl Thu Dec 15 11:13:30 2011
@@ -61,18 +61,25 @@
<p>Execute the LDPath on the Context:<br>
<form name="ldpathExample" id="ldpathExample">
- <input type="text" size="150" name="context">
- <textarea class="input" name="ldpath" rows="10">@prefix dct : <http://purl.org/dc/terms/subject/> ;
+ <strong>Context:</strong> <input type="text" size="120" name="context" value="http://dbpedia.org/resource/Paris">
+ <strong>LD-Path:</strong><br>
+ <textarea class="input" name="ldpath" rows="10">@prefix dct : <http://purl.org/dc/terms/> ;
@prefix geo : <http://www.w3.org/2003/01/geo/wgs84_pos#> ;
name = rdfs:label[@en] :: xsd:string;
labels = rdfs:label :: xsd:string;
comment = rdfs:comment[@en] :: xsd:string;
categories = dct:subject :: xsd:anyURI;
homepage = foaf:homepage :: xsd:anyURI;
-location = fn:concat("[",geo:lat,",",geo:long,"]") :: xsd:string;</textarea>
+location = fn:concat("[",geo:lat,",",geo:long,"]") :: xsd:string;</textarea><br>
+<strong>Format:</strong> <select name="format" id="findOutputFormat">
+ <option value="application/json">JSON-LD</option>
+ <option value="application/rdf+xml">RDF/XML</option>
+ <option value="application/rdf+json">RDF/JSON</option>
+ <option value="text/turtle">Turtle</option>
+ <option value="text/rdf+nt">N-TRIPLES</option>
+ </select> (Accept header set to the request)<p>
<input type="submit" value="Execute" onclick="executeLDPath(); return false;" /></p>
</form>
-</p>
<script language="javascript">
function executeLDPath() {
@@ -82,6 +89,9 @@ function executeLDPath() {
$.ajax({
type: 'POST',
url: "${it.publicBaseUri}entityhub/ldpath" ,
+ beforeSend: function(req) {
+ req.setRequestHeader("Accept", $("#findOutputFormat").val());
+ },
data: $("#ldpathExample").serialize(),
dataType: "text",
cache: false,
@@ -96,6 +106,6 @@ function executeLDPath() {
</script>
<div id="ldpathExampleResult" style="display: none">
-<p><a href="#" onclick="$('#findSymbolResult').hide(); return false;">Hide results</a>
+<p><a href="#" onclick="$('#ldpathExampleResult').hide(); return false;">Hide results</a>
<pre id="ldpathExampleResultText">... waiting for results ...</pre>
</div>
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/find.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/find.ftl?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/find.ftl (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/find.ftl Thu Dec 15 11:13:30 2011
@@ -19,6 +19,7 @@
<@common.page>
<#include "inc_find.ftl">
+<#include "/imports/ldpathdocumentation.ftl">
</...@common.page>
</#escape>
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_find.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_find.ftl?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_find.ftl (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_find.ftl Thu Dec 15 11:13:30 2011
@@ -39,6 +39,8 @@
<li>field: the name of the field used for the query. One MUST parse the full
name. Namespace prefixes are not supported yet. (default is rdfs:label)</li>
<li>lang: optionally the language of the parsed name can be defined</li>
+ <li>ldpath: optionally LDPath programs can be used to specify what
+ information to return for Entities selected by the /find request</li>
<li>limit: optionally the maximum number of results</li>
<li>offset: optionally the offset of first result</li>
</ul>
@@ -57,9 +59,52 @@
<h4>Test</h4>
-<form>
-<p>Start test search for
-<input type="text" id="testSearchValue" value="Paderb*" />
+<form name="findForm" id="findForm">
+<p>Find entities with <br>
+<table><tr>
+ <td><strong>Name:</strong></td>
+ <td><input type="text" name="name" size="40" value="Paderb*"/> (required)<br>
+ This supports Wildcards such as 'Exam?le*'</td>
+ </tr><tr>
+ <td><strong>Language:</strong></td>
+ <td><input type="text" name="lang" size="10" value="en" />
+ (optional, default: any)</td>
+ </tr><tr>
+ <td><strong>Field:</strong> </td>
+ <td><input type="text" name="field" size="60" />
+ (optional, reasonable default - usually rdfs:label)</td>
+ </tr><tr>
+ <td><strong>Limit:</string></td>
+ <td> <input type="text" name="limit" size="6" maxlength="6" value="10" />
+ (optional, number, default: 10) The maximum number of results</td>
+ </tr><tr>
+ <td><strong>Offset:</strong> </td>
+ <td><input type="text" name="offset" size="6" maxlength="6" value="0" />
+ (optional, number, default: 0) The offset of the first returned result</td>
+ </tr><tr>
+ <td><strong>LDPath:</strong>
+ </td><td><textarea class="input" name="ldpath" rows="10">@prefix dct : <http://purl.org/dc/terms/> ;
+@prefix geo : <http://www.w3.org/2003/01/geo/wgs84_pos#> ;
+name = rdfs:label[@en] :: xsd:string;
+comment = rdfs:comment[@en] :: xsd:string;
+categories = dct:subject :: xsd:anyURI;
+homepage = foaf:homepage :: xsd:anyURI;
+location = fn:concat("[",geo:lat,",",geo:long,"]") :: xsd:string;</textarea><br>
+ (optional). LDPath programs can be used to specify what information to return for
+ Entities selected by the /find request. This example selects the english
+ labels, comments, categories, homepage and builds a string representing the
+ location '[{latitude},{longitude}]'.<br></td>
+ </tr><tr>
+ <td><strong>Output Format:</strong></td>
+ <td><select name="format" id="findOutputFormat">
+ <option value="application/json">JSON</option>
+ <option value="application/rdf+xml">RDF/XML</option>
+ <option value="application/rdf+json">RDF/JSON</option>
+ <option value="text/turtle">Turtle</option>
+ <option value="text/rdf+nt">N-TRIPLES</option>
+ </select> (Accept header set to the request)</td>
+ </tr>
+</table>
<input type="submit" value="Search" onclick="startTestSearch(); return false;" /></p>
</form>
@@ -75,15 +120,18 @@ function startTestSearch() {
var data = "name=" + $("#testSearchValue").val() + "&limit=10&offset=0";
$.ajax({
type: "POST",
+ beforeSend: function(req) {
+ req.setRequestHeader("Accept", $("#findOutputFormat").val());
+ },
url: base,
- data: data,
+ data: $("#findForm").serialize(),
dataType: "text",
cache: false,
success: function(result) {
$("#testSearchResultText").text(result);
},
- error: function(result) {
- $("#testSearchResultText").text(result);
+ error: function(jqXHR, textStatus, errorThrown) {
+ $("#testSearchResultText").text(jqXHR.statusText + " - " + jqXHR.responseText);
}
});
}
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_ldpath.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_ldpath.ftl?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_ldpath.ftl (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_ldpath.ftl Thu Dec 15 11:13:30 2011
@@ -62,18 +62,25 @@
<p>Execute the LDPath on the Context:<br>
<form name="ldpathExample" id="ldpathExample">
- <input type="text" size="150" name="context" value="http://dbpedia.org/resource/Paris">
- <textarea class="input" name="ldpath" rows="10">@prefix dct : <http://purl.org/dc/terms/subject/> ;
+ <strong>Context:</strong> <input type="text" size="120" name="context" value="http://dbpedia.org/resource/Paris">
+ <strong>LD-Path:</strong><br>
+ <textarea class="input" name="ldpath" rows="10">@prefix dct : <http://purl.org/dc/terms/> ;
@prefix geo : <http://www.w3.org/2003/01/geo/wgs84_pos#> ;
name = rdfs:label[@en] :: xsd:string;
labels = rdfs:label :: xsd:string;
comment = rdfs:comment[@en] :: xsd:string;
categories = dct:subject :: xsd:anyURI;
homepage = foaf:homepage :: xsd:anyURI;
-location = fn:concat("[",geo:lat,",",geo:long,"]") :: xsd:string;</textarea>
+location = fn:concat("[",geo:lat,",",geo:long,"]") :: xsd:string;</textarea><br>
+<strong>Format:</strong> <select name="format" id="findOutputFormat">
+ <option value="application/json">JSON-LD</option>
+ <option value="application/rdf+xml">RDF/XML</option>
+ <option value="application/rdf+json">RDF/JSON</option>
+ <option value="text/turtle">Turtle</option>
+ <option value="text/rdf+nt">N-TRIPLES</option>
+ </select> (Accept header set to the request)<p>
<input type="submit" value="Execute" onclick="executeLDPath(); return false;" /></p>
</form>
-</p>
<script language="javascript">
function executeLDPath() {
@@ -88,6 +95,9 @@ function executeLDPath() {
$.ajax({
type: 'POST',
url: base ,
+ beforeSend: function(req) {
+ req.setRequestHeader("Accept", $("#findOutputFormat").val());
+ },
data: $("#ldpathExample").serialize(),
dataType: "text",
cache: false,
@@ -102,6 +112,29 @@ function executeLDPath() {
</script>
<div id="ldpathExampleResult" style="display: none">
-<p><a href="#" onclick="$('#findSymbolResult').hide(); return false;">Hide results</a>
+<p><a href="#" onclick="$('#ldpathExampleResult').hide(); return false;">Hide results</a>
<pre id="ldpathExampleResultText">... waiting for results ...</pre>
</div>
+
+<p><strong>Other LDPath Examples:</strong><ul>
+<li> This select all persons a) directly connected b) member of the same category c)
+member of a (direct) sub-category:
+ <textarea rows="5" readonly>@prefix dct : <http://purl.org/dc/terms/> ;
+@prefix dbp-ont : <http://dbpedia.org/ontology/> ;
+@prefix skos : <http://www.w3.org/2004/02/skos/core#> ;
+name = rdfs:label[@en] :: xsd:string ;
+people = (* | dct:subject/^dct:subject | dct:subject/^skos:broader/^dct:subject)[rdf:type is dbp-ont:Person] :: xsd:anyURI;</textarea>
+<li> Schema translation: The following example converts dbpedia data for to schema.org
+ <textarea rows="5" readonly>@prefix dct : <http://purl.org/dc/terms/> ;
+@prefix dbp-ont : <http://dbpedia.org/ontology/> ;
+@prefix skos : <http://www.w3.org/2004/02/skos/core#> ;
+@prefix schema : <http://schema.org/> ;
+@prefix foaf : <http://xmlns.com/foaf/0.1/> ;
+schema:name = rdfs:label[@en];
+schema:description = rdfs:comment[@en];
+schema:image = foaf:depiction;
+schema:url = foaf:homepage;
+schema:birthDate = dbp-ont:birthDate;
+schema:deathDate = dbp-ont:deathDate;</textarea>
+</ul>
+</p>
\ No newline at end of file
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_query.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_query.ftl?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_query.ftl (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_query.ftl Thu Dec 15 11:13:30 2011
@@ -45,3 +45,61 @@
<p><em>Note</em>: "@fieldQuery.json" links to a local file that contains the parsed
Fieldquery (see ection "FieldQuery JSON format" for examples).</p>
+
+<!-- TODO: Add Example for queries
+<h4>Test</h4>
+<p>Execute the FieldQuery:<br>
+<form name="ldpathExample" id="ldpathExample">
+<table><tr>
+<td><strong>Selected:</strong> :</td>
+<td><textarea class="input" name="selected" rows="4"></textarea></td>
+</tr><tr>
+<td><strong>LDPath:</strong> :</td>
+<td><textarea class="input" name="ldpath" rows="6">@prefix dct : <http://purl.org/dc/terms/subject/> ;
+@prefix geo : <http://www.w3.org/2003/01/geo/wgs84_pos#> ;
+name = rdfs:label[@en] :: xsd:string;
+labels = rdfs:label :: xsd:string;
+comment = rdfs:comment[@en] :: xsd:string;
+categories = dct:subject :: xsd:anyURI;
+homepage = foaf:homepage :: xsd:anyURI;
+latidude = geo:lat :: xsd:decimal;
+longitude = geo:long :: xsd:decimal;</textarea></td>
+</tr><tr>
+<td><strong>Constraints:</strong> :</td>
+<td><textarea class="input" name="constraints" rows="4">TODO: add Example</textarea></td>
+</tr><tr>
+<td><strong>Limit:</strong> :</td>
+<td><input type="text" size="5" name="limit" value="10"></td>
+</tr><tr>
+<td><strong>Offset:</strong> :</td>
+<td><input type="text" size="5" name="offset" value="0"></td>
+</tr></table>
+<input type="submit" value="Query" onclick="executeQuery(); return false;" /></p>
+</form>
+</p>
+
+<script language="javascript">
+function executeQuery() {
+ var relpath = "/ldpath";
+ var base = window.location.href.replace(/\/$/, "");
+ if(base.lastIndexOf(relpath) != (base.length-relpath.length)){
+ base = base+relpath;
+ }
+ $("#ldpathExampleResult").hide();
+ $("#ldpathExampleResultText").text("... waiting for results ...");
+ $("#ldpathExampleResult").show();
+ $.ajax({
+ type: 'POST',
+ url: base ,
+ data: $("#ldpathExample").serialize(),
+ dataType: "text",
+ cache: false,
+ success: function(data) {
+ $("#ldpathExampleResultText").text(data);
+ },
+ error: function(jqXHR, textStatus, errorThrown) {
+ $("#ldpathExampleResultText").text(jqXHR.statusText + " - " + jqXHR.responseText);
+ }
+ });
+}
+</script> -->
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/ldpath.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/ldpath.ftl?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/ldpath.ftl (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/ldpath.ftl Thu Dec 15 11:13:30 2011
@@ -19,7 +19,6 @@
<@common.page title="ReferencedSite LDPath" hasrestapi=true>
<#include "inc_ldpath.ftl">
-<hr>
<#include "/imports/ldpathdocumentation.ftl">
</...@common.page>
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/query.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/query.ftl?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/query.ftl (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/query.ftl Thu Dec 15 11:13:30 2011
@@ -19,8 +19,8 @@
<@common.page>
<#include "inc_query.ftl">
-<hr>
<#include "/imports/fieldquerydocumentation.ftl">
+<#include "/imports/ldpathdocumentation.ftl">
</...@common.page>
</#escape>
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/find.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/find.ftl?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/find.ftl (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/find.ftl Thu Dec 15 11:13:30 2011
@@ -19,6 +19,8 @@
<@common.page>
<#include "inc_find.ftl">
+<hr>
+<#include "/imports/ldpathdocumentation.ftl">
</...@common.page>
</#escape>
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_find.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_find.ftl?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_find.ftl (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_find.ftl Thu Dec 15 11:13:30 2011
@@ -54,11 +54,55 @@
<pre>curl -X POST -d "name=Bishofsh*&limit=10&offset=0" ${it.publicBaseUri}entityhub/sites/find</pre>
+
<h4>Test</h4>
-<form>
-<p>Start test search for
-<input type="text" id="testSearchValue" value="Paderb*" />
+<form name="findForm" id="findForm">
+<p>Find entities with <br>
+<table><tr>
+ <td><strong>Name:</strong></td>
+ <td><input type="text" name="name" size="40" value="Paderb*"/> (required)<br>
+ This supports Wildcards such as 'Exam?le*'</td>
+ </tr><tr>
+ <td><strong>Language:</strong></td>
+ <td><input type="text" name="lang" size="10" value="en" />
+ (optional, default: any)</td>
+ </tr><tr>
+ <td><strong>Field:</strong> </td>
+ <td><input type="text" name="field" size="60" />
+ (optional, reasonable default - usually rdfs:label)</td>
+ </tr><tr>
+ <td><strong>Limit:</string></td>
+ <td> <input type="text" name="limit" size="6" maxlength="6" value="10" />
+ (optional, number, default: 10) The maximum number of results</td>
+ </tr><tr>
+ <td><strong>Offset:</strong> </td>
+ <td><input type="text" name="offset" size="6" maxlength="6" value="0" />
+ (optional, number, default: 0) The offset of the first returned result</td>
+ </tr><tr>
+ <td><strong>LDPath:</strong>
+ </td><td><textarea class="input" name="ldpath" rows="10">@prefix dct : <http://purl.org/dc/terms/> ;
+@prefix geo : <http://www.w3.org/2003/01/geo/wgs84_pos#> ;
+name = rdfs:label[@en] :: xsd:string;
+comment = rdfs:comment[@en] :: xsd:string;
+categories = dct:subject :: xsd:anyURI;
+homepage = foaf:homepage :: xsd:anyURI;
+location = fn:concat("[",geo:lat,",",geo:long,"]") :: xsd:string;</textarea><br>
+ (optional). LDPath programs can be used to specify what information to return for
+ Entities selected by the /find request. This example selects the english
+ labels, comments, categories, homepage and builds a string representing the
+ location '[{latitude},{longitude}]'.</td>
+ </tr><tr>
+ <td><strong>Output Format:</strong></td>
+ <td><select name="format" id="findOutputFormat">
+ <option value="application/json">JSON</option>
+ <option value="application/rdf+xml">RDF/XML</option>
+ <option value="application/rdf+json">RDF/JSON</option>
+ <option value="text/turtle">Turtle</option>
+ <option value="text/rdf+nt">N-TRIPLES</option>
+ </select> (Accept header set to the request)</td>
+ </tr>
+</table>
<input type="submit" value="Search" onclick="startTestSearch(); return false;" /></p>
</form>
@@ -69,17 +113,20 @@ function startTestSearch() {
var data = "name=" + $("#testSearchValue").val() + "&limit=10&offset=0";
$.ajax({
type: "POST",
+ beforeSend: function(req) {
+ req.setRequestHeader("Accept", $("#findOutputFormat").val());
+ },
url: "${it.publicBaseUri}entityhub/sites/find",
- data: data,
+ data: $("#findForm").serialize(),
dataType: "text",
cache: false,
success: function(result) {
$("#testSearchResultText").text(result);
},
- error: function(result) {
- $("#testSearchResultText").text(result);
+ error: function(jqXHR, textStatus, errorThrown) {
+ $("#testSearchResultText").text(jqXHR.statusText + " - " + jqXHR.responseText);
}
- });
+ });
}
</script>
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_ldpath.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_ldpath.ftl?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_ldpath.ftl (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_ldpath.ftl Thu Dec 15 11:13:30 2011
@@ -61,18 +61,25 @@
<p>Execute the LDPath on the Context:<br>
<form name="ldpathExample" id="ldpathExample">
- <input type="text" size="150" name="context" value="http://dbpedia.org/resource/Paris">
- <textarea class="input" name="ldpath" rows="10">@prefix dct : <http://purl.org/dc/terms/subject/> ;
+ <strong>Context:</strong> <input type="text" size="120" name="context" value="http://dbpedia.org/resource/Paris">
+ <strong>LD-Path:</strong><br>
+ <textarea class="input" name="ldpath" rows="10">@prefix dct : <http://purl.org/dc/terms/> ;
@prefix geo : <http://www.w3.org/2003/01/geo/wgs84_pos#> ;
name = rdfs:label[@en] :: xsd:string;
labels = rdfs:label :: xsd:string;
comment = rdfs:comment[@en] :: xsd:string;
categories = dct:subject :: xsd:anyURI;
homepage = foaf:homepage :: xsd:anyURI;
-location = fn:concat("[",geo:lat,",",geo:long,"]") :: xsd:string;</textarea>
+location = fn:concat("[",geo:lat,",",geo:long,"]") :: xsd:string;</textarea><br>
+<strong>Format:</strong> <select name="format" id="findOutputFormat">
+ <option value="application/json">JSON-LD</option>
+ <option value="application/rdf+xml">RDF/XML</option>
+ <option value="application/rdf+json">RDF/JSON</option>
+ <option value="text/turtle">Turtle</option>
+ <option value="text/rdf+nt">N-TRIPLES</option>
+ </select> (Accept header set to the request)<p>
<input type="submit" value="Execute" onclick="executeLDPath(); return false;" /></p>
</form>
-</p>
<script language="javascript">
function executeLDPath() {
@@ -82,6 +89,9 @@ function executeLDPath() {
$.ajax({
type: 'POST',
url: "${it.publicBaseUri}entityhub/sites/ldpath" ,
+ beforeSend: function(req) {
+ req.setRequestHeader("Accept", $("#findOutputFormat").val());
+ },
data: $("#ldpathExample").serialize(),
dataType: "text",
cache: false,
@@ -96,6 +106,28 @@ function executeLDPath() {
</script>
<div id="ldpathExampleResult" style="display: none">
-<p><a href="#" onclick="$('#findSymbolResult').hide(); return false;">Hide results</a>
+<p><a href="#" onclick="$('#ldpathExampleResult').hide(); return false;">Hide results</a>
<pre id="ldpathExampleResultText">... waiting for results ...</pre>
</div>
+<p><strong>Other LDPath Examples:</strong><ul>
+<li> This select all persons a) directly connected b) member of the same category c)
+member of a (direct) sub-category:
+ <textarea rows="5" readonly>@prefix dct : <http://purl.org/dc/terms/> ;
+@prefix dbp-ont : <http://dbpedia.org/ontology/> ;
+@prefix skos : <http://www.w3.org/2004/02/skos/core#> ;
+name = rdfs:label[@en] :: xsd:string ;
+people = (* | dct:subject/^dct:subject | dct:subject/^skos:broader/^dct:subject)[rdf:type is dbp-ont:Person] :: xsd:anyURI;</textarea>
+<li> Schema translation: The following example converts dbpedia data for to schema.org
+ <textarea rows="5" readonly>@prefix dct : <http://purl.org/dc/terms/> ;
+@prefix dbp-ont : <http://dbpedia.org/ontology/> ;
+@prefix skos : <http://www.w3.org/2004/02/skos/core#> ;
+@prefix schema : <http://schema.org/> ;
+@prefix foaf : <http://xmlns.com/foaf/0.1/> ;
+schema:name = rdfs:label[@en];
+schema:description = rdfs:comment[@en];
+schema:image = foaf:depiction;
+schema:url = foaf:homepage;
+schema:birthDate = dbp-ont:birthDate;
+schema:deathDate = dbp-ont:deathDate;</textarea>
+</ul>
+</p>
Modified: incubator/stanbol/trunk/entityhub/ldpath/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/ldpath/pom.xml?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/ldpath/pom.xml (original)
+++ incubator/stanbol/trunk/entityhub/ldpath/pom.xml Thu Dec 15 11:13:30 2011
@@ -51,10 +51,22 @@
<Export-Package>
org.apache.stanbol.entityhub.ldpath;version=${project.version},
org.apache.stanbol.entityhub.ldpath.backend;version=${project.version},
+ org.apache.stanbol.entityhub.ldpath.query;version=${project.version},
org.apache.stanbol.entityhub.ldpath.transformer;version=${project.version},
at.newmedialab.ldpath;version=${ldpath.version},
- at.newmedialab.ldpath.api.*;version=${ldpath.version},
- at.newmedialab.ldpath.model.*;version=${ldpath.version},
+ at.newmedialab.ldpath.api;version=${ldpath.version},
+ at.newmedialab.ldpath.api.backend;version=${ldpath.version},
+ at.newmedialab.ldpath.api.functions;version=${ldpath.version},
+ at.newmedialab.ldpath.api.selectors;version=${ldpath.version},
+ at.newmedialab.ldpath.api.transformers;version=${ldpath.version},
+ at.newmedialab.ldpath.model;version=${ldpath.version},
+ at.newmedialab.ldpath.model.backend;version=${ldpath.version},
+ at.newmedialab.ldpath.model.fields;version=${ldpath.version},
+ at.newmedialab.ldpath.model.functions;version=${ldpath.version},
+ at.newmedialab.ldpath.model.programs;version=${ldpath.version},
+ at.newmedialab.ldpath.model.selectors;version=${ldpath.version},
+ at.newmedialab.ldpath.model.transformers;version=${ldpath.version},
+ at.newmedialab.ldpath.util;version=${ldpath.version},
at.newmedialab.ldpath.exception;version=${ldpath.version}
</Export-Package>
<Private-Package>
Modified: incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/EntityhubLDPath.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/EntityhubLDPath.java?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/EntityhubLDPath.java (original)
+++ incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/EntityhubLDPath.java Thu Dec 15 11:13:30 2011
@@ -1,7 +1,5 @@
package org.apache.stanbol.entityhub.ldpath;
-import java.io.Reader;
-
import org.apache.stanbol.entityhub.core.mapping.ValueConverterFactory.AnyUriConverter;
import org.apache.stanbol.entityhub.core.mapping.ValueConverterFactory.ReferenceConverter;
import org.apache.stanbol.entityhub.core.mapping.ValueConverterFactory.TextConverter;
Added: incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/backend/AbstractBackend.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/backend/AbstractBackend.java?rev=1214701&view=auto
==============================================================================
--- incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/backend/AbstractBackend.java (added)
+++ incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/backend/AbstractBackend.java Thu Dec 15 11:13:30 2011
@@ -0,0 +1,410 @@
+package org.apache.stanbol.entityhub.ldpath.backend;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.EnumMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+import org.apache.stanbol.entityhub.core.mapping.ValueConverterFactory;
+import org.apache.stanbol.entityhub.servicesapi.EntityhubException;
+import org.apache.stanbol.entityhub.servicesapi.defaults.DataTypeEnum;
+import org.apache.stanbol.entityhub.servicesapi.model.Reference;
+import org.apache.stanbol.entityhub.servicesapi.model.Representation;
+import org.apache.stanbol.entityhub.servicesapi.model.Text;
+import org.apache.stanbol.entityhub.servicesapi.model.ValueFactory;
+import org.apache.stanbol.entityhub.servicesapi.query.FieldQuery;
+import org.apache.stanbol.entityhub.servicesapi.query.QueryResultList;
+import org.apache.stanbol.entityhub.servicesapi.query.ReferenceConstraint;
+import org.apache.stanbol.entityhub.servicesapi.query.TextConstraint;
+import org.apache.stanbol.entityhub.servicesapi.query.ValueConstraint;
+import org.apache.stanbol.entityhub.servicesapi.query.TextConstraint.PatternType;
+import org.apache.stanbol.entityhub.servicesapi.util.ModelUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+/**
+ * Abstract super class for all Entityhub related {@link RDFBackend}
+ * implementations. This implements the whole {@link RDFBackend} interface by
+ * forwarding requests to the abstract methods<ul>
+ * <li> {@link #getRepresentation(String)}: Lookup of Representations by ID
+ * <li> {@link #query(FieldQuery)}: Used to query entities for property value
+ * pairs.
+ * </ul>
+ * In addition two further methods are defined to create {@link FieldQuery field queries} and
+ * o lookup the {@link ValueFactory} instance needed to create URIs and
+ * Literals.
+ * @author Rupert Westenthaler
+ *
+ */
+public abstract class AbstractBackend implements RDFBackend<Object> {
+
+ public static final int DEFAULT_MAX_SELECT = 1000; //select a maximum of 1000 values per query
+ public static final int DEFAULT_MAX_RESULTS = 100000; //select a maximum of 100k entities
+
+ private static final int LRU_CACHE_SIZE = 1000;
+
+ @SuppressWarnings("serial")
+ private final LinkedHashMap<String,Representation> lru =
+ new LinkedHashMap<String,Representation>(LRU_CACHE_SIZE+1, 0.75f, true){
+ @Override
+ protected boolean removeEldestEntry(java.util.Map.Entry<String,Representation> eldest) {
+ return size() > LRU_CACHE_SIZE;
+ }
+ };
+ /**
+ * Locally add Representations.
+ */
+ private final Map<String,Representation> local = new TreeMap<String,Representation>();
+ /**
+ * EnumMap to avoid instantiations of URIs for the limited set of
+ * DataTypes
+ */
+ private static final Map<DataTypeEnum,URI> dataTypeURIs;
+ static {
+ Map<DataTypeEnum,URI> uris = new EnumMap<DataTypeEnum,URI>(DataTypeEnum.class);
+ for(DataTypeEnum type : DataTypeEnum.values()){
+ uris.put(type, URI.create(type.getUri()));
+ }
+ dataTypeURIs = Collections.unmodifiableMap(uris);
+ }
+
+ private final Logger log = LoggerFactory.getLogger(YardBackend.class);
+
+ protected final ValueConverterFactory valueConverter;
+
+ public AbstractBackend() {
+ this(null);
+ }
+ public AbstractBackend(ValueConverterFactory valueConverter) {
+ if(valueConverter == null){
+ this.valueConverter = ValueConverterFactory.getDefaultInstance();
+ } else {
+ this.valueConverter = valueConverter;
+ }
+ } protected abstract ValueFactory getValueFactory();
+
+ protected abstract Representation getRepresentation(String id) throws EntityhubException;
+
+ protected abstract QueryResultList<String> query(FieldQuery query) throws EntityhubException;
+
+ protected abstract FieldQuery createQuery();
+
+ @Override
+ public String createLiteral(String content) {
+ return content;
+ }
+
+ @Override
+ public Object createLiteral(String content, Locale language, URI type) {
+ DataTypeEnum dataType = type == null ? null : DataTypeEnum.getDataType(type.toString());
+ if(language == null && type == null){
+ return content;
+ }
+ if(language != null){
+ if(type != null && !(DataTypeEnum.String == dataType || DataTypeEnum.Text == dataType)){
+ throw new IllegalArgumentException("Literals with a Lanugage MUST not have NULL,"+
+ DataTypeEnum.String.getShortName()+" or "+
+ DataTypeEnum.Text.getShortName()+" assigned as type!");
+ } else {
+ return getValueFactory().createText(content, language.getLanguage());
+ }
+ } else if(type != null){ //create a typed literal
+ if(dataType == null){ //the parsed type is an unknown data type
+ return content; //return an string
+ } else {
+ Object converted = valueConverter.convert(content, dataType.getUri(), getValueFactory());
+ if(converted == null){
+ log.debug("Unable to convert content '{}' to dataType '{}'",converted,dataType);
+ return content;
+ } else {
+ return converted;
+ }
+ }
+ } else { //language is null and type is null
+ return content;
+ }
+ }
+
+ @Override
+ public Object createURI(String uri) {
+ return getValueFactory().createReference(uri);
+ }
+
+ @Override
+ public Locale getLiteralLanguage(Object n) {
+ String language;
+ try {
+ language = ((Text)n).getLanguage();
+ } catch (ClassCastException e) {
+ return null;
+ }
+ if(language == null){
+ return null;
+ } else {
+ //TODO check if Locales should be create created like that
+ return new Locale(language);
+ }
+ }
+
+ @Override
+ public URI getLiteralType(Object n) {
+ if(n == null){
+ return null;
+ } else {
+ Set<DataTypeEnum> types = DataTypeEnum.getPrimaryDataTypes(n.getClass());
+ if(types == null || types.isEmpty()){
+ return dataTypeURIs.get(DataTypeEnum.String);
+ } else {
+ return dataTypeURIs.get(types.iterator().next());
+ }
+ }
+ }
+
+ @Override
+ public boolean isBlank(Object n) {
+ //The entityhub does not use blank nodes
+ return false;
+ }
+
+ @Override
+ public boolean isLiteral(Object n) {
+ return !(n instanceof Reference);
+ }
+
+ @Override
+ public boolean isURI(Object n) {
+ return n instanceof Reference;
+ }
+
+ @Override
+ public Collection<Object> listObjects(Object subject, Object property) {
+ Collection<Object> results;
+ if(subject == null){
+ results = Collections.emptySet();
+ } else {
+ //Here the assumption is the the LD Path program will request
+ //a lot of properties for a very low numbers of Entities
+ // .. there fore we keep here representations within an LRU cache
+ Representation r = getCached(subject.toString());
+ if(r == null){
+ try {
+ r = getRepresentation(subject.toString());
+ } catch (EntityhubException e) {
+ throw new IllegalStateException(e.getMessage(),e);
+ }
+ if(r != null){
+ toLRU(r);
+ }
+ }
+ if(r != null){
+ if(property != null){
+ results = ModelUtils.asCollection(r.get(property.toString()));
+ } else {
+ results = new LinkedHashSet<Object>();
+ for(Iterator<String> properties = r.getFieldNames();properties.hasNext();){
+ results.addAll(ModelUtils.addToCollection(r.get(properties.next()), results));
+ }
+ }
+ } else {
+ results = Collections.emptyList();
+ }
+ }
+ return results;
+ }
+
+ @Override
+ public Collection<Object> listSubjects(Object property, Object object) {
+ FieldQuery query = createQuery();
+ if(this.isURI(object)){
+ query.setConstraint(property.toString(), new ReferenceConstraint(object.toString()));
+ } else if(object instanceof Text){
+ Text text = (Text)object;
+ TextConstraint constraint;
+ if(text.getLanguage() == null){
+ constraint = new TextConstraint(text.getText(), PatternType.none, true);
+ } else {
+ constraint = new TextConstraint(text.getText(), PatternType.none, true,text.getLanguage());
+ }
+ query.setConstraint(property.toString(), constraint);
+ } else {
+ Set<DataTypeEnum> dataTypes = DataTypeEnum.getPrimaryDataTypes(object.getClass());
+ if(dataTypes == null || dataTypes.isEmpty()){
+ query.setConstraint(property.toString(),
+ new ValueConstraint(object));
+ } else {
+ Collection<String> types = new ArrayList<String>(dataTypes.size());
+ for(DataTypeEnum type : dataTypes){
+ types.add(type.getUri());
+ }
+ query.setConstraint(property.toString(),
+ new ValueConstraint(object,types));
+ }
+ }
+ query.setLimit(Integer.valueOf(DEFAULT_MAX_SELECT));
+ QueryResultList<String> results;
+ try {
+ results = query(query);
+
+ } catch (EntityhubException e) {
+ throw new IllegalStateException("Unable to query for resources with value '"+
+ object+"' on property '"+property+"'!",e);
+ }
+ Collection<Object> references;
+ if(results.isEmpty()){
+ references = Collections.emptySet();
+ } else if(results.size() == 1){ //assuming that a single result is a likely case
+ references = Collections.singleton(
+ (Object)getValueFactory().createReference(results.iterator().next()));
+ } else {
+ int offset = 0;
+ references = new HashSet<Object>(results.size());
+ for(String result : results){
+ references.add(getValueFactory().createReference(result));
+ }
+ while(results.size() >= DEFAULT_MAX_SELECT && references.size() <= DEFAULT_MAX_RESULTS-DEFAULT_MAX_SELECT){
+ offset = offset + results.size();
+ query.setOffset(offset);
+ try {
+ results = query(query);
+ } catch (EntityhubException e) {
+ throw new IllegalStateException("Unable to query for resources with value '"+
+ object+"' on property '"+property+"'!",e);
+ }
+ for(String result : results){
+ references.add(getValueFactory().createReference(result));
+ }
+ }
+ }
+ return references;
+ }
+ @Override
+ public String stringValue(Object node) {
+ //The Entityhub requires that the toString method returns the lexical form
+ return node == null ? null :
+ node instanceof Text ? ((Text)node).getText() : node.toString();
+ }
+ @Override
+ public Boolean booleanValue(Object node) {
+ return convert(DataTypeEnum.Boolean, node);
+ }
+ @Override
+ public BigInteger integerValue(Object node) {
+ return convert(DataTypeEnum.Integer, node);
+ }
+ @Override
+ public Integer intValue(Object node) {
+ return convert(DataTypeEnum.Int, node);
+ }
+ @Override
+ public Long longValue(Object node) {
+ return convert(DataTypeEnum.Long, node);
+ }
+ @Override
+ public Float floatValue(Object node) {
+ return convert(DataTypeEnum.Float, node);
+ }
+ @Override
+ public Double doubleValue(Object node) {
+ return convert(DataTypeEnum.Double, node);
+ }
+ @Override
+ public BigDecimal decimalValue(Object node) {
+ return convert(DataTypeEnum.Decimal, node);
+ }
+ @Override
+ public Date dateTimeValue(Object node) {
+ return convert(DataTypeEnum.DateTime, node);
+ }
+ @Override
+ public Date dateValue(Object node) {
+ return convert(DataTypeEnum.Date, node);
+ }
+ @Override
+ public Date timeValue(Object node) {
+ return convert(DataTypeEnum.Time, node);
+ }
+ /**
+ * Internal utility to save a lot of code lines for checking on <code>null</code>
+ * for conversions and throwing an {@link IllegalArgumentException} is so.
+ * @param <T> the generic return type
+ * @param type the dataType
+ * @param vf the valueFactory
+ * @param value the value to convert
+ * @return the converted value
+ */
+ @SuppressWarnings("unchecked")
+ private <T> T convert(DataTypeEnum type, Object value){
+ T converted;
+ Object convertedObject = valueConverter.convert(value, type.getUri(), getValueFactory());
+ try {
+ converted = (T)convertedObject;
+ } catch (ClassCastException e) {
+ //this is something unexpected ... fail cleanly
+ throw new IllegalStateException("Convert value for Node'"+
+ value+"' has not the expected java type "+type.getJavaType()+
+ "(for type '"+type.getShortName()+"') but '"+convertedObject.getClass()+"'!");
+ }
+ if(converted == null){
+ throw new IllegalArgumentException("Unable to convert value '"+
+ value+"' to dataType '"+type.getShortName()+"' (java: "+
+ type.getJavaType()+")!");
+ }
+ return converted;
+ }
+ /*
+ * Utility methods for managing the local cache
+ */
+ /**
+ * Adds an retrieved Representation to the LRU cache
+ * @param r
+ */
+ private void toLRU(Representation r){
+ lru.put(r.getId(), r);
+ }
+ /**
+ * Adds a Representation already available in-memory to this RDFBackend.
+ * This allows to prevent re-loading of Representations while executing
+ * LDPath programs.<p>
+ * Usually this is used if using Representations selected by a Query as
+ * context for LDPath program executions.
+ * @param r
+ */
+ public void addLocal(Representation r){
+ if(r != null){
+ local.put(r.getId(), r);
+ lru.remove(r.getId());
+ } //else ignore
+ }
+ /**
+ * Removes a Representation form the local cache
+ * @param id the ID of the represetnation to remove
+ */
+ public void removeLocal(String id){
+ if(id != null){
+ local.remove(id);
+ lru.remove(id);
+ }
+ }
+ /**
+ * Tries to get an {@link Representation} form {@link #local} or {@link #lru}
+ * @param id the ID
+ * @return the {@link Representation} or <code>null</code> if not cached
+ */
+ private Representation getCached(String id){
+ Representation r = local.get(id);
+ return r == null ? lru.get(id) : r;
+ }
+}
Modified: incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/backend/SiteBackend.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/backend/SiteBackend.java?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/backend/SiteBackend.java (original)
+++ incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/backend/SiteBackend.java Thu Dec 15 11:13:30 2011
@@ -10,6 +10,7 @@ import org.apache.stanbol.entityhub.serv
import org.apache.stanbol.entityhub.servicesapi.query.QueryResultList;
import org.apache.stanbol.entityhub.servicesapi.site.ReferencedSite;
+
public class SiteBackend extends AbstractBackend {
protected final ReferencedSite site;
Modified: incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/backend/SiteManagerBackend.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/backend/SiteManagerBackend.java?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/backend/SiteManagerBackend.java (original)
+++ incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/backend/SiteManagerBackend.java Thu Dec 15 11:13:30 2011
@@ -3,7 +3,6 @@ package org.apache.stanbol.entityhub.ldp
import org.apache.stanbol.entityhub.core.mapping.ValueConverterFactory;
import org.apache.stanbol.entityhub.core.model.InMemoryValueFactory;
import org.apache.stanbol.entityhub.core.query.DefaultQueryFactory;
-import org.apache.stanbol.entityhub.ldpath.backend.AbstractBackend;
import org.apache.stanbol.entityhub.servicesapi.EntityhubException;
import org.apache.stanbol.entityhub.servicesapi.model.Entity;
import org.apache.stanbol.entityhub.servicesapi.model.Representation;
Added: incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/query/LDPathFieldQueryImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/query/LDPathFieldQueryImpl.java?rev=1214701&view=auto
==============================================================================
--- incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/query/LDPathFieldQueryImpl.java (added)
+++ incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/query/LDPathFieldQueryImpl.java Thu Dec 15 11:13:30 2011
@@ -0,0 +1,25 @@
+package org.apache.stanbol.entityhub.ldpath.query;
+
+import org.apache.stanbol.entityhub.core.query.FieldQueryImpl;
+import org.apache.stanbol.entityhub.servicesapi.query.FieldQuery;
+
+/**
+ * FieldQuery implementation that also implements {@link LDPathSelect}
+ * @author Rupert Westenthaler
+ *
+ */
+public class LDPathFieldQueryImpl extends FieldQueryImpl implements FieldQuery, LDPathSelect {
+
+
+ private String ldpath;
+
+ public void setLDPathSelect(String ldpath) {
+ this.ldpath = ldpath;
+ }
+
+ @Override
+ public String getLDPathSelect() {
+ return ldpath;
+ }
+
+}
Propchange: incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/query/LDPathFieldQueryImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/query/LDPathSelect.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/query/LDPathSelect.java?rev=1214701&view=auto
==============================================================================
--- incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/query/LDPathSelect.java (added)
+++ incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/query/LDPathSelect.java Thu Dec 15 11:13:30 2011
@@ -0,0 +1,17 @@
+package org.apache.stanbol.entityhub.ldpath.query;
+
+/**
+ * Interface that allows to get the LDPath program to select values for
+ * QueryResults.
+ * @author Rupert Westenthaler
+ *
+ */
+public interface LDPathSelect {
+ /**
+ * The LDPath program used to select values for query results or
+ * <code>null</code> if none
+ * @return the LDPath program or <code>null</code> if none.
+ */
+ public String getLDPathSelect();
+
+}
Propchange: incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/query/LDPathSelect.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/stanbol/trunk/entityhub/ldpath/src/test/java/org/apache/stanbol/entityhub/ldpath/EntityhubLDPathTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/ldpath/src/test/java/org/apache/stanbol/entityhub/ldpath/EntityhubLDPathTest.java?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/ldpath/src/test/java/org/apache/stanbol/entityhub/ldpath/EntityhubLDPathTest.java (original)
+++ incubator/stanbol/trunk/entityhub/ldpath/src/test/java/org/apache/stanbol/entityhub/ldpath/EntityhubLDPathTest.java Thu Dec 15 11:13:30 2011
@@ -40,6 +40,7 @@ public class EntityhubLDPathTest extends
StringBuilder builder = new StringBuilder();
builder.append("@prefix eh : <http://www.iks-project.eu/ontology/rick/model/>;");
builder.append("@prefix dct : <http://purl.org/dc/terms/>;");
+ builder.append("@prefix geo : <http://www.w3.org/2003/01/geo/wgs84_pos#> ;");
//this test that even when selecting strings the language is preserved
builder.append("name = rdfs:label :: xsd:string;");
//this tests support for natural language texts as used by the entityhub
@@ -48,6 +49,7 @@ public class EntityhubLDPathTest extends
builder.append("categories = dct:subject :: xsd:anyURI;");
//this tests support for Reference as used by the entityhub
builder.append("type = rdf:type :: eh:ref;");
+ builder.append("lat = geo:lat :: xsd:double;");
DATA_TYPE_TEST_PROGRAM = builder.toString();
}
@@ -93,6 +95,7 @@ public class EntityhubLDPathTest extends
vf.createReference("http://dbpedia.org/ontology/PopulatedPlace"),
vf.createReference("http://dbpedia.org/ontology/Place")
)));
+ expected.put("lat", Collections.emptySet());
EXPECTED_RESULTS_LONDON = Collections.unmodifiableMap(expected);
}
Modified: incubator/stanbol/trunk/entityhub/ldpath/src/test/java/org/apache/stanbol/entityhub/ldpath/backend/BackendTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/ldpath/src/test/java/org/apache/stanbol/entityhub/ldpath/backend/BackendTest.java?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/ldpath/src/test/java/org/apache/stanbol/entityhub/ldpath/backend/BackendTest.java (original)
+++ incubator/stanbol/trunk/entityhub/ldpath/src/test/java/org/apache/stanbol/entityhub/ldpath/backend/BackendTest.java Thu Dec 15 11:13:30 2011
@@ -2,22 +2,12 @@ package org.apache.stanbol.entityhub.ldp
import static org.apache.stanbol.entityhub.ldpath.LDPathUtils.getReader;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.bcel.generic.GETSTATIC;
-import org.apache.stanbol.entityhub.ldpath.LDPathUtils;
import org.apache.stanbol.entityhub.ldpath.impl.LDPathTestBase;
import org.junit.Test;
import org.slf4j.Logger;
@@ -36,10 +26,12 @@ public class BackendTest extends LDPathT
static {
StringBuilder builder = new StringBuilder();
//TODO:write LDPath test statement (or load it from test resources
+ builder.append("@prefix geo : <http://www.w3.org/2003/01/geo/wgs84_pos#> ;");
builder.append("title = rdfs:label :: xsd:string;");
builder.append("title_en = rdfs:label[@en] :: xsd:string;");
builder.append("type = rdf:type :: xsd:anyURI;");
builder.append("all = * :: xsd:string;");
+ builder.append("lat = geo:lat :: xsd:double;");
DBPEDIA_TEST_PROGRAM = builder.toString();
}
@@ -68,6 +60,7 @@ public class BackendTest extends LDPathT
"http://dbpedia.org/resource/Category:Host_cities_of_the_Summer_Olympic_Games",
"2.350833","0.81884754","2193031"));
expected.put("all", allValues);
+ expected.put("lat", Collections.emptySet());
EXPECTED_RESULTS_PARIS = Collections.unmodifiableMap(expected);
}
Modified: incubator/stanbol/trunk/entityhub/query/clerezza/src/main/java/org/apache/stanbol/entityhub/query/clerezza/RdfQueryResultList.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/query/clerezza/src/main/java/org/apache/stanbol/entityhub/query/clerezza/RdfQueryResultList.java?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/query/clerezza/src/main/java/org/apache/stanbol/entityhub/query/clerezza/RdfQueryResultList.java (original)
+++ incubator/stanbol/trunk/entityhub/query/clerezza/src/main/java/org/apache/stanbol/entityhub/query/clerezza/RdfQueryResultList.java Thu Dec 15 11:13:30 2011
@@ -16,10 +16,14 @@
*/
package org.apache.stanbol.entityhub.query.clerezza;
+import static org.apache.stanbol.entityhub.servicesapi.util.ModelUtils.RESULT_SCORE_COMPARATOR;
+
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashSet;
+import java.util.List;
import java.util.Set;
import org.apache.clerezza.rdf.core.MGraph;
@@ -33,7 +37,7 @@ import org.apache.stanbol.entityhub.serv
public class RdfQueryResultList implements QueryResultList<Representation> {
private final FieldQuery query;
- private final Collection<RdfRepresentation> results;
+ private final List<RdfRepresentation> results;
private final MGraph resultGraph;
public RdfQueryResultList(FieldQuery query,MGraph resultGraph) {
@@ -45,10 +49,13 @@ public class RdfQueryResultList implemen
}
this.query = query;
this.resultGraph = resultGraph;
- this.results = Collections.unmodifiableSet(
- ModelUtils.addToSet(
- SparqlQueryUtils.parseQueryResultsFromMGraph(resultGraph),
- new LinkedHashSet<RdfRepresentation>()));
+ List<RdfRepresentation> results = (List<RdfRepresentation>)ModelUtils.addToCollection(
+ SparqlQueryUtils.parseQueryResultsFromMGraph(resultGraph),
+ new ArrayList<RdfRepresentation>());
+ //sort the list based on the score
+ Collections.sort(results,RESULT_SCORE_COMPARATOR);
+ this.results = Collections.unmodifiableList(results);
+
}
@Override
public final FieldQuery getQuery() {
Added: incubator/stanbol/trunk/entityhub/query/clerezza/src/test/java/org/apache/stanbol/entityhub/query/clerezza/RdfResultListTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/query/clerezza/src/test/java/org/apache/stanbol/entityhub/query/clerezza/RdfResultListTest.java?rev=1214701&view=auto
==============================================================================
--- incubator/stanbol/trunk/entityhub/query/clerezza/src/test/java/org/apache/stanbol/entityhub/query/clerezza/RdfResultListTest.java (added)
+++ incubator/stanbol/trunk/entityhub/query/clerezza/src/test/java/org/apache/stanbol/entityhub/query/clerezza/RdfResultListTest.java Thu Dec 15 11:13:30 2011
@@ -0,0 +1,68 @@
+package org.apache.stanbol.entityhub.query.clerezza;
+
+import java.util.Iterator;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.stanbol.entityhub.core.query.FieldQueryImpl;
+import org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation;
+import org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory;
+import org.apache.stanbol.entityhub.servicesapi.model.Representation;
+import org.apache.stanbol.entityhub.servicesapi.model.rdf.RdfResourceEnum;
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RdfResultListTest {
+ private final static Logger log = LoggerFactory.getLogger(RdfResultListTest.class);
+ /**
+ * Providing a sorted Iteration over query results stored in an RDF
+ * graph is not something trivial. Therefore this test
+ */
+ @Test
+ public void testRdfResultSorting(){
+ SortedMap<Double,RdfRepresentation> sorted = new TreeMap<Double,RdfRepresentation>();
+ MGraph resultGraph = new SimpleMGraph();
+ RdfValueFactory vf = new RdfValueFactory(resultGraph);
+ UriRef resultListNode = new UriRef(RdfResourceEnum.QueryResultSet.getUri());
+ UriRef resultProperty = new UriRef(RdfResourceEnum.queryResult.getUri());
+ for(int i=0;i<100;i++){
+ Double rank;
+ do { //avoid duplicate keys
+ rank = Math.random();
+ } while (sorted.containsKey(rank));
+ RdfRepresentation r = vf.createRepresentation("urn:sortTest:rep."+i);
+ //link the representation with the query result set
+ resultGraph.add(new TripleImpl(resultListNode,resultProperty,r.getNode()));
+ r.set(RdfResourceEnum.resultScore.getUri(), rank);
+ sorted.put(rank, r);
+ }
+ RdfQueryResultList resultList = new RdfQueryResultList(new FieldQueryImpl(),
+ resultGraph);
+ if(log.isDebugEnabled()){
+ log.debug("---DEBUG Sorting ---");
+ for(Iterator<Representation> it = resultList.iterator();it.hasNext();){
+ Representation r = it.next();
+ log.debug("{}: {}",r.getFirst(RdfResourceEnum.resultScore.getUri()),r.getId());
+ }
+ }
+ log.debug("---ASSERT Sorting ---");
+ for(Iterator<Representation> it = resultList.iterator();it.hasNext();){
+ Representation r = it.next();
+ Double lastkey = sorted.lastKey();
+ Representation last = sorted.get(lastkey);
+ Assert.assertEquals("score: "+r.getFirst(RdfResourceEnum.resultScore.getUri())+
+ " of Representation "+r.getId()+" is not as expected "+
+ last.getFirst(RdfResourceEnum.resultScore.getUri())+" of Representation "+
+ last.getId()+"!",r, last);
+ sorted.remove(lastkey);
+ }
+ Assert.assertTrue(sorted.isEmpty());
+ }
+
+}
Propchange: incubator/stanbol/trunk/entityhub/query/clerezza/src/test/java/org/apache/stanbol/entityhub/query/clerezza/RdfResultListTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/ldpath/DbpediaLDPathTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/ldpath/DbpediaLDPathTest.java?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/ldpath/DbpediaLDPathTest.java (original)
+++ incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/ldpath/DbpediaLDPathTest.java Thu Dec 15 11:13:30 2011
@@ -173,5 +173,199 @@ public class DbpediaLDPathTest extends E
"\"@literal\": \"Paris\","
);
}
+ /*
+ * "/find" tests
+ */
+ @Test
+ public void testFindInvalidLDPath() throws IOException {
+ //parse some illegal LDPath
+ executor.execute(
+ builder.buildPostRequest("/entityhub/site/dbpedia/ldpath")
+ .withHeader("Accept", "text/turtle")
+ .withFormContent(
+ "name","Vienna",
+ "lang","en",
+ //NOTE the missing semicolon
+ "ldpath","label_de = rdfs:label[@de] :: xsd:string",
+ "limit","1")
+ )
+ .assertStatus(Status.BAD_REQUEST.getStatusCode());
+ }
+ @Test
+ public void testFindLDPathSelectLabel() throws IOException {
+ //select the German label on a query for the english one
+ executor.execute(
+ builder.buildPostRequest("/entityhub/site/dbpedia/find")
+ .withHeader("Accept", "text/turtle")
+ .withFormContent(
+ "name","Vienna",
+ "lang","en",
+ "ldpath","name_de = rdfs:label[@de] :: xsd:string;",
+ "limit","1")
+ )
+ .assertStatus(200)
+ .assertContentType("text/turtle")
+ .assertContentContains(
+ "<http://www.iks-project.eu/ontology/rick/query/score>",
+ "<http://dbpedia.org/resource/Vienna>",
+ "<name_de> \"Wien\"@de .");
+ }
+ @Test
+ public void testFindLDPathOnMultipleResults() throws IOException {
+ //select multiple end check that LD-Path is executed on all results
+ executor.execute(
+ builder.buildPostRequest("/entityhub/site/dbpedia/find")
+ .withHeader("Accept", "text/turtle")
+ .withFormContent(
+ "name","York",
+ "lang","en",
+ "ldpath","@prefix geo : <http://www.w3.org/2003/01/geo/wgs84_pos#> ;"+
+ "lat = geo:lat :: xsd:double;",
+ "limit","3")
+ )
+ .assertStatus(200)
+ .assertContentType("text/turtle")
+ .assertContentContains(
+ "<http://www.iks-project.eu/ontology/rick/query/score>",
+ "<http://dbpedia.org/resource/York>",
+ "<lat> \"53.958332\"^^<http://www.w3.org/2001/XMLSchema#double> .",
+ "<http://dbpedia.org/resource/New_York_City>",
+ "<lat> \"40.716667\"^^<http://www.w3.org/2001/XMLSchema#double> .",
+ "<http://dbpedia.org/resource/New_York>",
+ "<lat> \"43.0\"^^<http://www.w3.org/2001/XMLSchema#double> .");
+ }
+ @Test
+ public void testFindLDPathSelectPaths() throws IOException {
+ //select the German name and the categories ond other members of the
+ //same category
+ executor.execute(
+ builder.buildPostRequest("/entityhub/site/dbpedia/find")
+ .withHeader("Accept", "text/turtle")
+ .withFormContent(
+ "name","Spinne",
+ "lang","de",
+ "ldpath","@prefix dct : <http://purl.org/dc/terms/> ;"+
+ "name = rdfs:label[@en] :: xsd:string;"+
+ "category = dct:subject :: xsd:anyURI;"+
+ "others = dct:subject/^dct:subject :: xsd:anyURI;",
+ "limit","1")
+ )
+ .assertStatus(200)
+ .assertContentType("text/turtle")
+ .assertContentContains(
+ "<http://www.iks-project.eu/ontology/rick/query/score>",
+ "<name> \"Spider\"@en ;",
+ "<category> <http://dbpedia.org/resource/Category:Arachnids> , " +
+ "<http://dbpedia.org/resource/Category:Spiders> ;",
+ "<others> <http://dbpedia.org/resource/Acari> , " +
+ "<http://dbpedia.org/resource/Spider> , " +
+ "<http://dbpedia.org/resource/Scorpion> , " +
+ "<http://dbpedia.org/resource/Arachnid> .");
+ }
+ @Test
+ public void testQueryIllegalLDPath() throws IOException {
+ //The field query as java string
+ String query = "{"+
+ "\"ldpath\": \"@prefix dct : <http:\\/\\/purl.org\\/dc\\/terms\\/subject\\/> ; " +
+ "@prefix geo : <http:\\/\\/www.w3.org\\/2003\\/01\\/geo\\/wgs84_pos#> ; " +
+ "@prefix dbp-ont : <http:\\/\\/dbpedia.org\\/ontology\\/> ; " +
+ //note the missing semicolon
+ "lat = geo:lat :: xsd:decimal ; long = geo:long :: xsd:decimal " +
+ "type = rdf:type :: xsd:anyURI;\","+
+ "\"constraints\": [{ "+
+ "\"type\": \"reference\","+
+ "\"field\": \"http:\\/\\/www.w3.org\\/1999\\/02\\/22-rdf-syntax-ns#type\","+
+ "\"value\": \"http:\\/\\/dbpedia.org\\/ontology\\/Place\","+
+ "},"+
+ "{"+
+ "\"type\": \"range\","+
+ "\"field\": \"http:\\/\\/www.w3.org\\/2003\\/01\\/geo\\/wgs84_pos#lat\","+
+ "\"lowerBound\": 50,"+
+ "\"upperBound\": 51,"+
+ "\"inclusive\": true,"+
+ "\"datatype\": \"xsd:double\""+
+ "},"+
+ "{"+
+ "\"type\": \"range\","+
+ "\"field\": \"http:\\/\\/www.w3.org\\/2003\\/01\\/geo\\/wgs84_pos#long\","+
+ "\"lowerBound\": 6,"+
+ "\"upperBound\": 8,"+
+ "\"inclusive\": true,"+
+ "\"datatype\": \"xsd:double\""+
+ "}"+
+ "],"+
+ "\"offset\": 0,"+
+ "\"limit\": 10,"+
+ "}";
+ executor.execute(
+ builder.buildPostRequest("/entityhub/site/dbpedia/query")
+ .withHeader("Content-Type", "application/json")
+ .withHeader("Accept", "text/turtle")
+ .withContent(query)
+ )
+ .assertStatus(Status.BAD_REQUEST.getStatusCode());
+ }
+ @Test
+ public void testQueryLDPathSelection() throws IOException {
+ //The field query as java string
+ String query = "{"+
+ "\"ldpath\": \"@prefix dct : <http:\\/\\/purl.org\\/dc\\/terms\\/subject\\/> ; " +
+ "@prefix geo : <http:\\/\\/www.w3.org\\/2003\\/01\\/geo\\/wgs84_pos#> ; " +
+ "@prefix dbp-ont : <http:\\/\\/dbpedia.org\\/ontology\\/> ; " +
+ "lat = geo:lat :: xsd:decimal ; long = geo:long :: xsd:decimal ; " +
+ "population = dbp-ont:populationTotal :: xsd:integer ; " +
+ "elevation = dbp-ont:elevation :: xsd:integer ; " +
+ "name = rdfs:label[@en] :: xsd:string; " +
+ "categories = dct:subject :: xsd:anyURI; " +
+ "type = rdf:type :: xsd:anyURI;\","+
+ "\"constraints\": [{ "+
+ "\"type\": \"reference\","+
+ "\"field\": \"http:\\/\\/www.w3.org\\/1999\\/02\\/22-rdf-syntax-ns#type\","+
+ "\"value\": \"http:\\/\\/dbpedia.org\\/ontology\\/Place\","+
+ "},"+
+ "{"+
+ "\"type\": \"range\","+
+ "\"field\": \"http:\\/\\/www.w3.org\\/2003\\/01\\/geo\\/wgs84_pos#lat\","+
+ "\"lowerBound\": 50,"+
+ "\"upperBound\": 51,"+
+ "\"inclusive\": true,"+
+ "\"datatype\": \"xsd:double\""+
+ "},"+
+ "{"+
+ "\"type\": \"range\","+
+ "\"field\": \"http:\\/\\/www.w3.org\\/2003\\/01\\/geo\\/wgs84_pos#long\","+
+ "\"lowerBound\": 6,"+
+ "\"upperBound\": 8,"+
+ "\"inclusive\": true,"+
+ "\"datatype\": \"xsd:double\""+
+ "}"+
+ "],"+
+ "\"offset\": 0,"+
+ "\"limit\": 10,"+
+ "}";
+ executor.execute(
+ builder.buildPostRequest("/entityhub/site/dbpedia/query")
+ .withHeader("Content-Type", "application/json")
+ .withHeader("Accept", "text/turtle")
+ .withContent(query)
+ )
+ .assertStatus(200)
+ .assertContentType("text/turtle")
+ .assertContentContains(
+ //first expected entities
+ "<http://dbpedia.org/resource/Bonn>",
+ "<http://dbpedia.org/resource/Aachen>",
+ "<http://dbpedia.org/resource/Koblenz>",
+ "<http://dbpedia.org/resource/Cologne>",
+ //now some values based on the LDPath
+ "<name> \"Koblenz\"@en",
+ "<lat> \"50.359722\"",
+ "<long> \"7.597778\"",
+ "<type> <http://www.w3.org/2002/07/owl#Thing> , " +
+ "<http://www.opengis.net/gml/_Feature> , " +
+ "<http://dbpedia.org/ontology/Town>",
+ "<population> 314926");
+ }
+
}