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 [1/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...
Author: rwesten
Date: Thu Dec 15 11:13:30 2011
New Revision: 1214701
URL: http://svn.apache.org/viewvc?rev=1214701&view=rev
Log:
### STANBOL-417: LD Path for Entityhub queries
This fixes STANBOL-417. LD Path is now supported for all "/find" and "/query" endpoints of the Entityhub.
The Documentation is available via the Stanbol HTTP Endpoint (e.g. http://localhost:8080/entityhub/site/dbpedia/find).
### LD-Path general (STANBOL-408)
* Remove the Query Backend. The AbstractBackend (super Class of all Entityhub RDFBackend implementations) now allows to add cached Representations.
* This also allowed to go back to normal Lists for the QueryResultList implementations.
* Added Extension to FieldQuery that allows use LD Paths
### Entityhub Web Endpoint (/jersey):
* improved Documentation (in general)
* added/improved API tests (HTML forms that allow to test the RESTful APIs)
* tests for /query is still missing
* added collapse/expand feature for the inline documentation of "field query" and "LD path"
### Managed SolrServer
* corrected a multi thread related issue in the initialization of managed indexes.
* Managed SolrServers can refer to multiple solr index archives
* if a second archives become available before the initialization of the fist one completed, than a side effect of the first initialization prevented the initialization of the second.
### Entityhub general
* added support for a sorted iteration (based on result score) over query results with the RDF triple-store based RdfQueryResultList
* This only ensures the correct iteration order via the Java API. This has no influence on the RDF serializations.
Added:
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/static/style/
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/static/style/entityhub.css (with props)
incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/backend/AbstractBackend.java
incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/backend/impl/
incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/query/
incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/query/LDPathFieldQueryImpl.java (with props)
incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/query/LDPathSelect.java (with props)
incubator/stanbol/trunk/entityhub/query/clerezza/src/test/java/org/apache/stanbol/entityhub/query/clerezza/RdfResultListTest.java (with props)
Removed:
incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/backend/QueryResultBackend.java
Modified:
incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/impl/ManagedSolrServerImpl.java
incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/query/QueryResultListImpl.java
incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/util/ModelUtils.java
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/fragment/EntityhubWebFragment.java
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/parsers/FieldQueryReader.java
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource.java
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource.java
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource.java
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/utils/JerseyUtils.java
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/utils/LDPathHelper.java
incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/writers/FieldQueryToJSON.java
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/imports/fieldquerydocumentation.ftl
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/imports/ldpathdocumentation.ftl
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource/find.ftl
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource/inc_find.ftl
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource/inc_ldpath.ftl
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/find.ftl
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_find.ftl
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_ldpath.ftl
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/inc_query.ftl
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/ldpath.ftl
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource/query.ftl
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/find.ftl
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_find.ftl
incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource/inc_ldpath.ftl
incubator/stanbol/trunk/entityhub/ldpath/pom.xml
incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/EntityhubLDPath.java
incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/backend/SiteBackend.java
incubator/stanbol/trunk/entityhub/ldpath/src/main/java/org/apache/stanbol/entityhub/ldpath/backend/SiteManagerBackend.java
incubator/stanbol/trunk/entityhub/ldpath/src/test/java/org/apache/stanbol/entityhub/ldpath/EntityhubLDPathTest.java
incubator/stanbol/trunk/entityhub/ldpath/src/test/java/org/apache/stanbol/entityhub/ldpath/backend/BackendTest.java
incubator/stanbol/trunk/entityhub/query/clerezza/src/main/java/org/apache/stanbol/entityhub/query/clerezza/RdfQueryResultList.java
incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/ldpath/DbpediaLDPathTest.java
Modified: incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/impl/ManagedSolrServerImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/impl/ManagedSolrServerImpl.java?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/impl/ManagedSolrServerImpl.java (original)
+++ incubator/stanbol/trunk/commons/solr/managed/src/main/java/org/apache/stanbol/commons/solr/managed/impl/ManagedSolrServerImpl.java Thu Dec 15 11:13:30 2011
@@ -1019,7 +1019,7 @@ public class ManagedSolrServerImpl imple
indexUpdateDaemon.update(
currentArchive == null ? ManagedIndexState.UNINITIALISED :
ManagedIndexState.ACTIVE,
- indexName, ais);
+ metadata, ais);
} // else an unused archive is no longer available -> nothing to do
} //else are not available -> nothing to do
} //end for all Indexes using the archive that is no longer available
@@ -1046,7 +1046,7 @@ public class ManagedSolrServerImpl imple
archives.indexOf(resourceName) < archives.indexOf(currentArchive)){
metadata.setArchive(resourceName);
managedCores.store(metadata);
- indexUpdateDaemon.update(ManagedIndexState.ACTIVE,indexName, ais);
+ indexUpdateDaemon.update(ManagedIndexState.ACTIVE,metadata, ais);
//if synchronised do not remove this listener
keepTracking = keepTracking || metadata.isSynchronized();
} else { //currently used Archive is of higher priority as
@@ -1073,8 +1073,19 @@ public class ManagedSolrServerImpl imple
*
*/
private class IndexUpdateDaemon extends Thread {
-
- private Map<String, ArchiveInputStream> toUpdate = new HashMap<String,ArchiveInputStream>();
+
+ private class IndexActionInfo {
+ public final ArchiveInputStream ais;
+ public final IndexMetadata metadata;
+ public final ManagedIndexState action;
+ private IndexActionInfo(ManagedIndexState action,ArchiveInputStream ais, IndexMetadata metadata){
+ this.ais = ais;
+ this.metadata = metadata;
+ this.action = action;
+ }
+ }
+ private Map<String, IndexActionInfo> toUpdate = new HashMap<String,IndexActionInfo>();
+
private boolean active = true;
public void close(){
@@ -1083,14 +1094,18 @@ public class ManagedSolrServerImpl imple
toUpdate.notifyAll();
}
}
- public void update(ManagedIndexState state, String name,ArchiveInputStream ais){
+ public void update(ManagedIndexState desiredState, IndexMetadata metadata,ArchiveInputStream ais){
+ if(metadata == null){
+ throw new IllegalArgumentException("The parsed IndexMetadata MUST NOT be NULL");
+ }
+ String name = metadata.getIndexName();
if(name == null || name.isEmpty()){
- throw new IllegalArgumentException("The parsed index name MUST NOT be NULL");
+ throw new IllegalArgumentException("The parsed IndexMetadata MUST contain a valid name (NOT NULL and NOT empty)!");
}
- if(state == null){
+ if(desiredState == null){
throw new IllegalArgumentException("The parsed desired ManagedIndexState MUST NOT be NULL");
}
- switch (state) {
+ switch (desiredState) {
case ACTIVE:
if(ais == null){
throw new IllegalArgumentException("If the parsed ManagedIndexState is ACTIVE, " +
@@ -1109,17 +1124,17 @@ public class ManagedSolrServerImpl imple
throw new IllegalArgumentException("The IndexUpdateDeamon only supports the ManagedIndexStates ACTIVE and UNINITIALISED!");
}
synchronized (toUpdate) {
- toUpdate.put(name, ais);
+ toUpdate.put(name, new IndexActionInfo(desiredState,ais, metadata));
toUpdate.notifyAll();
}
}
@Override
public void run() {
while(active){
- Entry<String,ArchiveInputStream> entry;
+ Entry<String,IndexActionInfo> entry;
while(!toUpdate.isEmpty()) {
synchronized (toUpdate) {
- Iterator<Entry<String,ArchiveInputStream>> it = toUpdate.entrySet().iterator();
+ Iterator<Entry<String,IndexActionInfo>> it = toUpdate.entrySet().iterator();
if(it.hasNext()){ //get the next element
entry = it.next();
it.remove(); //and remove it
@@ -1128,47 +1143,52 @@ public class ManagedSolrServerImpl imple
}
}
if(entry != null){
- IndexMetadata metadata = managedCores.getIndexMetadata(entry.getKey());
- if(metadata != null){
- if(entry.getValue() != null) { //desired state ACTIVE
- log.info(" ... start to ACTIVATE Index {} on ManagedSolrServer",entry.getKey(),metadata.getServerName());
+ //IndexMetadata metadata = managedCores.getIndexMetadata(entry.getKey());
+ IndexActionInfo info = entry.getValue();
+ if(isManagedIndex(entry.getKey())){
+ if(info.action == ManagedIndexState.ACTIVE){
+ log.info(" ... start to ACTIVATE Index {} on ManagedSolrServer",entry.getKey(),info.metadata.getServerName());
try {
- updateCore(metadata, entry.getValue());
- log.info(" ... Index {} on ManagedSolrServer {} is now ACTIVE",entry.getKey(),metadata.getServerName());
+ updateCore(info.metadata, info.ais);
+ log.info(" ... Index {} on ManagedSolrServer {} is now ACTIVE",entry.getKey(),info.metadata.getServerName());
} catch (IOException e) {
log.error("IOException while activating Index '"+
- metadata.getServerName()+':'+
- metadata.getIndexName()+"'!",e);
- metadata.setError(e);
+ info.metadata.getServerName()+':'+
+ info.metadata.getIndexName()+"'!",e);
+ info.metadata.setError(e);
} catch (SAXException e) {
log.error("SAXException while activating Index '"+
- metadata.getServerName()+':'+
- metadata.getIndexName()+"'!",e);
- metadata.setError(e);
+ info.metadata.getServerName()+':'+
+ info.metadata.getIndexName()+"'!",e);
+ info.metadata.setError(e);
} catch (RuntimeException e) {
log.error("Exception while activating Index '"+
- metadata.getServerName()+':'+
- metadata.getIndexName()+"'!",e);
- metadata.setError(e);
+ info.metadata.getServerName()+':'+
+ info.metadata.getIndexName()+"'!",e);
+ info.metadata.setError(e);
} finally {
- managedCores.store(metadata);
+ managedCores.store(info.metadata);
}
} else { //desired state UNINITIALISED
- log.info(" ... start to UNINITIALISE Index {} on ManagedSolrServer",entry.getKey(),metadata.getServerName());
+ log.info(" ... start to UNINITIALISE Index {} on ManagedSolrServer",entry.getKey(),info.metadata.getServerName());
try {
- uninitialiseCore(metadata,true);
- log.info(" ... Index {} on ManagedSolrServer {} is now UNINITIALISED",entry.getKey(),metadata.getServerName());
+ uninitialiseCore(info.metadata,true);
+ log.info(" ... Index {} on ManagedSolrServer {} is now UNINITIALISED",entry.getKey(),info.metadata.getServerName());
} catch (RuntimeException e) {
log.error("Exception while uninitialising Index '"+
- metadata.getServerName()+':'+
- metadata.getIndexName()+"'!",e);
- metadata.setError(e);
+ info.metadata.getServerName()+':'+
+ info.metadata.getIndexName()+"'!",e);
+ info.metadata.setError(e);
} finally {
// store the updated metadata
- managedCores.store(metadata);
+ managedCores.store(info.metadata);
}
}
- } //else removed in the meantime -> nothing to do
+ } else { //else removed in the meantime -> nothing to do
+ log.info("ingonre Update request for Index {} with desired state {} " +
+ "because this index seams to be no longer managed!",
+ entry.getKey(),info.action);
+ }
}
}
synchronized (toUpdate) {
Modified: incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/query/QueryResultListImpl.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/query/QueryResultListImpl.java?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/query/QueryResultListImpl.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/core/src/main/java/org/apache/stanbol/entityhub/core/query/QueryResultListImpl.java Thu Dec 15 11:13:30 2011
@@ -51,13 +51,13 @@ public class QueryResultListImpl<T> impl
}
this.type = type;
if(resultIterator == null || !resultIterator.hasNext()){
- this.results = Collections.emptySet();
+ this.results = Collections.emptyList();
} else {
- LinkedHashSet<T> resultList = new LinkedHashSet<T>();
+ List<T> resultList = new ArrayList<T>();
while(resultIterator.hasNext()){
resultList.add(resultIterator.next());
}
- this.results = Collections.unmodifiableSet(resultList);
+ this.results = Collections.unmodifiableList(resultList);
}
}
@Override
Modified: incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/util/ModelUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/util/ModelUtils.java?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/util/ModelUtils.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/util/ModelUtils.java Thu Dec 15 11:13:30 2011
@@ -21,6 +21,7 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
@@ -74,6 +75,23 @@ public final class ModelUtils {
}
/**
+ * Comparator based on the {@link RdfResourceEnum#resultScore} property that
+ * assumes that values of this property implement {@link Comparable}. The
+ * Representation with the highest score will be first
+ */
+ public static final Comparator<Representation> RESULT_SCORE_COMPARATOR = new Comparator<Representation>() {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public int compare(Representation r1, Representation r2) {
+ Object score1 = r1.getFirst(RdfResourceEnum.resultScore.getUri());
+ Object score2 = r2.getFirst(RdfResourceEnum.resultScore.getUri());
+ return score1 == null && score2 == null ? 0 :
+ score2 == null ? -1 :
+ score1 == null ? 1 :
+ ((Comparable)score2).compareTo((Comparable)score1);
+ }};
+ /**
* Processes a value parsed as object to the representation.
* This processing includes:
* <ul>
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/fragment/EntityhubWebFragment.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/fragment/EntityhubWebFragment.java?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/fragment/EntityhubWebFragment.java (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/fragment/EntityhubWebFragment.java Thu Dec 15 11:13:30 2011
@@ -99,7 +99,9 @@ public class EntityhubWebFragment implem
@Override
public List<LinkResource> getLinkResources() {
- return Collections.emptyList();
+ List<LinkResource> resources = new ArrayList<LinkResource>();
+ resources.add(new LinkResource("stylesheet", "style/entityhub.css", this, 0));
+ return resources;
}
@Override
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/parsers/FieldQueryReader.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/parsers/FieldQueryReader.java?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/parsers/FieldQueryReader.java (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/parsers/FieldQueryReader.java Thu Dec 15 11:13:30 2011
@@ -40,6 +40,8 @@ import org.apache.commons.io.IOUtils;
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.core.query.FieldQueryImpl;
+import org.apache.stanbol.entityhub.ldpath.query.LDPathFieldQueryImpl;
import org.apache.stanbol.entityhub.servicesapi.defaults.DataTypeEnum;
import org.apache.stanbol.entityhub.servicesapi.defaults.NamespaceEnum;
import org.apache.stanbol.entityhub.servicesapi.model.ValueFactory;
@@ -85,8 +87,7 @@ public class FieldQueryReader implements
acceptedType = MediaType.TEXT_PLAIN_TYPE;
}
try {
- return fromJSON(
- DefaultQueryFactory.getInstance(),
+ return fromJSON(
queryString,acceptedType);
} catch (JSONException e) {
log.error("Unable to parse Request ",e);
@@ -117,12 +118,19 @@ public class FieldQueryReader implements
* @throws JSONException
* @throws WebApplicationException
*/
- public static FieldQuery fromJSON(FieldQueryFactory queryFactory, String jsonQueryString,MediaType acceptedMediaType) throws JSONException,WebApplicationException{
+ public static FieldQuery fromJSON(String jsonQueryString,MediaType acceptedMediaType) throws JSONException,WebApplicationException{
if(jsonQueryString == null){
throw new IllegalArgumentException("The parsed JSON object MUST NOT be NULL!");
}
JSONObject jQuery = new JSONObject(jsonQueryString);
- FieldQuery query = queryFactory.createFieldQuery();
+ FieldQuery query;
+ if(jQuery.has("ldpath")){ //STANBOL-417: support for using LDPath as select
+ LDPathFieldQueryImpl ldPathQuery = new LDPathFieldQueryImpl();
+ ldPathQuery.setLDPathSelect(jQuery.getString("ldpath"));
+ query = ldPathQuery;
+ } else {
+ query = new FieldQueryImpl();
+ }
if(!jQuery.has("constraints")){
StringBuilder message = new StringBuilder();
message.append("The parsed Field Query MUST contain at least a single 'constraints'\n");
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource.java?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource.java (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource.java Thu Dec 15 11:13:30 2011
@@ -36,7 +36,10 @@ import static org.apache.clerezza.rdf.co
import static org.apache.clerezza.rdf.core.serializedform.SupportedFormat.X_TURTLE;
import static org.apache.stanbol.commons.web.base.CorsHelper.addCORSOrigin;
import static org.apache.stanbol.commons.web.base.CorsHelper.enableCORS;
+import static org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.getLDPathParseExceptionMessage;
import static org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.handleLDPathRequest;
+import static org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.prepairQueryLDPathProgram;
+import static org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.transformQueryResults;
import java.io.File;
import java.util.ArrayList;
@@ -48,7 +51,6 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-import javax.servlet.ServletContext;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
@@ -69,16 +71,21 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
import org.apache.stanbol.commons.web.base.ContextHelper;
import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
import org.apache.stanbol.entityhub.core.query.QueryResultListImpl;
import org.apache.stanbol.entityhub.jersey.utils.JerseyUtils;
-import org.apache.stanbol.entityhub.ldpath.backend.SiteBackend;
+import org.apache.stanbol.entityhub.ldpath.EntityhubLDPath;
+import org.apache.stanbol.entityhub.ldpath.backend.EntityhubBackend;
import org.apache.stanbol.entityhub.ldpath.backend.YardBackend;
+import org.apache.stanbol.entityhub.ldpath.query.LDPathSelect;
+import org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory;
import org.apache.stanbol.entityhub.servicesapi.Entityhub;
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.model.rdf.RdfResourceEnum;
import org.apache.stanbol.entityhub.servicesapi.query.FieldQuery;
import org.apache.stanbol.entityhub.servicesapi.query.QueryResultList;
@@ -86,6 +93,9 @@ import org.apache.stanbol.entityhub.serv
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import at.newmedialab.ldpath.exception.LDPathParseException;
+import at.newmedialab.ldpath.model.programs.Program;
+
import com.sun.jersey.api.view.Viewable;
@Path("/entityhub")
@@ -430,8 +440,9 @@ public class EntityhubRootResource exten
// Use this feature here instead of using this hand crafted
// solution!
@QueryParam(value = "select") String select,
+ @QueryParam(value = "ldpath") String ldpath,
@Context HttpHeaders headers) {
- return findEntity(name, field, language, limit, offset, select, headers);
+ return findEntity(name, field, language, limit, offset, select, ldpath, headers);
}
@POST
@@ -446,6 +457,7 @@ public class EntityhubRootResource exten
// Use this feature here instead of using this hand crafted
// solution!
@FormParam(value = "select") String select,
+ @FormParam(value = "ldpath") String ldpath,
@Context HttpHeaders headers) {
log.debug("/find Request");
final MediaType acceptedMediaType = JerseyUtils.getAcceptableMediaType(headers,
@@ -470,16 +482,14 @@ public class EntityhubRootResource exten
field = field.trim();
}
FieldQuery query = JerseyUtils.createFieldQueryForFindRequest(name, field, language,
- limit == null || limit < 1 ? DEFAULT_FIND_RESULT_LIMIT : limit, offset);
+ limit == null || limit < 1 ? DEFAULT_FIND_RESULT_LIMIT : limit, offset,ldpath);
// For the Entityhub we support to select additional fields for results
// of find requests. For the Sites and {site} endpoint this is currently
// deactivated because of very bad performance with OPTIONAL graph patterns
// in SPARQL queries.
Collection<String> additionalSelectedFields = new ArrayList<String>();
- if (select == null || select.isEmpty()) {
- additionalSelectedFields.addAll(DEFAULT_FIND_SELECTED_FIELDS);
- } else {
+ if (select != null && !select.isEmpty()) {
for (String selected : select.trim().split(" ")) {
if (selected != null && !selected.isEmpty()) {
additionalSelectedFields.add(selected);
@@ -542,18 +552,83 @@ public class EntityhubRootResource exten
*/
private Response executeQuery(FieldQuery query, HttpHeaders headers, MediaType acceptedMediaType) throws WebApplicationException {
Entityhub entityhub = ContextHelper.getServiceFromContext(Entityhub.class, servletContext);
- try {
- ResponseBuilder rb = Response.ok(entityhub.find(query));
+ if(query instanceof LDPathSelect && ((LDPathSelect)query).getLDPathSelect() != null){
+ //use the LDPath variant to process this query
+ return executeLDPathQuery(entityhub,query, ((LDPathSelect)query).getLDPathSelect(),
+ acceptedMediaType, headers);
+ } else { //use the default query execution
+ QueryResultList<Representation> result;
+ try {
+ result = entityhub.find(query);
+ } catch (EntityhubException e) {
+ String message = String.format("Exception while performing the " +
+ "FieldQuery on the EntityHub (message: %s)", e.getMessage());
+ log.error(message, e);
+ return Response.status(Status.INTERNAL_SERVER_ERROR)
+ .entity(message)
+ .header(HttpHeaders.ACCEPT, acceptedMediaType).build();
+ }
+ ResponseBuilder rb = Response.ok(result);
rb.header(HttpHeaders.CONTENT_TYPE, acceptedMediaType+"; charset=utf-8");
addCORSOrigin(servletContext, rb, headers);
return rb.build();
- } catch (EntityhubException e) {
- log.error("Exception while performing the FieldQuery on the EntityHub", e);
- log.error("Query:\n" + query);
- throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}
-
+ /**
+ * Execute a Query that uses LDPath to process results.
+ * @param query the query
+ * @param mediaType the mediaType for the response
+ * @param headers the http headers of the request
+ * @return the response
+ */
+ private Response executeLDPathQuery(Entityhub entityhub,FieldQuery query, String ldpathProgramString, MediaType mediaType, HttpHeaders headers) {
+ QueryResultList<Representation> result;
+ ValueFactory vf = new RdfValueFactory(new SimpleMGraph());
+ EntityhubBackend backend = new EntityhubBackend(entityhub);
+ EntityhubLDPath ldPath = new EntityhubLDPath(backend,vf);
+ //copy the selected fields, because we might need to delete some during
+ //the preparation phase
+ Set<String> selectedFields = new HashSet<String>(query.getSelectedFields());
+ //first prepare (only execute the query if the parameters are valid)
+ Program<Object> program;
+ try {
+ program = prepairQueryLDPathProgram(ldpathProgramString, selectedFields, backend, ldPath);
+ } catch (LDPathParseException e) {
+ log.warn("Unable to parse LDPath program used as select for Query:");
+ log.warn("FieldQuery: \n {}",query);
+ log.warn("LDPath: \n {}",((LDPathSelect)query).getLDPathSelect());
+ log.warn("Exception:",e);
+ return Response.status(Status.BAD_REQUEST)
+ .entity(("Unable to parse LDPath program (Messages: "+
+ getLDPathParseExceptionMessage(e)+")!\n"))
+ .header(HttpHeaders.ACCEPT, mediaType).build();
+ } catch (IllegalStateException e) {
+ log.warn("parsed LDPath program is not compatible with parsed Query!",e);
+ return Response.status(Status.BAD_REQUEST)
+ .entity(e.getMessage())
+ .header(HttpHeaders.ACCEPT, mediaType).build();
+ }
+ //2. execute the query
+ Iterator<Representation> resultIt;
+ try { // go directly to the yard and query there for Representations
+ resultIt = entityhub.getYard().findRepresentation(query).iterator();
+ } catch (EntityhubException e) {
+ String message = String.format("Exception while performing the " +
+ "FieldQuery on the EntityHub (message: %s)", e.getMessage());
+ log.error(message, e);
+ return Response.status(Status.INTERNAL_SERVER_ERROR)
+ .entity(message)
+ .header(HttpHeaders.ACCEPT, mediaType).build();
+ }
+ //process the results
+ Collection<Representation> transformedResults = transformQueryResults(resultIt, program,
+ selectedFields, ldPath, backend, vf);
+ result = new QueryResultListImpl<Representation>(query, transformedResults, Representation.class);
+ ResponseBuilder rb = Response.ok(result);
+ rb.header(HttpHeaders.CONTENT_TYPE, mediaType+"; charset=utf-8");
+ addCORSOrigin(servletContext, rb, headers);
+ return rb.build();
+ }
/*--------------------------------------------------------------------------
* Methods for EntityMappings
*--------------------------------------------------------------------------
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource.java?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource.java (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/ReferencedSiteRootResource.java Thu Dec 15 11:13:30 2011
@@ -34,12 +34,16 @@ import static org.apache.stanbol.entityh
import static org.apache.stanbol.entityhub.jersey.utils.JerseyUtils.REPRESENTATION_SUPPORTED_MEDIA_TYPES;
import static org.apache.stanbol.entityhub.jersey.utils.JerseyUtils.createFieldQueryForFindRequest;
import static org.apache.stanbol.entityhub.jersey.utils.JerseyUtils.getAcceptableMediaType;
+import static org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.getLDPathParseExceptionMessage;
import static org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.handleLDPathRequest;
+import static org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.prepairQueryLDPathProgram;
+import static org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.transformQueryResults;
import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
@@ -63,19 +67,26 @@ import javax.ws.rs.core.UriInfo;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
import org.apache.clerezza.rdf.ontologies.RDFS;
import org.apache.stanbol.commons.web.base.ContextHelper;
import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
+import org.apache.stanbol.entityhub.core.query.QueryResultListImpl;
+import org.apache.stanbol.entityhub.core.utils.AdaptingIterator;
import org.apache.stanbol.entityhub.jersey.parsers.FieldQueryReader;
import org.apache.stanbol.entityhub.jersey.utils.JerseyUtils;
+import org.apache.stanbol.entityhub.ldpath.EntityhubLDPath;
import org.apache.stanbol.entityhub.ldpath.backend.SiteBackend;
+import org.apache.stanbol.entityhub.ldpath.query.LDPathSelect;
import org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation;
import org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory;
import org.apache.stanbol.entityhub.servicesapi.defaults.NamespaceEnum;
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;
+import org.apache.stanbol.entityhub.servicesapi.query.QueryResultList;
import org.apache.stanbol.entityhub.servicesapi.site.License;
import org.apache.stanbol.entityhub.servicesapi.site.ReferencedSite;
import org.apache.stanbol.entityhub.servicesapi.site.ReferencedSiteException;
@@ -84,6 +95,9 @@ import org.apache.stanbol.entityhub.serv
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import at.newmedialab.ldpath.exception.LDPathParseException;
+import at.newmedialab.ldpath.model.programs.Program;
+
import com.sun.jersey.api.view.Viewable;
/**
@@ -298,8 +312,9 @@ public class ReferencedSiteRootResource
// @QueryParam(value="select") String select,
@QueryParam(value = "limit") @DefaultValue(value = "-1") int limit,
@QueryParam(value = "offset") @DefaultValue(value = "0") int offset,
+ @QueryParam(value = "ldpath") String ldpath,
@Context HttpHeaders headers) {
- return findEntity(name, field, language, limit, offset, headers);
+ return findEntity(name, field, language, limit, offset, ldpath, headers);
}
@POST
@@ -310,6 +325,7 @@ public class ReferencedSiteRootResource
// @FormParam(value="select") String select,
@FormParam(value = "limit") Integer limit,
@FormParam(value = "offset") Integer offset,
+ @FormParam(value = "ldpath") String ldpath,
@Context HttpHeaders headers) {
log.debug("site/{}/find Request",site.getId());
Collection<String> supported = new HashSet<String>(JerseyUtils.QUERY_RESULT_SUPPORTED_MEDIA_TYPES);
@@ -328,7 +344,6 @@ public class ReferencedSiteRootResource
.header(HttpHeaders.ACCEPT, acceptedMediaType).build();
}
}
- // process the optional search field parameter
if (field == null) {
field = DEFAULT_FIND_FIELD;
} else {
@@ -337,8 +352,10 @@ public class ReferencedSiteRootResource
field = DEFAULT_FIND_FIELD;
}
}
- return executeQuery(createFieldQueryForFindRequest(name, field, language,
- limit == null || limit < 1 ? DEFAULT_FIND_RESULT_LIMIT : limit, offset),
+ return executeQuery(createFieldQueryForFindRequest(
+ name, field, language,
+ limit == null || limit < 1 ? DEFAULT_FIND_RESULT_LIMIT : limit,
+ offset,ldpath),
headers);
}
@@ -389,19 +406,91 @@ public class ReferencedSiteRootResource
private Response executeQuery(FieldQuery query, HttpHeaders headers) throws WebApplicationException {
MediaType mediaType = getAcceptableMediaType(headers, ENTITY_SUPPORTED_MEDIA_TYPES,
APPLICATION_JSON_TYPE);
- try {
- ResponseBuilder rb = Response.ok(site.find(query));
+ if(query instanceof LDPathSelect && ((LDPathSelect)query).getLDPathSelect() != null){
+ //use the LDPath variant to process this query
+ return executeLDPathQuery(query, ((LDPathSelect)query).getLDPathSelect(),
+ mediaType, headers);
+ } else { //use the default query execution
+ QueryResultList<Representation> result;
+ try {
+ result = site.find(query);
+ } catch (ReferencedSiteException e) {
+ String message = String.format("Unable to Query Site '%s' (message: %s)",
+ site.getId(),e.getMessage());
+ log.error(message, e);
+ return Response.status(Status.INTERNAL_SERVER_ERROR)
+ .entity(message)
+ .header(HttpHeaders.ACCEPT, mediaType).build();
+ }
+ ResponseBuilder rb = Response.ok(result);
rb.header(HttpHeaders.CONTENT_TYPE, mediaType+"; charset=utf-8");
addCORSOrigin(servletContext, rb, headers);
return rb.build();
- } catch (ReferencedSiteException e) {
- log.error("ReferencedSiteException while accessing Site " +
- site.getConfiguration().getName() + " (id="
- + site.getId() + ")", e);
- throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
}
-
}
+
+ /**
+ * Execute a Query that uses LDPath to process results.
+ * @param query the query
+ * @param mediaType the mediaType for the response
+ * @param headers the http headers of the request
+ * @return the response
+ */
+ private Response executeLDPathQuery(FieldQuery query, String ldpathProgramString, MediaType mediaType, HttpHeaders headers) {
+ QueryResultList<Representation> result;
+ ValueFactory vf = new RdfValueFactory(new SimpleMGraph());
+ SiteBackend backend = new SiteBackend(site,vf);
+ EntityhubLDPath ldPath = new EntityhubLDPath(backend,vf);
+ //copy the selected fields, because we might need to delete some during
+ //the preparation phase
+ Set<String> selectedFields = new HashSet<String>(query.getSelectedFields());
+ //first prepare (only execute the query if the parameters are valid)
+ Program<Object> program;
+ try {
+ program = prepairQueryLDPathProgram(ldpathProgramString, selectedFields, backend, ldPath);
+ } catch (LDPathParseException e) {
+ log.warn("Unable to parse LDPath program used as select for Query:");
+ log.warn("FieldQuery: \n {}",query);
+ log.warn("LDPath: \n {}",((LDPathSelect)query).getLDPathSelect());
+ log.warn("Exception:",e);
+ return Response.status(Status.BAD_REQUEST)
+ .entity(("Unable to parse LDPath program (Messages: "+
+ getLDPathParseExceptionMessage(e)+")!\n"))
+ .header(HttpHeaders.ACCEPT, mediaType).build();
+ } catch (IllegalStateException e) {
+ log.warn("parsed LDPath program is not compatible with parsed Query!",e);
+ return Response.status(Status.BAD_REQUEST)
+ .entity(e.getMessage())
+ .header(HttpHeaders.ACCEPT, mediaType).build();
+ }
+ //2. execute the query
+ Iterator<Representation> resultIt;
+ try { // we need to adapt from Entity to Representation
+ resultIt = new AdaptingIterator<Entity,Representation>(site.findEntities(query).iterator(),
+ new AdaptingIterator.Adapter<Entity,Representation>() {
+ @Override
+ public Representation adapt(Entity value, Class<Representation> type) {
+ return value.getRepresentation();
+ }},Representation.class);
+ } catch (ReferencedSiteException e) {
+ String message = String.format("Unable to Query Site '%s' (message: %s)",
+ site.getId(),e.getMessage());
+ log.error(message, e);
+ return Response.status(Status.INTERNAL_SERVER_ERROR)
+ .entity(message)
+ .header(HttpHeaders.ACCEPT, mediaType).build();
+ }
+ //process the results
+ Collection<Representation> transformedResults = transformQueryResults(resultIt, program,
+ selectedFields, ldPath, backend, vf);
+ result = new QueryResultListImpl<Representation>(query, transformedResults, Representation.class);
+ ResponseBuilder rb = Response.ok(result);
+ rb.header(HttpHeaders.CONTENT_TYPE, mediaType+"; charset=utf-8");
+ addCORSOrigin(servletContext, rb, headers);
+ return rb.build();
+ }
+
+
/*
* LDPath support
*/
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource.java?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource.java (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/resource/SiteManagerRootResource.java Thu Dec 15 11:13:30 2011
@@ -19,6 +19,7 @@ package org.apache.stanbol.entityhub.jer
import static javax.ws.rs.HttpMethod.GET;
import static javax.ws.rs.HttpMethod.OPTIONS;
import static javax.ws.rs.HttpMethod.POST;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
import static javax.ws.rs.core.MediaType.TEXT_HTML;
import static org.apache.clerezza.rdf.core.serializedform.SupportedFormat.N3;
import static org.apache.clerezza.rdf.core.serializedform.SupportedFormat.N_TRIPLE;
@@ -28,11 +29,19 @@ import static org.apache.clerezza.rdf.co
import static org.apache.clerezza.rdf.core.serializedform.SupportedFormat.X_TURTLE;
import static org.apache.stanbol.commons.web.base.CorsHelper.addCORSOrigin;
import static org.apache.stanbol.commons.web.base.CorsHelper.enableCORS;
+import static org.apache.stanbol.entityhub.jersey.utils.JerseyUtils.ENTITY_SUPPORTED_MEDIA_TYPES;
+import static org.apache.stanbol.entityhub.jersey.utils.JerseyUtils.QUERY_RESULT_SUPPORTED_MEDIA_TYPES;
+import static org.apache.stanbol.entityhub.jersey.utils.JerseyUtils.getAcceptableMediaType;
+import static org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.getLDPathParseExceptionMessage;
import static org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.handleLDPathRequest;
+import static org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.prepairQueryLDPathProgram;
+import static org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.transformQueryResults;
+import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
@@ -46,6 +55,7 @@ import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
@@ -54,18 +64,32 @@ import javax.ws.rs.core.UriInfo;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
import org.apache.clerezza.rdf.ontologies.RDFS;
import org.apache.stanbol.commons.web.base.ContextHelper;
import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
+import org.apache.stanbol.entityhub.core.query.QueryResultListImpl;
+import org.apache.stanbol.entityhub.core.utils.AdaptingIterator;
import org.apache.stanbol.entityhub.jersey.utils.JerseyUtils;
+import org.apache.stanbol.entityhub.ldpath.EntityhubLDPath;
+import org.apache.stanbol.entityhub.ldpath.backend.SiteBackend;
import org.apache.stanbol.entityhub.ldpath.backend.SiteManagerBackend;
+import org.apache.stanbol.entityhub.ldpath.query.LDPathSelect;
+import org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory;
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;
+import org.apache.stanbol.entityhub.servicesapi.query.QueryResultList;
+import org.apache.stanbol.entityhub.servicesapi.site.ReferencedSiteException;
import org.apache.stanbol.entityhub.servicesapi.site.ReferencedSiteManager;
import org.codehaus.jettison.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import at.newmedialab.ldpath.exception.LDPathParseException;
+import at.newmedialab.ldpath.model.programs.Program;
+
import com.sun.jersey.api.view.Viewable;
/**
@@ -242,8 +266,9 @@ public class SiteManagerRootResource ext
// @QueryParam(value="select") String select,
@QueryParam(value = "limit") @DefaultValue(value = "-1") int limit,
@QueryParam(value = "offset") @DefaultValue(value = "0") int offset,
+ @QueryParam(value = "ldpath") String ldpath,
@Context HttpHeaders headers) {
- return findEntity(name, field, language, limit, offset, headers);
+ return findEntity(name, field, language, limit, offset, ldpath, headers);
}
@POST
@@ -254,6 +279,7 @@ public class SiteManagerRootResource ext
// @FormParam(value="select") String select,
@FormParam(value = "limit") Integer limit,
@FormParam(value = "offset") Integer offset,
+ @FormParam(value = "ldpath") String ldpath,
@Context HttpHeaders headers) {
log.debug("findEntity() Request");
Collection<String> supported = new HashSet<String>(JerseyUtils.QUERY_RESULT_SUPPORTED_MEDIA_TYPES);
@@ -280,14 +306,11 @@ public class SiteManagerRootResource ext
field = DEFAULT_FIND_FIELD;
}
}
- ReferencedSiteManager referencedSiteManager = ContextHelper.getServiceFromContext(
- ReferencedSiteManager.class, servletContext);
+
FieldQuery query = JerseyUtils.createFieldQueryForFindRequest(name, field, language,
- limit == null || limit < 1 ? DEFAULT_FIND_RESULT_LIMIT : limit, offset);
- ResponseBuilder rb = Response.ok(referencedSiteManager.find(query));
- rb.header(HttpHeaders.CONTENT_TYPE, acceptedMediaType+"; charset=utf-8");
- addCORSOrigin(servletContext, rb, headers);
- return rb.build();
+ limit == null || limit < 1 ? DEFAULT_FIND_RESULT_LIMIT : limit, offset,ldpath);
+ return executeQuery(ContextHelper.getServiceFromContext(
+ ReferencedSiteManager.class, servletContext), query, acceptedMediaType, headers);
}
@GET
@Path("/query")
@@ -330,12 +353,8 @@ public class SiteManagerRootResource ext
.header(HttpHeaders.ACCEPT, acceptedMediaType).build();
}
} else {
- ReferencedSiteManager referencedSiteManager = ContextHelper.getServiceFromContext(
- ReferencedSiteManager.class, servletContext);
- ResponseBuilder rb = Response.ok(referencedSiteManager.find(query));
- rb.header(HttpHeaders.CONTENT_TYPE, acceptedMediaType+"; charset=utf-8");
- addCORSOrigin(servletContext, rb, headers);
- return rb.build();
+ return executeQuery(ContextHelper.getServiceFromContext(
+ ReferencedSiteManager.class, servletContext), query, acceptedMediaType, headers);
}
}
/*
@@ -367,5 +386,83 @@ public class SiteManagerRootResource ext
return handleLDPathRequest(this,new SiteManagerBackend(referencedSiteManager),
ldpath, contexts, headers, servletContext);
}
-
+ /**
+ * Executes the query parsed by {@link #queryEntities(String, File, HttpHeaders)} or created based
+ * {@link #findEntity(String, String, String, int, int, HttpHeaders)}
+ *
+ * @param manager The {@link ReferencedSiteManager}
+ * @param query
+ * The query to execute
+ * @param headers the request headers
+ * @return the response (results of error)
+ */
+ private Response executeQuery(ReferencedSiteManager manager,
+ FieldQuery query, MediaType mediaType,
+ HttpHeaders headers) throws WebApplicationException {
+ if(query instanceof LDPathSelect && ((LDPathSelect)query).getLDPathSelect() != null){
+ //use the LDPath variant to process this query
+ return executeLDPathQuery(manager, query, ((LDPathSelect)query).getLDPathSelect(),
+ mediaType, headers);
+ } else { //use the default query execution
+ QueryResultList<Representation> result = manager.find(query);
+ ResponseBuilder rb = Response.ok(result);
+ rb.header(HttpHeaders.CONTENT_TYPE, mediaType+"; charset=utf-8");
+ addCORSOrigin(servletContext, rb, headers);
+ return rb.build();
+ }
+ }
+
+ /**
+ * Execute a Query that uses LDPath to process results.
+ * @param query the query
+ * @param mediaType the mediaType for the response
+ * @param headers the http headers of the request
+ * @return the response
+ */
+ private Response executeLDPathQuery(ReferencedSiteManager manager,FieldQuery query, String ldpathProgramString, MediaType mediaType, HttpHeaders headers) {
+ QueryResultList<Representation> result;
+ ValueFactory vf = new RdfValueFactory(new SimpleMGraph());
+ SiteManagerBackend backend = new SiteManagerBackend(manager);
+ EntityhubLDPath ldPath = new EntityhubLDPath(backend,vf);
+ //copy the selected fields, because we might need to delete some during
+ //the preparation phase
+ Set<String> selectedFields = new HashSet<String>(query.getSelectedFields());
+ //first prepare (only execute the query if the parameters are valid)
+ Program<Object> program;
+ try {
+ program = prepairQueryLDPathProgram(ldpathProgramString, selectedFields, backend, ldPath);
+ } catch (LDPathParseException e) {
+ log.warn("Unable to parse LDPath program used as select for a Query to the '/sites' endpoint:");
+ log.warn("FieldQuery: \n {}",query);
+ log.warn("LDPath: \n {}",((LDPathSelect)query).getLDPathSelect());
+ log.warn("Exception:",e);
+ return Response.status(Status.BAD_REQUEST)
+ .entity(("Unable to parse LDPath program (Messages: "+
+ getLDPathParseExceptionMessage(e)+")!\n"))
+ .header(HttpHeaders.ACCEPT, mediaType).build();
+ } catch (IllegalStateException e) {
+ log.warn("parsed LDPath program is not compatible with the Query " +
+ "parsed to the '/sites' endpoint!",e);
+ return Response.status(Status.BAD_REQUEST)
+ .entity(e.getMessage())
+ .header(HttpHeaders.ACCEPT, mediaType).build();
+ }
+ //2. execute the query
+ // we need to adapt from Entity to Representation
+ //TODO: should we add the metadata to the result?
+ Iterator<Representation> resultIt = new AdaptingIterator<Entity,Representation>(manager.findEntities(query).iterator(),
+ new AdaptingIterator.Adapter<Entity,Representation>() {
+ @Override
+ public Representation adapt(Entity value, Class<Representation> type) {
+ return value.getRepresentation();
+ }},Representation.class);
+ //process the results
+ Collection<Representation> transformedResults = transformQueryResults(resultIt, program,
+ selectedFields, ldPath, backend, vf);
+ result = new QueryResultListImpl<Representation>(query, transformedResults, Representation.class);
+ ResponseBuilder rb = Response.ok(result);
+ rb.header(HttpHeaders.CONTENT_TYPE, mediaType+"; charset=utf-8");
+ addCORSOrigin(servletContext, rb, headers);
+ return rb.build();
+ }
}
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/utils/JerseyUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/utils/JerseyUtils.java?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/utils/JerseyUtils.java (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/utils/JerseyUtils.java Thu Dec 15 11:13:30 2011
@@ -49,6 +49,7 @@ import javax.ws.rs.ext.MessageBodyReader
import org.apache.commons.io.IOUtils;
import org.apache.stanbol.entityhub.core.query.DefaultQueryFactory;
+import org.apache.stanbol.entityhub.ldpath.query.LDPathFieldQueryImpl;
import org.apache.stanbol.entityhub.servicesapi.model.Entity;
import org.apache.stanbol.entityhub.servicesapi.model.Representation;
import org.apache.stanbol.entityhub.servicesapi.query.FieldQuery;
@@ -205,7 +206,9 @@ public final class JerseyUtils {
* @throws IllegalArgumentException in case the parsed field is invalid. Callers
* of this method need to ensure that this parameter is set to an valid value.
*/
- public static FieldQuery createFieldQueryForFindRequest(String name, String field, String language, Integer limit, Integer offset) throws WebApplicationException, IllegalArgumentException{
+ public static FieldQuery createFieldQueryForFindRequest(String name, String field,
+ String language, Integer limit,
+ Integer offset, String ldpath) throws WebApplicationException, IllegalArgumentException{
if(name == null || name.trim().isEmpty()){
// This throws an WebApplicationException, because the search name is
// provided by the caller. So an empty or missing name is interpreted
@@ -232,15 +235,22 @@ public final class JerseyUtils {
log.debug(" > lang : " + language);
log.debug(" > limit : " + limit);
log.debug(" > offset: " + offset);
- FieldQuery query = queryFactory.createFieldQuery();
- if (language == null) {
+ log.debug(" > ldpath: " + ldpath);
+ FieldQuery query;
+ if(ldpath != null && !ldpath.isEmpty()){ //STANBOL-417
+ query = new LDPathFieldQueryImpl();
+ ((LDPathFieldQueryImpl)query).setLDPathSelect(ldpath);
+ } else { //if no LDPath is parsed select the default field
+ query = queryFactory.createFieldQuery();
+ Collection<String> selectedFields = new ArrayList<String>();
+ selectedFields.add(field); //select also the field used to find entities
+ query.addSelectedFields(selectedFields);
+ }
+ if (language == null || language.trim().isEmpty()) {
query.setConstraint(field, new TextConstraint(name, PatternType.wildcard, false));
} else {
query.setConstraint(field, new TextConstraint(name, PatternType.wildcard, false, language));
}
- Collection<String> selectedFields = new ArrayList<String>();
- selectedFields.add(field); //select also the field used to find entities
- query.addSelectedFields(selectedFields);
if (limit != null && limit > 0) {
query.setLimit(limit);
}
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/utils/LDPathHelper.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/utils/LDPathHelper.java?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/utils/LDPathHelper.java (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/utils/LDPathHelper.java Thu Dec 15 11:13:30 2011
@@ -2,11 +2,14 @@ package org.apache.stanbol.entityhub.jer
import static javax.ws.rs.core.MediaType.TEXT_HTML;
import static org.apache.stanbol.commons.web.base.CorsHelper.addCORSOrigin;
+import static org.apache.stanbol.entityhub.jersey.utils.LDPathHelper.RESULT_SCORE_MAPPING;
import static org.apache.stanbol.entityhub.ldpath.LDPathUtils.getReader;
import java.util.Collection;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
@@ -20,22 +23,46 @@ import javax.ws.rs.core.Response.Status;
import org.apache.clerezza.rdf.core.MGraph;
import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
import org.apache.stanbol.commons.web.base.resource.BaseStanbolResource;
+import org.apache.stanbol.entityhub.core.model.InMemoryValueFactory;
import org.apache.stanbol.entityhub.jersey.resource.EntityhubRootResource;
import org.apache.stanbol.entityhub.jersey.resource.ReferencedSiteRootResource;
import org.apache.stanbol.entityhub.jersey.resource.SiteManagerRootResource;
import org.apache.stanbol.entityhub.ldpath.EntityhubLDPath;
+import org.apache.stanbol.entityhub.ldpath.backend.AbstractBackend;
+import org.apache.stanbol.entityhub.ldpath.backend.SiteBackend;
import org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory;
+import org.apache.stanbol.entityhub.servicesapi.defaults.NamespaceEnum;
+import org.apache.stanbol.entityhub.servicesapi.model.Reference;
+import org.apache.stanbol.entityhub.servicesapi.model.Representation;
+import org.apache.stanbol.entityhub.servicesapi.model.ValueFactory;
+import org.apache.stanbol.entityhub.servicesapi.model.rdf.RdfResourceEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.sun.jersey.api.view.Viewable;
+import at.newmedialab.ldpath.LDPath;
import at.newmedialab.ldpath.api.backend.RDFBackend;
import at.newmedialab.ldpath.exception.LDPathParseException;
+import at.newmedialab.ldpath.model.fields.FieldMapping;
import at.newmedialab.ldpath.model.programs.Program;
+import at.newmedialab.ldpath.model.selectors.PropertySelector;
+import at.newmedialab.ldpath.model.transformers.DoubleTransformer;
public class LDPathHelper {
private static final Logger log = LoggerFactory.getLogger(LDPathHelper.class);
+
+ /**
+ * LDPath {@link FieldMapping} for the {@link RdfResourceEnum#resultScore}
+ * property used for the score of query results
+ */
+ public static final FieldMapping<Double,Object> RESULT_SCORE_MAPPING =
+ new FieldMapping<Double,Object>(RdfResourceEnum.resultScore.getUri(),
+ NamespaceEnum.xsd+"double", new PropertySelector<Object>(
+ InMemoryValueFactory.getInstance().createReference(
+ RdfResourceEnum.resultScore.getUri())),
+ new DoubleTransformer<Object>(), null);
+
/**
* Executes the LDPath program on the contexts stored in the backend and
* returns the result as an RDF graph
@@ -77,7 +104,7 @@ public class LDPathHelper {
* @param e the exception
* @return the info useful to replay in BAD_REQUEST responses
*/
- private static Map<String,String> getLDPathParseExceptionMessage(LDPathParseException e) {
+ public static Map<String,String> getLDPathParseExceptionMessage(LDPathParseException e) {
Map<String,String> messages = new LinkedHashMap<String,String>();
Throwable t = e;
do { // the real parsing error is in some cause ...
@@ -152,4 +179,95 @@ public class LDPathHelper {
addCORSOrigin(servletContext, rb, headers);
return rb.build();
}
+
+
+ /**
+ * Transform the results of a query
+ * @param resultIt The Iterator over the results
+ * @param program the LDPath {@link Program} to execute on the results
+ * @param selectedFields additional selected fields of the query
+ * @param ldPath the Entityhub LDPath
+ * @param backend the {@link AbstractBackend} mainly used to
+ * {@link AbstractBackend#addLocal(Representation) add representations} of
+ * the query to the local cache
+ * @param vf the {@link ValueFactory} used create {@link Reference}s for the
+ * String {@link Representation#getId() id}s of the {@link Representation} in
+ * the query results
+ * @return A collection with the transformed Representations in the processed
+ * order.
+ */
+ public static Collection<Representation> transformQueryResults(Iterator<Representation> resultIt,
+ Program<Object> program,
+ Set<String> selectedFields,
+ EntityhubLDPath ldPath,
+ AbstractBackend backend,
+ ValueFactory vf) {
+ Collection<Representation> transformedResults = new LinkedHashSet<Representation>();
+ while(resultIt.hasNext()){
+ Representation rep = resultIt.next();
+ backend.addLocal(rep); //add results to local cache
+ Representation transformed = ldPath.execute(vf.createReference(rep.getId()), program);
+ //also add additional selected fields
+ for(String selected : selectedFields){
+ Iterator<Object> values = rep.get(selected);
+ if(values != null){
+ while(values.hasNext()){
+ transformed.add(selected, values.next());
+ }
+ }
+ }
+ transformedResults.add(transformed);
+ }
+ return transformedResults;
+ }
+
+
+ /**
+ *
+ * @param ldpathProgram the LDPath program as string
+ * @param selectedFields the selected fields of the query
+ * @param backend the RDFBackend (only needed for logging)
+ * @param ldPath the {@link LDPath} used to parse the program.
+ * @return the pre-processed and validated program
+ * @throws LDPathParseException if the parsed LDPath program string is not
+ * valid
+ * @throws IllegalStateException if the fields selected by the LDPath
+ * program conflict with the fields selected by the query.
+ */
+ public static Program<Object> prepairQueryLDPathProgram(String ldpathProgram,
+ Set<String> selectedFields,
+ AbstractBackend backend,
+ EntityhubLDPath ldPath) throws LDPathParseException {
+ Program<Object> program = ldPath.parseProgram(getReader(ldpathProgram));
+
+ //We need to do two things:
+ // 1) ensure that no fields define by LDPath are also selected
+ StringBuilder conflicting = null;
+ // 2) add the field of the result score if not defined by LDPath
+ String resultScoreProperty = RdfResourceEnum.resultScore.getUri();
+ boolean foundRsultRankingField = false;
+ for(FieldMapping<?,Object> ldPathField : program.getFields()){
+ String field = ldPathField.getFieldName();
+ if(!foundRsultRankingField && resultScoreProperty.equals(field)){
+ foundRsultRankingField = true;
+ }
+ //remove from selected fields -> if we decide later that
+ //this should not be an BAD_REQUEST
+ if(selectedFields.remove(ldPathField.getFieldName())){
+ if(conflicting == null){
+ conflicting = new StringBuilder();
+ }
+ conflicting.append('\n').append(" > ")
+ .append(ldPathField.getPathExpression(backend));
+ }
+ }
+ if(conflicting != null){ //there are conflicts
+ throw new IllegalStateException("Selected Fields conflict with Fields defined by" +
+ "the LDPath program! Conflicts: "+conflicting.toString());
+ }
+ if(!foundRsultRankingField){ //if no mapping for the result score
+ program.addMapping(RESULT_SCORE_MAPPING); //add the default mapping
+ }
+ return program;
+ }
}
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/writers/FieldQueryToJSON.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/writers/FieldQueryToJSON.java?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/writers/FieldQueryToJSON.java (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/writers/FieldQueryToJSON.java Thu Dec 15 11:13:30 2011
@@ -22,6 +22,7 @@ import java.util.EnumSet;
import java.util.Set;
import java.util.Map.Entry;
+import org.apache.stanbol.entityhub.ldpath.query.LDPathSelect;
import org.apache.stanbol.entityhub.servicesapi.defaults.DataTypeEnum;
import org.apache.stanbol.entityhub.servicesapi.defaults.NamespaceEnum;
import org.apache.stanbol.entityhub.servicesapi.query.Constraint;
@@ -65,6 +66,11 @@ final class FieldQueryToJSON {
//if(query.getOffset() != 0){
jQuery.put("offset", query.getOffset());
//}
+ if(query instanceof LDPathSelect &&
+ ((LDPathSelect)query).getLDPathSelect() != null &&
+ !((LDPathSelect)query).getLDPathSelect().isEmpty()){
+ jQuery.put("ldpath", ((LDPathSelect)query).getLDPathSelect());
+ }
return jQuery;
}
Added: incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/static/style/entityhub.css
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/static/style/entityhub.css?rev=1214701&view=auto
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/static/style/entityhub.css (added)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/static/style/entityhub.css Thu Dec 15 11:13:30 2011
@@ -0,0 +1,38 @@
+/*
+* 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.
+*/
+.docu {
+ border: 1px solid #eee;
+ padding: 3px;
+
+}
+.docuTitle {
+ background: url("/static/home/images/foldable_unfolded.png");
+ background-repeat: no-repeat;
+ background-position: right;
+ cursor: pointer;
+}
+
+.collapsed .docuTitle {
+ background: url("/static/home/images/foldable_folded.png");
+ background-repeat: no-repeat;
+ background-position: right;
+ cursor: pointer;
+}
+.docu .collapsed .docuCollapsable {
+ margin: 5px;
+ display: none
+}
Propchange: incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/static/style/entityhub.css
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/imports/fieldquerydocumentation.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/imports/fieldquerydocumentation.ftl?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/imports/fieldquerydocumentation.ftl (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/imports/fieldquerydocumentation.ftl Thu Dec 15 11:13:30 2011
@@ -14,7 +14,16 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<h3>FieldQuery JSON format:</h3>
+<div class="docu">
+ <div class="collapsed">
+ <h3 id="fqDocTitle" class="docuTitle">
+ FieldQuery Documentation:</h3>
+ <script>
+ $("#fqDocTitle").click(function () {
+ $("#fqDocTitle").parent().toggleClass("collapsed");
+ });
+ </script>
+ <div class= "docuCollapsable">
<p> The <a href="http://svn.apache.org/repos/asf/incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/query/FieldQuery.java">
FieldQuery</a> is part of the java API defined in the
@@ -268,3 +277,6 @@ because otherwise the parsed value would
<p>Expected Results on DBPedia.org include Bill Clinton, George W. Bush and
Donald Trump.</p>
+ </div>
+ </div>
+</div>
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/imports/ldpathdocumentation.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/imports/ldpathdocumentation.ftl?rev=1214701&r1=1214700&r2=1214701&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/imports/ldpathdocumentation.ftl (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/imports/ldpathdocumentation.ftl Thu Dec 15 11:13:30 2011
@@ -14,7 +14,16 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<h3>LD Path Language:</h3>
+<div class="docu">
+ <div class="collapsed">
+ <h3 id="ldpathDocTitle" class="docuTitle">
+ LD Path Language Documentation:</h3>
+ <script>
+ $("#ldpathDocTitle").click(function () {
+ $("#ldpathDocTitle").parent().toggleClass("collapsed");
+ });
+ </script>
+ <div class="docuCollapsable">
<p><strong>NOTE:</strong> This only provides a short overview. A much more
complete <a href="http://code.google.com/p/ldpath/wiki/PathLanguage">
@@ -39,15 +48,29 @@ documentation</a> is also available on t
<p>Define fields in the search index to map to path definitions.</p>
-<pre><code>FIELDNAME = PATH :: FIELDTYPE FIELDCONF
+<pre><code>[FIELDNAME =] PATH [:: FIELDTYPE] [FIELDCONF]
</code></pre>
-<p>where PATH is an RDF path and FIELDTYPE is one of the available field types.
-FIELDCONF is an optional field configuration.</p>
+<p>where</p> <ul>
+<li> <strong>FIELDNAME</strong>: The name of the field used to store the values.
+If not provided the first element of the PATH is used as field name. If the PATH
+does not provide an unique field name (e.g. if unions or intersections are used)
+than FIELDNAME is required. This field supports '<{uri}>',
+'{prefix}:{localname}' as well as '{name}'.
+<li> <strong>PATH</strong>: the RDF path (see following sections)
+<li> <strong>FIELDTYPE</strong>: The data type for the selected values. Type
+conversions are supported (e.g. parsing numbers, dates ... from strings). If not
+present the selected values are not converted.
+<li> <strong>FIELDCONF</strong>: Allows to provide additional configurations for
+the field. Currently not used - and ignored - by the Entityhub.
+</ul>
-<p><em>Example:</em></p>
+<p><em>Examples:</em></p>
<pre><code>title = foaf:name :: xsd:string ;
+schema:name = rdfs:label[@en];
+geo:lat; geo:long;
+<urn:my.company:label.private> = skos:hiddenLabel;
</code></pre>
<h3>Path Selectors</h3>
@@ -123,3 +146,7 @@ title = fn:xpath("//head/title/text()",
content = fn:content(foaf:homepage) :: xsd:string ;</p></li></ul></li>
</code></pre></li>
</ul>
+
+ </div>
+ </div>
+</div>
Modified: incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource/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/EntityhubRootResource/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/EntityhubRootResource/find.ftl (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource/find.ftl Thu Dec 15 11:13:30 2011
@@ -19,6 +19,8 @@
<@common.page title="Entityhub Find" hasrestapi=false>
<#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/EntityhubRootResource/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/EntityhubRootResource/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/EntityhubRootResource/inc_find.ftl (original)
+++ incubator/stanbol/trunk/entityhub/jersey/src/main/resources/org/apache/stanbol/entityhub/jersey/templates/org/apache/stanbol/entityhub/jersey/resource/EntityhubRootResource/inc_find.ftl Thu Dec 15 11:13:30 2011
@@ -58,36 +58,79 @@ with 'Pari'.</p>
<h4>Test</h4>
-<p>Find symbol by searching for 'Paris' for the language 'de'.<br>
-<a href="#" onclick="findSymbol(); return false;">Go and find symbol</a>
-<form name="findSymbolForm" id="findSymbolForm" style="display: none">
- <input type="hidden" name="name" value="Paris">
- <input type="hidden" name="lang" value="de">
+<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>
-</p>
<script language="javascript">
-function findSymbol() {
- $("#findSymbolResult").hide();
- $("#findSymbolResultText").text("... waiting for results ...");
- $("#findSymbolResult").show();
+function startTestSearch() {
+ $("#testSearchResultText").text("... waiting for results ...");
+ $("#testSearchResult").show();
$.ajax({
- type: 'POST',
+ type: "POST",
+ beforeSend: function(req) {
+ req.setRequestHeader("Accept", $("#findOutputFormat").val());
+ },
url: "${it.publicBaseUri}entityhub/find",
- data: $("#findSymbolForm").serialize(),
+ data: $("#findForm").serialize(),
dataType: "text",
cache: false,
- success: function(data) {
- $("#findSymbolResultText").text(data);
+ success: function(result) {
+ $("#testSearchResultText").text(result);
},
error: function(jqXHR, textStatus, errorThrown) {
- $("#findSymbolResultText").text(jqXHR.statusText + " - " + jqXHR.responseText);
+ $("#testSearchResultText").text(jqXHR.statusText + " - " + jqXHR.responseText);
}
- });
+ });
}
</script>
-<div id="findSymbolResult" style="display: none">
-<p><a href="#" onclick="$('#findSymbolResult').hide(); return false;">Hide results</a>
-<pre id="findSymbolResultText">... waiting for results ...</pre>
+<div id="testSearchResult" style="display: none">
+<p><a href="#" onclick="$('#testSearchResult').hide(); return false;">Hide results</a>
+<pre id="testSearchResultText">... waiting for results ...</pre>
</div>