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/09 16:02:10 UTC
svn commit: r1212465 [2/2] - in /incubator/stanbol/trunk:
entityhub/bundlelist/src/main/bundles/
entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/mapping/
entityhub/jersey/
entityhub/jersey/src/main/java/org/apache/stanbol/entityh...
Added: 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=1212465&view=auto
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/ldpath.ftl (added)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/ldpath.ftl Fri Dec 9 15:02:09 2011
@@ -0,0 +1,26 @@
+<#--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<#import "/imports/common.ftl" as common>
+<#escape x as x?html>
+<@common.page title="ReferencedSite LDPath" hasrestapi=true>
+
+<#include "inc_ldpath.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/ReferencedSiteRootResource/site_common.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/site_common.ftl?rev=1212465&r1=1212464&r2=1212465&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/site_common.ftl (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/site_common.ftl Fri Dec 9 15:02:09 2011
@@ -20,7 +20,7 @@
<@common.page title="Referenced Site" hasrestapi=true>
<div class="panel" id="restapi">
-<h3>Service Endpoint <a href="${it.publicBaseUri}entityhub/sites">/entityhub/sites</a></h3>
+<h3>Service Endpoint <a href="${it.publicBaseUri}entityhub/sites">/entityhub/site/{siteId}</a></h3>
<#nested>
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_entity.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_entity.ftl?rev=1212465&r1=1212464&r2=1212465&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_entity.ftl (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_entity.ftl Fri Dec 9 15:02:09 2011
@@ -14,7 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<h4>Subresource /entity?id={URI}</h4>
+<h3>Subresource /entity?id={URI}</h3>
<table>
<tbody>
@@ -39,7 +39,7 @@
</tbody>
</table>
-<h5>Example</h5>
+<h4>Example</h4>
<pre>curl "${it.publicBaseUri}entityhub/sites/entity?id=http://dbpedia.org/resource/Paris"</pre>
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=1212465&r1=1212464&r2=1212465&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 Fri Dec 9 15:02:09 2011
@@ -14,7 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<h4>Subresource /find?name={name}</h4>
+<h3>Subresource /find?name={name}</h3>
<table>
<tbody>
@@ -50,11 +50,11 @@
</tbody>
</table>
-<h5>Example</h5>
+<h4>Example</h4>
<pre>curl -X POST -d "name=Bishofsh*&limit=10&offset=0" ${it.publicBaseUri}entityhub/sites/find</pre>
-<h5>Test</h5>
+<h4>Test</h4>
<form>
<p>Start test search for
Added: 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=1212465&view=auto
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_ldpath.ftl (added)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_ldpath.ftl Fri Dec 9 15:02:09 2011
@@ -0,0 +1,101 @@
+<#--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<h3> Subresource LDPath (/ldpath?ldpath={ldpath}&context={context})</h3>
+<table>
+<tbody>
+ <tr>
+ <th>Description</th>
+ <td>This service can be used to execute an LDPath program on one or more
+ Entities (contexts). Both a POST and a GET version are available.</td>
+ </tr>
+ <tr>
+ <th>Request</th>
+ <td><ul>
+ <li>GET /entityhub/ldpath?ldpath=ldpath&context={context1}[&context={contextn}]</li>
+ <li>POST -d "ldpath=ldpath&context={context1}[&context={contextn}]" /entityhub/ldpath</li>
+ </ul>
+ </td>
+ </tr>
+ <tr>
+ <th>Parameter</th>
+ <td><ul><li>ldpath: The LDPath program to execute.</li>
+ <li>context: The id of the entity used as context for the execution
+ of the LDPath program. This parameter can occur multiple times</li>
+ </ul>
+ </td>
+ </tr>
+ <tr>
+ <th>Produces:</th>
+ <td>Produces an RDF Graph with the parsed context(s) as subject the
+ field selected by the LDPath program as properties and the selected
+ values as object. All RDF serialisations are supported however
+ JSON-LD seams to be a natural fit for the data created by LDPath.
+ JSON-LD is also the default encoding.</td>
+ </tr>
+</tbody>
+</table>
+
+<h4>Example</h4>
+<p>The following LDPath statement will be executed on the defined contexts</p>
+
+<pre>curl -X POST -d "context=http://dbpedia.org/resource/Paris&ldpath=name%20%3D%20rdfs%3Alabel%5B%40en%5D%3B" ${it.publicBaseUri}entityhub/sites/ldpath</pre>
+
+<p> NOTE: the LDPath MUST BE URLEncoded. The decoded string of the above example is
+"name = rdfs:label[@en];" and would select the english label of Paris in the field "name".</p>
+
+<h4>Test</h4>
+
+<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/> ;
+@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:lon,"]") :: xsd:string;</textarea>
+ <input type="submit" value="Execute" onclick="executeLDPath(); return false;" /></p>
+</form>
+</p>
+
+<script language="javascript">
+function executeLDPath() {
+ $("#ldpathExampleResult").hide();
+ $("#ldpathExampleResultText").text("... waiting for results ...");
+ $("#ldpathExampleResult").show();
+ $.ajax({
+ type: 'POST',
+ url: "${it.publicBaseUri}entityhub/sites/ldpath" ,
+ 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>
+
+<div id="ldpathExampleResult" style="display: none">
+<p><a href="#" onclick="$('#findSymbolResult').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/SiteManagerRootResource/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/SiteManagerRootResource/inc_query.ftl?rev=1212465&r1=1212464&r2=1212465&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_query.ftl (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_query.ftl Fri Dec 9 15:02:09 2011
@@ -14,7 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<h4>Subresource /query</h4>
+<h3>Subresource /query</h3>
<table>
<tbody>
@@ -39,7 +39,7 @@
</tbody>
</table>
-<h5>Example</h5>
+<h4>Example</h4>
<pre>curl -X POST -H "Content-Type:application/json" --data "@fieldQuery.json" ${it.publicBaseUri}entityhub/sites/query</pre>
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_referenced.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_referenced.ftl?rev=1212465&r1=1212464&r2=1212465&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_referenced.ftl (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_referenced.ftl Fri Dec 9 15:02:09 2011
@@ -14,7 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<h4>Subresource /referenced</h4>
+<h3>Subresource /referenced</h3>
<table>
<tbody>
@@ -39,14 +39,14 @@
</tbody>
</table>
-<h5>Example</h5>
+<h4>Example</h4>
<pre>curl "${it.publicBaseUri}entityhub/sites/referenced"</pre>
-<h5>Example response</h5>
+<h4>Example response</h4>
<pre>["http:\/\/localhost:8080\/entityhub\/site\/dbpedia\/",
"http:\/\/localhost:8080\/entityhub\/site\/musicbrainz\/"]</pre>
-<h5>Test</h5>
+<h4>Test</h4>
<p>You can check the referenced sites in this installation by
<a href="#" onclick="listReferencedSites(); return false;">clicking here</a>.</p>
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/index.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/index.ftl?rev=1212465&r1=1212464&r2=1212465&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/index.ftl (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/index.ftl Fri Dec 9 15:02:09 2011
@@ -24,6 +24,7 @@
<li><a href="${it.publicBaseUri}entityhub/sites/entity">/entityhub/sites/entity</a></li>
<li><a href="${it.publicBaseUri}entityhub/sites/find">/entityhub/sites/find</a></li>
<li><a href="${it.publicBaseUri}entityhub/sites/query">/entityhub/sites/query</a></li>
+ <li><a href="${it.publicBaseUri}entityhub/sites/ldpath">/entityhub/sites/ldpath</a></li>
</ul>
<hr>
@@ -34,6 +35,8 @@
<#include "inc_find.ftl">
<hr>
<#include "inc_query.ftl">
+<hr>
+<#include "inc_ldpath.ftl">
</...@common.page>
</#escape>
Added: incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/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/ldpath.ftl?rev=1212465&view=auto
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/ldpath.ftl (added)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/ldpath.ftl Fri Dec 9 15:02:09 2011
@@ -0,0 +1,26 @@
+<#--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<#import "/imports/common.ftl" as common>
+<#escape x as x?html>
+<@common.page title="ReferecedSiteManager LDPath" hasrestapi=true>
+
+<#include "inc_ldpath.ftl">
+<hr>
+<#include "/imports/ldpathdocumentation.ftl">
+
+</...@common.page>
+</#escape>
Modified: incubator/stanbol/trunk/entityhub/ldpath/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/ldpath/pom.xml?rev=1212465&r1=1212464&r2=1212465&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/ldpath/pom.xml (original)
+++ incubator/stanbol/trunk/entityhub/ldpath/pom.xml Fri Dec 9 15:02:09 2011
@@ -35,6 +35,9 @@
</developerConnection>
<url>http://incubator.apache.org/stanbol</url>
</scm>
+ <properties>
+ <ldpath.version>0.9.3-SNAPSHOT</ldpath.version>
+ </properties>
<build>
<!-- make it an OSGi bundle -->
@@ -46,11 +49,39 @@
<configuration>
<instructions>
<Export-Package>
- org.apache.stanbol.entityhub.ldpath;version=${project.version}
+ org.apache.stanbol.entityhub.ldpath;version=${project.version},
+ org.apache.stanbol.entityhub.ldpath.backend;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.exception;version=${ldpath.version}
</Export-Package>
<Private-Package>
org.apache.stanbol.entityhub.ldpath.impl;version=${project.version}
</Private-Package>
+ <!--
+ excludes
+ * ANT for htmlcleaner
+ * some sun.** private APIs referenced by guava
+ -->
+ <Import-Package>
+ !sun.misc,
+ !org.apache.tools.ant.*,
+ !org.apache.tools.bzip2,
+ !org.apache.tools.mail,
+ !org.apache.tools.tar,
+ !org.apache.tools.zip,
+ *
+ </Import-Package>
+ <!--
+ Embeds ldPath, guava and htmlcleaner
+ JDOM is an own Bundle
+ -->
+ <Embed-Dependency>
+ ldpath-api, ldpath-core,
+ guava, htmlcleaner,
+ </Embed-Dependency>
</instructions>
</configuration>
</plugin>
@@ -79,14 +110,28 @@
<dependency>
<groupId>at.newmedialab.ldpath</groupId>
<artifactId>ldpath-api</artifactId>
- <version>0.9.3-SNAPSHOT</version>
+ <version>${ldpath.version}</version>
</dependency>
<dependency>
<groupId>at.newmedialab.ldpath</groupId>
<artifactId>ldpath-core</artifactId>
- <version>0.9.3-SNAPSHOT</version>
+ <version>${ldpath.version}</version>
+ </dependency>
+ <!-- additional LD Path dependencies -->
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>10.0.1</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.htmlcleaner</groupId>
+ <artifactId>htmlcleaner</artifactId>
+ <version>2.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jdom</groupId>
+ <artifactId>com.springsource.org.jdom</artifactId>
</dependency>
-
<!-- dependencies on other Entityhub modules -->
<dependency>
<groupId>org.apache.stanbol</groupId>
Added: 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=1212465&view=auto
==============================================================================
--- incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/EntityhubLDPath.java (added)
+++ incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/EntityhubLDPath.java Fri Dec 9 15:02:09 2011
@@ -0,0 +1,100 @@
+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;
+import org.apache.stanbol.entityhub.core.mapping.ValueConverterFactory.ValueConverter;
+import org.apache.stanbol.entityhub.core.model.InMemoryValueFactory;
+import org.apache.stanbol.entityhub.ldpath.transformer.ValueConverterTransformerAdapter;
+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 at.newmedialab.ldpath.LDPath;
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+import at.newmedialab.ldpath.api.transformers.NodeTransformer;
+import at.newmedialab.ldpath.model.fields.FieldMapping;
+import at.newmedialab.ldpath.model.programs.Program;
+
+/**
+ * {@link LDPath} with Entityhub specific configurations.
+ * In detail this registers {@link NodeTransformer} for:<ul>
+ * <li> {@link DataTypeEnum#Reference} returning {@link Reference} instances
+ * <li> xsd:anyURI also returning {@link Reference} instances
+ * <li> {@link DataTypeEnum#Text} returning {@link Text} instances
+ * <li> xsd:string also returning {@link Text} instances
+ * </ul><p>
+ * It adds also support for returning {@link Representation} instances as
+ * result of executing {@link Program}s on a context. This is important because
+ * it allows a seamless integration of LDPath with existing Entityhub
+ * functionality/interfaces
+ *
+ * <p>Because there is currently
+ * no way to get the LDPath parser to instantiate an extension of {@link Program}
+ * this feature is currently implemented by {@link #execute(Reference, Program)}
+ * of this class.
+ *
+ * @author Rupert Westenthaler
+ *
+ */
+public class EntityhubLDPath extends LDPath<Object> {
+
+ private final ValueFactory vf;
+ private final RDFBackend<Object> backend;
+ public EntityhubLDPath(RDFBackend<Object> backend) {
+ this(backend,null);
+ }
+ public EntityhubLDPath(RDFBackend<Object> backend,ValueFactory vf) {
+ super(backend);
+ this.vf = vf == null ? InMemoryValueFactory.getInstance() : vf;
+ this.backend = backend;
+ //register special Entutyhub Transformer for
+ // * entityhub:reference
+ ValueConverter<Reference> referenceConverter = new ReferenceConverter();
+ registerTransformer(referenceConverter.getDataType(),
+ new ValueConverterTransformerAdapter<Reference>(referenceConverter,vf));
+ // * xsd:anyURI
+ ValueConverter<Reference> uriConverter = new AnyUriConverter();
+ registerTransformer(uriConverter.getDataType(),
+ new ValueConverterTransformerAdapter<Reference>(uriConverter,vf));
+ // * entityhub:text
+ ValueConverter<Text> literalConverter = new TextConverter();
+ registerTransformer(literalConverter.getDataType(),
+ new ValueConverterTransformerAdapter<Text>(literalConverter,vf));
+ // xsd:string (use also the literal converter for xsd:string
+ registerTransformer(DataTypeEnum.String.getUri(),
+ new ValueConverterTransformerAdapter<Text>(literalConverter,vf));
+ //TODO: Currently it is NOT possible to register the default
+ // Namespace mappings defined for the Entityhub!
+ }
+
+ /**
+ * Executes the parsed {@link Program} and stores the
+ * {@link Program#getFields() fields} in a {@link Representation}. The actual
+ * implementation used for the {@link Representation} depends on the
+ * {@link ValueFactory} of this EntityhubLDPath instance
+ * @param context the context
+ * @param program the program
+ * @return the {@link Representation} holding the results of the execution
+ * @throws IllegalArgumentException if the parsed context or the program is
+ * <code>null</code>
+ */
+ public Representation execute(Reference context,Program<Object> program){
+ if(context == null){
+ throw new IllegalArgumentException("The parsed context MUST NOT be NULL!");
+ }
+ if(program == null){
+ throw new IllegalArgumentException("The parsed program MUST NOT be NULL!");
+ }
+ Representation result = vf.createRepresentation(context.getReference());
+ for(FieldMapping<?,Object> mapping : program.getFields()) {
+ result.add(mapping.getFieldName(),mapping.getValues(backend,context));
+ }
+ return result;
+
+ }
+}
Propchange: incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/EntityhubLDPath.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/LDPathUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/LDPathUtils.java?rev=1212465&view=auto
==============================================================================
--- incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/LDPathUtils.java (added)
+++ incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/LDPathUtils.java Fri Dec 9 15:02:09 2011
@@ -0,0 +1,35 @@
+package org.apache.stanbol.entityhub.ldpath;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+
+import at.newmedialab.ldpath.model.programs.Program;
+
+public class LDPathUtils {
+ /**
+ * Utility method that creates a reader over the parsed String using UTF-8
+ * as encoding.<p> This is necessary because currently LDPath only accepts
+ * Reader as parameter for parsing {@link Program}s
+ * Note that it is not necessary to call {@link InputStream#close()} on the
+ * returned {@link InputStreamReader} because this is backed by an in-memory
+ * {@link ByteArrayInputStream}.
+ * @param string the string to be read by the Reader
+ * @return A reader over the parsed string
+ * @throws IllegalStateException if 'utf-8' is not supported
+ * @throws IllegalArgumentException if <code>null</code> is parsed as string
+ */
+ public static final Reader getReader(String string) {
+ if(string == null){
+ throw new IllegalArgumentException("The parsed string MUST NOT be NULL!");
+ }
+ try {
+ return new InputStreamReader(new ByteArrayInputStream(string.getBytes("utf-8")), "utf-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalStateException("Encoding 'utf-8' is not supported by this system!",e);
+ }
+ }
+
+}
Propchange: incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/LDPathUtils.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
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=1212465&r1=1212464&r2=1212465&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 Fri Dec 9 15:02:09 2011
@@ -3,6 +3,7 @@ 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.servicesapi.EntityhubException;
+import org.apache.stanbol.entityhub.servicesapi.model.Entity;
import org.apache.stanbol.entityhub.servicesapi.model.Representation;
import org.apache.stanbol.entityhub.servicesapi.model.ValueFactory;
import org.apache.stanbol.entityhub.servicesapi.query.FieldQuery;
@@ -12,16 +13,20 @@ import org.apache.stanbol.entityhub.serv
public class SiteBackend extends AbstractBackend {
protected final ReferencedSite site;
- private ValueFactory vf = InMemoryValueFactory.getInstance();
+ private final ValueFactory vf;
public SiteBackend(ReferencedSite site) {
- this(site,null);
+ this(site,null,null);
}
- public SiteBackend(ReferencedSite site,ValueConverterFactory valueConverter) {
+ public SiteBackend(ReferencedSite site,ValueFactory vf) {
+ this(site,vf,null);
+ }
+ public SiteBackend(ReferencedSite site,ValueFactory vf,ValueConverterFactory valueConverter) {
super(valueConverter);
if(site == null){
throw new IllegalArgumentException("The parsed ReferencedSite MUST NOT be NULL");
}
+ this.vf = vf == null ? InMemoryValueFactory.getInstance():vf;
this.site = site;
}
@Override
@@ -30,7 +35,8 @@ public class SiteBackend extends Abstrac
}
@Override
protected Representation getRepresentation(String id) throws EntityhubException {
- return site.getEntity(id).getRepresentation();
+ Entity entity = site.getEntity(id);
+ return entity != null ? entity.getRepresentation():null;
}
@Override
protected ValueFactory getValueFactory() {
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=1212465&r1=1212464&r2=1212465&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 Fri Dec 9 15:02:09 2011
@@ -5,6 +5,7 @@ import org.apache.stanbol.entityhub.core
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;
import org.apache.stanbol.entityhub.servicesapi.model.ValueFactory;
import org.apache.stanbol.entityhub.servicesapi.query.FieldQuery;
@@ -34,7 +35,8 @@ public class SiteManagerBackend extends
}
@Override
protected Representation getRepresentation(String id) throws EntityhubException {
- return siteManager.getEntity(id).getRepresentation();
+ Entity entity = siteManager.getEntity(id);
+ return entity != null ? entity.getRepresentation() : null;
}
@Override
protected ValueFactory getValueFactory() {
Added: incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/transformer/ValueConverterTransformerAdapter.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/transformer/ValueConverterTransformerAdapter.java?rev=1212465&view=auto
==============================================================================
--- incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/transformer/ValueConverterTransformerAdapter.java (added)
+++ incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/transformer/ValueConverterTransformerAdapter.java Fri Dec 9 15:02:09 2011
@@ -0,0 +1,49 @@
+package org.apache.stanbol.entityhub.ldpath.transformer;
+
+import org.apache.stanbol.entityhub.core.mapping.ValueConverterFactory.ValueConverter;
+import org.apache.stanbol.entityhub.core.model.InMemoryValueFactory;
+import org.apache.stanbol.entityhub.servicesapi.model.Reference;
+import org.apache.stanbol.entityhub.servicesapi.model.Text;
+import org.apache.stanbol.entityhub.servicesapi.model.ValueFactory;
+
+import at.newmedialab.ldpath.LDPath;
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+import at.newmedialab.ldpath.api.transformers.NodeTransformer;
+
+/**
+ * LDPath {@link NodeTransformer} internally using the Entityhub
+ * {@link ValueConverter}. <p>
+ * This transformer should be used for plain literals and references (xsd:anyURI)
+ * to ensure that nodes are transformed to {@link Text} and {@link Reference}
+ * instances.<p>
+ * Users should use {@link LDPathUtils#createAndInitLDPath(RDFBackend, ValueFactory)}
+ * to ensure that {@link LDPath} instances are configured accordingly.
+ *
+ * @author Rupert Westenthaler.
+ * @see LDPathUtils#createAndInitLDPath(RDFBackend, ValueFactory)
+ * @param <T>
+ */
+public class ValueConverterTransformerAdapter<T> implements NodeTransformer<T,Object> {
+
+ private final ValueFactory vf;
+ private final ValueConverter<T> vc;
+
+ public ValueConverterTransformerAdapter(ValueConverter<T> vc, ValueFactory vf){
+ this.vf = vf == null ? InMemoryValueFactory.getInstance() : vf;
+ this.vc = vc;
+ }
+ @Override
+ public T transform(RDFBackend<Object> backend, Object node) throws IllegalArgumentException {
+ T value = vc.convert(node, vf);
+ if(value == null){
+ value = vc.convert(backend.stringValue(node), vf);
+ }
+ if(value == null){
+ throw new IllegalArgumentException("Unable to transform node '"+
+ node+"' to data type '"+vc.getDataType()+"'!");
+ } else {
+ return value;
+ }
+ }
+
+}
Propchange: incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/transformer/ValueConverterTransformerAdapter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: 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=1212465&view=auto
==============================================================================
--- incubator/stanbol/trunk/entityhub/ldpath/src/test/java/org/apache/stanbol/entityhub/ldpath/EntityhubLDPathTest.java (added)
+++ incubator/stanbol/trunk/entityhub/ldpath/src/test/java/org/apache/stanbol/entityhub/ldpath/EntityhubLDPathTest.java Fri Dec 9 15:02:09 2011
@@ -0,0 +1,145 @@
+package org.apache.stanbol.entityhub.ldpath;
+
+import static org.apache.stanbol.entityhub.ldpath.LDPathUtils.getReader;
+import static org.junit.Assert.*;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.stanbol.entityhub.core.model.InMemoryValueFactory;
+import org.apache.stanbol.entityhub.ldpath.impl.LDPathTestBase;
+import org.apache.stanbol.entityhub.ldpath.transformer.ValueConverterTransformerAdapter;
+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.util.ModelUtils;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+import at.newmedialab.ldpath.model.programs.Program;
+
+public class EntityhubLDPathTest extends LDPathTestBase {
+
+ private static final Logger log = LoggerFactory.getLogger(EntityhubLDPathTest.class);
+
+ private static final ValueFactory vf = InMemoryValueFactory.getInstance();
+
+ private static final String CONTEXT_LONDON = DBPEDIA+"London";
+
+ private static final String DATA_TYPE_TEST_PROGRAM;
+ static {
+ 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/>;");
+ //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
+ builder.append("comment = rdfs:comment :: eh:text;");
+ //this tests that Reference is used for URIs
+ builder.append("categories = dct:subject :: xsd:anyURI;");
+ //this tests support for Reference as used by the entityhub
+ builder.append("type = rdf:type :: eh:ref;");
+ DATA_TYPE_TEST_PROGRAM = builder.toString();
+
+ }
+ /**
+ * This expects {@link Text} and {@link Reference} instances as results
+ * of the execution.
+ */
+ private static final Map<String,Collection<?>> EXPECTED_RESULTS_LONDON;
+ static {
+ Map<String,Collection<?>> expected = new HashMap<String,Collection<?>>();
+ expected.put("name", new HashSet<Text>(Arrays.asList(
+ vf.createText("London", "en"),
+ vf.createText("London","de"),
+ vf.createText("Londres","pt"),
+ vf.createText("Londra","tr"),
+ vf.createText("Ðондон","ru"),
+ vf.createText("伦æ¦","zh")
+ )));
+ expected.put("comment", new HashSet<Text>(Arrays.asList(
+ vf.createText("London is the capital of England and the United Kingdom, " +
+ "the largest metropolitan area in the United Kingdom and the " +
+ "largest urban zone in the European Union by most measures. " +
+ "London has been a major settlement for two millennia, its " +
+ "history going back to its founding by the Romans, who called " +
+ "it Londinium. London's core, the ancient City of London, " +
+ "largely retains its square-mile mediaeval boundaries.","en"))));
+ // NOTE: LDPath uses String to represent anyUri
+ expected.put("categories", new HashSet<Reference>(Arrays.asList(
+ vf.createReference("http://dbpedia.org/resource/Category:London"),
+ vf.createReference("http://dbpedia.org/resource/Category:British_capitals"),
+ vf.createReference("http://dbpedia.org/resource/Category:Populated_places_established_in_the_1st_century"),
+ vf.createReference("http://dbpedia.org/resource/Category:Staple_ports"),
+ vf.createReference("http://dbpedia.org/resource/Category:Articles_including_recorded_pronunciations_%28UK_English%29"),
+ vf.createReference("http://dbpedia.org/resource/Category:Capitals_in_Europe"),
+ vf.createReference("http://dbpedia.org/resource/Category:Host_cities_of_the_Commonwealth_Games"),
+ vf.createReference("http://dbpedia.org/resource/Category:Host_cities_of_the_Summer_Olympic_Games"),
+ vf.createReference("http://dbpedia.org/resource/Category:Port_cities_and_towns_in_the_United_Kingdom")
+ )));
+ expected.put("type", new HashSet<Reference>(Arrays.asList(
+ vf.createReference("http://www.w3.org/2002/07/owl#Thing"),
+ vf.createReference("http://www.opengis.net/gml/_Feature"),
+ vf.createReference("http://dbpedia.org/ontology/Settlement"),
+ vf.createReference("http://dbpedia.org/ontology/PopulatedPlace"),
+ vf.createReference("http://dbpedia.org/ontology/Place")
+ )));
+ EXPECTED_RESULTS_LONDON = Collections.unmodifiableMap(expected);
+ }
+
+ @Override
+ protected Collection<String> checkContexts() {
+ return Arrays.asList(CONTEXT_LONDON);
+ }
+ /**
+ * Tests that the {@link LDPathUtils#createAndInitLDPath(RDFBackend, ValueFactory)}
+ * correctly registers the {@link ValueConverterTransformerAdapter} for
+ * {@link DataTypeEnum#Reference}, {@link DataTypeEnum#Text},
+ * {@link DataTypeEnum#AnyUri} and {@link DataTypeEnum#String}.
+ */
+ @Test
+ public void testTransformers() throws Exception {
+ EntityhubLDPath ldPath = new EntityhubLDPath(backend);
+ Program<Object> program = ldPath.parseProgram(
+ getReader(DATA_TYPE_TEST_PROGRAM));
+ assertNotNull("The Program MUST NOT be NULL", program);
+ Map<String,Collection<?>> result = program.execute(backend,
+ vf.createReference(CONTEXT_LONDON));
+ log.info("Results for {}:\n{}",CONTEXT_LONDON,result);
+ log.info("Assert LDPath Result for {}:", CONTEXT_LONDON);
+ assertLDPathResult(result, EXPECTED_RESULTS_LONDON);
+ }
+ @Test
+ public void testReprentationMappings() throws Exception {
+ EntityhubLDPath ldPath = new EntityhubLDPath(backend);
+ Program<Object> program = ldPath.parseProgram(
+ getReader(DATA_TYPE_TEST_PROGRAM));
+ assertNotNull("The Program MUST NOT be NULL", program);
+ Representation result = ldPath.execute(
+ vf.createReference(CONTEXT_LONDON), program);
+ assertEquals("The id of the Representation '"+
+ result.getId()+"' is not the same as the parsed Context '"+
+ CONTEXT_LONDON+"'!", CONTEXT_LONDON, result.getId());
+ Iterator<Entry<String,Collection<?>>> entryIt = cloneExpected(EXPECTED_RESULTS_LONDON).entrySet().iterator();
+ while(entryIt.hasNext()){
+ Entry<String,Collection<?>> entry = entryIt.next();
+ Iterator<Object> valueIt = result.get(entry.getKey());
+ assertNotNull("The result is missing the expected field '"+
+ entry.getKey()+"'!",valueIt);
+ Collection<Object> values = ModelUtils.asCollection(valueIt);
+ entry.getValue().removeAll(values);
+ assertTrue("The following expected values "+
+ entry.getValue()+"' are missing (present: "+
+ values+")!",entry.getValue().isEmpty());
+ }
+ }
+}
Propchange: incubator/stanbol/trunk/entityhub/ldpath/src/test/java/org/apache/stanbol/entityhub/ldpath/EntityhubLDPathTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
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=1212465&r1=1212464&r2=1212465&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 Fri Dec 9 15:02:09 2011
@@ -1,26 +1,24 @@
package org.apache.stanbol.entityhub.ldpath.backend;
+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.File;
+import java.io.InputStream;
import java.io.InputStreamReader;
-import java.net.URI;
+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 static org.junit.Assert.*;
-
-import org.apache.stanbol.commons.solr.managed.ManagedSolrServer;
-import org.apache.stanbol.entityhub.servicesapi.model.Representation;
-import org.apache.stanbol.entityhub.servicesapi.util.ModelUtils;
-import org.apache.stanbol.entityhub.servicesapi.yard.Yard;
-import org.apache.stanbol.entityhub.yard.solr.impl.SolrYard;
-import org.apache.stanbol.entityhub.yard.solr.impl.SolrYardConfig;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
+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;
import org.slf4j.LoggerFactory;
@@ -29,23 +27,10 @@ import at.newmedialab.ldpath.LDPath;
import at.newmedialab.ldpath.api.backend.RDFBackend;
import at.newmedialab.ldpath.model.programs.Program;
-public class BackendTest {
+public class BackendTest extends LDPathTestBase {
private static final Logger log = LoggerFactory.getLogger(BackendTest.class);
- /**
- * The SolrYard used for the tests
- */
- private static Yard yard;
- private static YardBackend backend;
- /**
- * The SolrDirectoryManager also tested within this unit test
- */
- public static final String TEST_YARD_ID = "dbpedia";
- public static final String TEST_SOLR_CORE_NAME = "dbpedia_43k";
- protected static final String TEST_INDEX_REL_PATH = File.separatorChar + "target" + File.separatorChar
- + ManagedSolrServer.DEFAULT_SOLR_DATA_DIR;
-
- private static final String DBPEDIA = "http://dbpedia.org/resource/";
+
private static final String CONTEXT_PARIS = DBPEDIA+"Paris";
private static final String DBPEDIA_TEST_PROGRAM;
static {
@@ -60,12 +45,12 @@ public class BackendTest {
private static final Map<String,Collection<?>> EXPECTED_RESULTS_PARIS;
static {
- EXPECTED_RESULTS_PARIS = new HashMap<String,Collection<?>>();
- EXPECTED_RESULTS_PARIS.put("title_en", new HashSet<String>(Arrays.asList("Paris")));
- EXPECTED_RESULTS_PARIS.put("title", new HashSet<String>(
+ Map<String,Collection<?>> expected = new HashMap<String,Collection<?>>();
+ expected.put("title_en", new HashSet<String>(Arrays.asList("Paris")));
+ expected.put("title", new HashSet<String>(
Arrays.asList("Paris","Parijs","Parigi","Pariisi","å·´é»","ÐаÑиж")));
-// LDPath uses String to represent anyUri
- EXPECTED_RESULTS_PARIS.put("type", new HashSet<String>(Arrays.asList(
+ // NOTE: LDPath uses String to represent anyUri
+ expected.put("type", new HashSet<String>(Arrays.asList(
"http://www.w3.org/2002/07/owl#Thing",
"http://dbpedia.org/ontology/Place",
"http://dbpedia.org/ontology/PopulatedPlace",
@@ -73,24 +58,17 @@ public class BackendTest {
"http://www.opengis.net/gml/_Feature",
"http://dbpedia.org/ontology/Settlement",
"http://www.opengis.net/gml/_Feature")));
-// EXPECTED_RESULTS_PARIS.put("type", new HashSet<URI>(Arrays.asList(
-// URI.create("http://www.w3.org/2002/07/owl#Thing"),
-// URI.create("http://dbpedia.org/ontology/Place"),
-// URI.create("http://dbpedia.org/ontology/PopulatedPlace"),
-// URI.create("http://dbpedia.org/ontology/Settlement"),
-// URI.create("http://www.opengis.net/gml/_Feature"),
-// URI.create("http://dbpedia.org/ontology/Settlement"),
-// URI.create("http://www.opengis.net/gml/_Feature"))));
- //Add all previouse and some additional to test the WIldcard implementation
+ //Add all previous and some additional to test the WIldcard implementation
Collection<Object> allValues = new HashSet<Object>();
- for(Collection<?> values : EXPECTED_RESULTS_PARIS.values()){
+ for(Collection<?> values : expected.values()){
allValues.addAll(values);
}
allValues.addAll(Arrays.asList(
"http://dbpedia.org/resource/Category:Capitals_in_Europe",
"http://dbpedia.org/resource/Category:Host_cities_of_the_Summer_Olympic_Games",
"2.350833","0.81884754","2193031"));
- EXPECTED_RESULTS_PARIS.put("all", allValues);
+ expected.put("all", allValues);
+ EXPECTED_RESULTS_PARIS = Collections.unmodifiableMap(expected);
}
private static final String CONTEXT_HARVARD_ALUMNI = DBPEDIA+"Category:Harvard_University_alumni";
@@ -107,22 +85,22 @@ public class BackendTest {
private static final Map<String,Collection<?>> EXPECTED_HARVARD_ALUMNI;
static {
- EXPECTED_HARVARD_ALUMNI = new HashMap<String,Collection<?>>();
- EXPECTED_HARVARD_ALUMNI.put("name", new HashSet<String>(
+ Map<String,Collection<?>> expected = new HashMap<String,Collection<?>>();
+ expected.put("name", new HashSet<String>(
Arrays.asList("Harvard University alumni")
));
- EXPECTED_HARVARD_ALUMNI.put("parent", new HashSet<String>(Arrays.asList(
+ expected.put("parent", new HashSet<String>(Arrays.asList(
"http://dbpedia.org/resource/Category:Harvard_University_people",
"http://dbpedia.org/resource/Category:Alumni_by_university_or_college_in_Massachusetts",
"http://dbpedia.org/resource/Category:Ivy_League_alumni")
));
- EXPECTED_HARVARD_ALUMNI.put("childs", new HashSet<String>(Arrays.asList(
+ expected.put("childs", new HashSet<String>(Arrays.asList(
"http://dbpedia.org/resource/Category:John_F._Kennedy_School_of_Government_alumni",
"http://dbpedia.org/resource/Category:Harvard_Law_School_alumni",
"http://dbpedia.org/resource/Category:Harvard_Medical_School_alumni",
"http://dbpedia.org/resource/Category:Harvard_Business_School_alumni")
));
- EXPECTED_HARVARD_ALUMNI.put("members", new HashSet<String>(Arrays.asList(
+ expected.put("members", new HashSet<String>(Arrays.asList(
"http://dbpedia.org/resource/Edward_Said",
"http://dbpedia.org/resource/Cole_Porter",
"http://dbpedia.org/resource/Theodore_Roosevelt",
@@ -140,48 +118,12 @@ public class BackendTest {
"http://dbpedia.org/resource/Franklin_D._Roosevelt",
"http://dbpedia.org/resource/John_Adams") // and manny more
));
- //Add all previouse and some additional to test the WIldcard implementation
- Collection<Object> allValues = new HashSet<Object>();
- for(Collection<?> values : EXPECTED_RESULTS_PARIS.values()){
- allValues.addAll(values);
- }
- allValues.addAll(Arrays.asList(
- "http://dbpedia.org/resource/Category:Capitals_in_Europe",
- "http://dbpedia.org/resource/Category:Host_cities_of_the_Summer_Olympic_Games",
- "2.350833","0.81884754","2193031"));
- EXPECTED_RESULTS_PARIS.put("all", allValues);
+ EXPECTED_HARVARD_ALUMNI = Collections.unmodifiableMap(expected);
}
- @BeforeClass
- public static void setup() throws Exception {
- // get the working directory
- // use property substitution to test this feature!
- String prefix = System.getProperty("basedir") == null ? "." : "${basedir}";
- String solrServerDir = prefix + TEST_INDEX_REL_PATH;
- log.info("Test Solr Server Directory: {}", solrServerDir);
- System.setProperty(ManagedSolrServer.MANAGED_SOLR_DIR_PROPERTY, solrServerDir);
- SolrYardConfig config = new SolrYardConfig(TEST_YARD_ID, TEST_SOLR_CORE_NAME);
- config.setDefaultInitialisation(false);
- config.setName("DBpedia.org default data");
- config.setDescription("Data used for the LDPath setup");
- // create the Yard used for the tests
- yard = new SolrYard(config);
- backend = new YardBackend(yard);
- }
-
- /**
- * Tests that the yard is setup correctly
- * @throws Exception
- */
- @Test
- public void testSetup() throws Exception {
- Representation rep = yard.getRepresentation(CONTEXT_PARIS);
- assertNotNull(rep);
- assertEquals(rep.getId(),CONTEXT_PARIS);
- log.info(ModelUtils.getRepresentationInfo(rep));
- rep = yard.getRepresentation(CONTEXT_HARVARD_ALUMNI);
- assertNotNull(rep);
- assertEquals(rep.getId(),CONTEXT_HARVARD_ALUMNI);
- log.info(ModelUtils.getRepresentationInfo(rep));
+
+ @Override
+ protected Collection<String> checkContexts() {
+ return Arrays.asList(CONTEXT_PARIS,CONTEXT_HARVARD_ALUMNI);
}
/**
* Test {@link RDFBackend} implementation including WildCard
@@ -190,27 +132,22 @@ public class BackendTest {
@Test
public void testLDPath() throws Exception {
LDPath<Object> ldPath = new LDPath<Object>(backend);
- Program<Object> program = ldPath.parseProgram(new InputStreamReader(
- new ByteArrayInputStream(
- DBPEDIA_TEST_PROGRAM.getBytes("utf-8")
- ), "utf-8"));
+ Program<Object> program = ldPath.parseProgram(
+ getReader(DBPEDIA_TEST_PROGRAM));
assertNotNull("parsed Programm is null (Input: "+
DBPEDIA_TEST_PROGRAM+")", program);
log.info("LDPath Programm:\n{}",program.getPathExpression(backend));
Object context = backend.createURI(CONTEXT_PARIS);
Map<String,Collection<?>> result = program.execute(backend, context);
log.info("Results for {}:\n{}",CONTEXT_PARIS,result);
- assertNotNull("The result of the LDPath execution MUST NOT be NULL " +
- "(entity: %s)",context);
+ log.info("Assert LDPath Result for {}:", CONTEXT_PARIS);
assertLDPathResult(result,EXPECTED_RESULTS_PARIS);
}
@Test
public void testInversePath() throws Exception {
LDPath<Object> ldPath = new LDPath<Object>(backend);
- Program<Object> program = ldPath.parseProgram(new InputStreamReader(
- new ByteArrayInputStream(
- CATEGORIES_TEST_PROGRAM.getBytes("utf-8")
- ), "utf-8"));
+ Program<Object> program = ldPath.parseProgram(
+ getReader(CATEGORIES_TEST_PROGRAM));
assertNotNull("parsed Programm is null (Input: "+
CATEGORIES_TEST_PROGRAM+")", program);
log.info("LDPath Programm:\n{}",program.getPathExpression(backend));
@@ -218,36 +155,8 @@ public class BackendTest {
Map<String,Collection<?>> result = program.execute(backend, context);
log.info("Results for {}:\n{}",CONTEXT_HARVARD_ALUMNI,result);
assertNotNull("The result of the LDPath execution MUST NOT be NULL " +
- "(entity: %s)",context);
+ "(entity: %s)",result);
+ log.info("Assert LDPath Result for {}:", EXPECTED_HARVARD_ALUMNI);
assertLDPathResult(result,EXPECTED_HARVARD_ALUMNI);
}
-
- /**
- * @param result
- * @param expected
- */
- private void assertLDPathResult(Map<String,Collection<?>> result, Map<String,Collection<?>> expected) {
- log.info("Assert LDPath Result for {}:", CONTEXT_PARIS);
- Map<String,Collection<?>> expectedClone = new HashMap<String,Collection<?>>();
- for(Entry<String,Collection<?>> expectedEntries : expected.entrySet()){
- expectedClone.put(expectedEntries.getKey(), new HashSet<Object>(expectedEntries.getValue()));
- }
- for(Entry<String,Collection<?>> entry : result.entrySet()){
- log.info("{}: {}",entry.getKey(),entry.getValue());
- Collection<?> expectedValues = expectedClone.remove(entry.getKey());
- assertNotNull("Current field '"+entry.getKey()+"' is not expected (expected: " +
- expectedClone.keySet()+"!",
- expectedValues);
- expectedValues.removeAll(entry.getValue());
- assertTrue("Missing expected Result '"+expectedValues+"' (present: '"
- +entry.getValue()+"'", expectedValues.isEmpty());
- }
- assertTrue("Missing expected Field '"+expectedClone.keySet()+"' (present: '"+
- result.keySet()+"'!",expectedClone.isEmpty());
- }
-
- @AfterClass
- public static void cleanup() throws Exception {
- yard = null;
- }
}
Added: incubator/stanbol/trunk/entityhub/ldpath/src/test/java/org/apache/stanbol/entityhub/ldpath/impl/LDPathTestBase.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/ldpath/src/test/java/org/apache/stanbol/entityhub/ldpath/impl/LDPathTestBase.java?rev=1212465&view=auto
==============================================================================
--- incubator/stanbol/trunk/entityhub/ldpath/src/test/java/org/apache/stanbol/entityhub/ldpath/impl/LDPathTestBase.java (added)
+++ incubator/stanbol/trunk/entityhub/ldpath/src/test/java/org/apache/stanbol/entityhub/ldpath/impl/LDPathTestBase.java Fri Dec 9 15:02:09 2011
@@ -0,0 +1,131 @@
+package org.apache.stanbol.entityhub.ldpath.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.stanbol.commons.solr.managed.ManagedSolrServer;
+import org.apache.stanbol.entityhub.ldpath.backend.YardBackend;
+import org.apache.stanbol.entityhub.servicesapi.model.Representation;
+import org.apache.stanbol.entityhub.servicesapi.util.ModelUtils;
+import org.apache.stanbol.entityhub.servicesapi.yard.Yard;
+import org.apache.stanbol.entityhub.yard.solr.impl.SolrYard;
+import org.apache.stanbol.entityhub.yard.solr.impl.SolrYardConfig;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class LDPathTestBase {
+
+ private final static Logger log = LoggerFactory.getLogger(LDPathTestBase.class);
+ /**
+ * The SolrYard used for the tests
+ */
+ protected static Yard yard;
+ protected static YardBackend backend;
+ /**
+ * The SolrDirectoryManager also tested within this unit test
+ */
+ public static final String TEST_YARD_ID = "dbpedia";
+ public static final String TEST_SOLR_CORE_NAME = "dbpedia_43k";
+ protected static final String TEST_INDEX_REL_PATH = File.separatorChar + "target" + File.separatorChar
+ + ManagedSolrServer.DEFAULT_SOLR_DATA_DIR;
+
+ protected static final String DBPEDIA = "http://dbpedia.org/resource/";
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ // get the working directory
+ // use property substitution to test this feature!
+ String prefix = System.getProperty("basedir") == null ? "." : "${basedir}";
+ String solrServerDir = prefix + TEST_INDEX_REL_PATH;
+ log.info("Test Solr Server Directory: {}", solrServerDir);
+ System.setProperty(ManagedSolrServer.MANAGED_SOLR_DIR_PROPERTY, solrServerDir);
+ SolrYardConfig config = new SolrYardConfig(TEST_YARD_ID, TEST_SOLR_CORE_NAME);
+ config.setDefaultInitialisation(false);
+ config.setName("DBpedia.org default data");
+ config.setDescription("Data used for the LDPath setup");
+ // create the Yard used for the tests
+ yard = new SolrYard(config);
+ backend = new YardBackend(yard);
+ }
+ @AfterClass
+ public static void cleanup() throws Exception {
+ yard = null;
+ }
+
+ protected abstract Collection<String> checkContexts();
+
+ /**
+ * Tests that the yard is setup correctly by checking for the
+ * {@link Representation}s of the ids returned by {@link #checkContexts()}.
+ * <p>
+ * This methods should make is more easy to detect if a failure of a test
+ * is because of a wrong setup of the Yard.
+ * @throws Exception
+ */
+ @Test
+ public void testSetup() throws Exception {
+ for(String context : checkContexts()){
+ Representation rep = yard.getRepresentation(context);
+ assertNotNull(rep);
+ assertEquals(rep.getId(),context);
+ if(log.isDebugEnabled()){
+ log.debug(ModelUtils.getRepresentationInfo(rep));
+ }
+ }
+ }
+
+ /**
+ * Utility method that checks the results of an LDPath execution against
+ * a map whit expected results
+ * @param result the results of the execution
+ * @param expected the expected results
+ * @throws IllegalStateException if the parsed expected results are <code>null</code>
+ */
+ protected final void assertLDPathResult(Map<String,Collection<?>> result, Map<String,Collection<?>> expected) {
+ if(expected == null){
+ throw new IllegalStateException("The expected LDPath execution results MUST NOT be NULL. This" +
+ "indicated an ERROR in the implementation of the Unit Test and NOT in the tested Component!");
+ }
+ assertNotNull("The result of the LDPath execution MUST NOT be NULL " +
+ "(entity: %s)",result);
+ Map<String,Collection<?>> expectedClone = cloneExpected(expected);
+ for(Entry<String,Collection<?>> entry : result.entrySet()){
+ log.info("{}: {}",entry.getKey(),entry.getValue());
+ Collection<?> expectedValues = expectedClone.remove(entry.getKey());
+ assertNotNull("Current field '"+entry.getKey()+"' is not expected (expected: " +
+ expectedClone.keySet()+"!",
+ expectedValues);
+ expectedValues.removeAll(entry.getValue());
+ assertTrue("Missing expected Result '"+expectedValues+"' (present: '"
+ +entry.getValue()+"'", expectedValues.isEmpty());
+ }
+ assertTrue("Missing expected Field '"+expectedClone.keySet()+"' (present: '"+
+ result.keySet()+"'!",expectedClone.isEmpty());
+ }
+ /**
+ * Creates a clone of expected results. This is necessary because assertion of
+ * results does remove found fields and results and checks at the end for
+ * empty collections of expected results of the field and an empty map with
+ * the expected fields.
+ * @param expected the expected results
+ * @return the clone
+ */
+ protected final Map<String,Collection<?>> cloneExpected(Map<String,Collection<?>> expected) {
+ Map<String,Collection<?>> expectedClone = new HashMap<String,Collection<?>>();
+ for(Entry<String,Collection<?>> expectedEntries : expected.entrySet()){
+ expectedClone.put(expectedEntries.getKey(), new HashSet<Object>(expectedEntries.getValue()));
+ }
+ return expectedClone;
+ }
+}
Propchange: incubator/stanbol/trunk/entityhub/ldpath/src/test/java/org/apache/stanbol/entityhub/ldpath/impl/LDPathTestBase.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/stanbol/trunk/entityhub/model/clerezza/src/main/java/org/apache/stanbol/entityhub/model/clerezza/RdfValueFactory.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/model/clerezza/src/main/java/org/apache/stanbol/entityhub/model/clerezza/RdfValueFactory.java?rev=1212465&r1=1212464&r2=1212465&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/model/clerezza/src/main/java/org/apache/stanbol/entityhub/model/clerezza/RdfValueFactory.java (original)
+++ incubator/stanbol/trunk/entityhub/model/clerezza/src/main/java/org/apache/stanbol/entityhub/model/clerezza/RdfValueFactory.java Fri Dec 9 15:02:09 2011
@@ -20,6 +20,7 @@ import java.util.Iterator;
import org.apache.clerezza.rdf.core.Graph;
import org.apache.clerezza.rdf.core.Literal;
+import org.apache.clerezza.rdf.core.MGraph;
import org.apache.clerezza.rdf.core.TripleCollection;
import org.apache.clerezza.rdf.core.UriRef;
import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
@@ -47,9 +48,24 @@ public final class RdfValueFactory imple
}
return instance;
}
-
+ /**
+ * If not <code>null</code> all {@link RdfRepresentation} created by this
+ * instance will use this graph.
+ */
+ private MGraph graph;
private RdfValueFactory(){
+ this(null);
+ }
+ /**
+ * This allows to create an instance that uses the same graph for all
+ * created {@link Representation}s. This allows to automatically add all
+ * data added to {@link Representation} created by this Factory to this
+ * graph.
+ * @param graph
+ */
+ public RdfValueFactory(MGraph graph){
super();
+ this.graph = graph;
}
@Override
@@ -86,7 +102,8 @@ public final class RdfValueFactory imple
} else if(id.isEmpty()){
throw new IllegalArgumentException("The parsed id MUST NOT be empty!");
} else {
- return createRdfRepresentation(new UriRef(id), new SimpleMGraph());
+ return createRdfRepresentation(new UriRef(id),
+ graph == null ? new SimpleMGraph() : graph);
}
}
Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java?rev=1212465&r1=1212464&r2=1212465&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrYard.java Fri Dec 9 15:02:09 2011
@@ -496,12 +496,14 @@ public class SolrYard extends AbstractYa
//TODO: remove and replace with a setting where the SolrYard does not
// not activate until the SolrServer is available.
if(server == null){
- try {
- log.info(" ... waiting 1sec for SolrServer");
- server = (SolrServer)_registeredServerTracker.waitForService(1000);
- } catch (InterruptedException e) {}
+ for(int i = 0;i<5;i++){//waiting for a maximum of 5sec
+ try {
+ log.info(" ... waiting 1sec for SolrServer");
+
+ server = (SolrServer)_registeredServerTracker.waitForService(1000);
+ } catch (InterruptedException e) {}
+ }
}
-
}
//the server is not available -> throw an exception!
if(server != null){
Added: 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=1212465&view=auto
==============================================================================
--- incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/ldpath/DbpediaLDPathTest.java (added)
+++ incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/ldpath/DbpediaLDPathTest.java Fri Dec 9 15:02:09 2011
@@ -0,0 +1,177 @@
+package org.apache.stanbol.entityhub.it.ldpath;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.Arrays;
+import java.util.Collections;
+
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.stanbol.entityhub.it.ReferencedSiteTest;
+import org.apache.stanbol.entityhub.it.SitesManagerTest;
+import org.apache.stanbol.entityhub.test.it.EntityhubTestBase;
+import org.apache.stanbol.entityhub.test.query.FieldQueryTestCase;
+import org.apache.stanbol.entityhub.test.query.FindQueryTestCase;
+import org.apache.stanbol.entityhub.test.query.QueryTestBase;
+import org.codehaus.jettison.json.JSONException;
+import org.junit.Test;
+import org.slf4j.LoggerFactory;
+/**
+ * Tests for the "/query" (Field Query) and "/find" (label search)
+ * implementation of the Entityhub.<p>
+ * All the tests defined by this class assume the default data set for
+ * dbpedia as provided by the
+ * <code>org.apache.stanbol.data.sites.dbpedia.default</code> bundle. <p>
+ * This test cases are used to test both the ReferencedSiteManager and
+ * the ReferencedSite. This is also the reason why having this abstract super
+ * class defining the tests.
+ * @see ReferencedSiteTest
+ * @see SitesManagerTest
+ * @author Rupert Westenthaler
+ *
+ */
+public class DbpediaLDPathTest extends EntityhubTestBase {
+
+
+ public DbpediaLDPathTest() {
+ super(Collections.singleton("dbpedia"));
+ }
+ @Test
+ public void testNoContext() throws IOException {
+ executor.execute(
+ builder.buildPostRequest("/entityhub/site/dbpedia/ldpath")
+ .withFormContent(
+ "ldpath","name = rdfs:label[@en] :: xsd:string;")
+ )
+ .assertStatus(Status.BAD_REQUEST.getStatusCode());
+ }
+ @Test
+ public void testEmptyContext() throws IOException {
+ executor.execute(
+ builder.buildPostRequest("/entityhub/site/dbpedia/ldpath")
+ .withFormContent(
+ "ldpath","name = rdfs:label[@en] :: xsd:string;",
+ "context","")
+ )
+ .assertStatus(Status.BAD_REQUEST.getStatusCode());
+ executor.execute(
+ builder.buildPostRequest("/entityhub/site/dbpedia/ldpath")
+ .withFormContent(
+ "ldpath","name = rdfs:label[@en] :: xsd:string;",
+ "context",null)
+ )
+ .assertStatus(Status.BAD_REQUEST.getStatusCode());
+ }
+ @Test
+ public void testNoLDPath() throws IOException {
+ executor.execute(
+ builder.buildPostRequest("/entityhub/site/dbpedia/ldpath")
+ .withFormContent(
+ "context","http://dbpedia.org/resource/Paris")
+ )
+ .assertStatus(Status.BAD_REQUEST.getStatusCode());
+ }
+ @Test
+ public void testEmptyLDPath() throws IOException {
+ executor.execute(
+ builder.buildPostRequest("/entityhub/site/dbpedia/ldpath")
+ .withFormContent(
+ "context","http://dbpedia.org/resource/Paris",
+ "ldpath",null)
+ )
+ .assertStatus(Status.BAD_REQUEST.getStatusCode());
+ executor.execute(
+ builder.buildPostRequest("/entityhub/site/dbpedia/ldpath")
+ .withFormContent(
+ "context","http://dbpedia.org/resource/Paris",
+ "ldpath","")
+ )
+ .assertStatus(Status.BAD_REQUEST.getStatusCode());
+ }
+ @Test
+ public void testIllegalLDPath() throws IOException {
+ executor.execute(
+ builder.buildPostRequest("/entityhub/site/dbpedia/ldpath")
+ .withFormContent(
+ "context","http://dbpedia.org/resource/Paris",
+ //missing semicolon
+ "ldpath","name = rdfs:label[@en] :: xsd:string")
+ )
+ .assertStatus(Status.BAD_REQUEST.getStatusCode());
+ executor.execute(
+ builder.buildPostRequest("/entityhub/site/dbpedia/ldpath")
+ .withFormContent(
+ "context","http://dbpedia.org/resource/Paris",
+ //unknown namespace prefix
+ "ldpath","name = dct:subject :: xsd:anyURI;")
+ )
+ .assertStatus(Status.BAD_REQUEST.getStatusCode());
+ executor.execute(
+ builder.buildPostRequest("/entityhub/site/dbpedia/ldpath")
+ .withFormContent(
+ "context","http://dbpedia.org/resource/Paris",
+ //unknown dataType prefix
+ "ldpath","name = rdfs:label[@en] :: xsd:String;")
+ )
+ .assertStatus(Status.BAD_REQUEST.getStatusCode());
+ }
+ @Test
+ public void testMultipleContext() throws IOException {
+ executor.execute(
+ builder.buildPostRequest("/entityhub/site/dbpedia/ldpath")
+ .withFormContent(
+ "context","http://dbpedia.org/resource/Paris",
+ "context","http://dbpedia.org/resource/London",
+ "ldpath","name = rdfs:label[@en] :: xsd:string;")
+ )
+ .assertStatus(200)
+ .assertContentContains(
+ "\"@literal\": \"Paris\"",
+ "\"@literal\": \"London\"");
+ }
+ @Test
+ public void testUnknownContext() throws IOException {
+ executor.execute(
+ builder.buildPostRequest("/entityhub/site/dbpedia/ldpath")
+ .withFormContent(
+ "context","http://dbpedia.org/resource/ThisEntityDoesNotExist_ForSure_49283",
+ "ldpath","name = rdfs:label[@en] :: xsd:string;")
+ )
+ .assertStatus(200)
+ .assertContentContains("{","}");
+ }
+ @Test
+ public void testLDPath() throws IOException {
+ executor.execute(
+ builder.buildPostRequest("/entityhub/site/dbpedia/ldpath")
+ .withFormContent(
+ "context","http://dbpedia.org/resource/Paris",
+ "ldpath","@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;" +
+ "location = fn:concat(\"[\",geo:lat,\",\",geo:long,\"]\") :: xsd:string;")
+ )
+ .assertStatus(200)
+ .assertContentType("application/json")
+ .assertContentContains(
+ "\"@subject\": \"http://dbpedia.org/resource/Paris\"",
+ "\"comment\": {",
+ "Paris is the capital and largest city in France",
+ "\"homepage\": [",
+ "http://www.paris.fr",
+ "\"labels\": [",
+ "\"@literal\": \"Pariisi\",",
+ "\"@literal\": \"å·´é»\",",
+ "\"location\": \"[48.856667,2.350833]\",",
+ "\"name\": {",
+ "\"@literal\": \"Paris\","
+ );
+ }
+
+}
Propchange: incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/ldpath/DbpediaLDPathTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/stanbol/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/parent/pom.xml?rev=1212465&r1=1212464&r2=1212465&view=diff
==============================================================================
--- incubator/stanbol/trunk/parent/pom.xml (original)
+++ incubator/stanbol/trunk/parent/pom.xml Fri Dec 9 15:02:09 2011
@@ -423,6 +423,12 @@
<artifactId>org.apache.stanbol.entityhub.yard.clerezza</artifactId>
<version>0.9.0-incubating-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.entityhub.ldpath</artifactId>
+ <version>0.9.0-incubating-SNAPSHOT</version>
+ </dependency>
+
<!-- Stanbol Entityhub Indexing Bundles -->
<dependency>
<groupId>org.apache.stanbol</groupId>
@@ -1109,6 +1115,13 @@
<!-- END Solr/Lucene dependencies -->
<!-- JDom -->
+ <!-- first the ready to use bundle -->
+ <dependency>
+ <groupId>org.jdom</groupId>
+ <artifactId>com.springsource.org.jdom</artifactId>
+ <version>1.1.0</version>
+ </dependency>
+ <!-- here are the jar -->
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
@@ -1550,6 +1563,14 @@
<name>Clojars Maven Repository</name>
<url>http://clojars.org/repo</url>
</repository>
+
+ <repository>
+ <!-- this is where the jdom bundle lives -->
+ <id>com.springsource.repository.bundles.external</id>
+ <name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name>
+ <url>http://repository.springsource.com/maven/bundles/external</url>
+ </repository>
+
</repositories>
</project>