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 2012/05/07 12:32:10 UTC
svn commit: r1334950 [1/2] - in /incubator/stanbol/trunk:
cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/helper/
commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/format/
entityhub/generic/servicesapi/sr...
Author: rwesten
Date: Mon May 7 10:32:08 2012
New Revision: 1334950
URL: http://svn.apache.org/viewvc?rev=1334950&view=rev
Log:
fixes STANBOL-589:
* added Integration test
* added support for full text field similarity constraints (see also STANBOL-596)
* added similarity constraint to the Field Query documentation
fixes STANBOL-596 and STANBOL-597
* entityhub-query:fullText is now used for full text searches
* entityhub-query:references is now used for semantic context searches
* implementation for the SolrYard
* implementation for all SPARQL based components (EntitySearcher, ClerezzaYard)
* added integration-tests for both
* added this feature to the FieldQuery documentation
fixes STANBOL-595
* adds support for "any", "all" modes for ReferenceConstraint and ValueConstraint
* implementation for the SolrYard
* implementation for all SPARQL based components (EntitySearcher, ClerezzaYard)
* added integration-tests for both
* added this feature to the FieldQuery documentation
fixes STANBOL-600
* changed namespaces as defined in the issue
* old namespaces are still available with the prefixes "rick" and "rick-query"
* adapted also NamespaceEnums of other components.
* adapted integration-tests
NOTE: that existing Indexes will still use the old namespace for the entityRank. This includes the default dbpedia index.
However as a new dbpedia release should be available soon I decided to keeep for now the current default data index and only to create a new one after the next dbpedia release.
Added:
incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/defaults/SpecialFieldEnum.java (with props)
Modified:
incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/helper/NamespaceEnum.java
incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/format/NamespaceEnum.java
incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/defaults/DataTypeEnum.java
incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/defaults/NamespaceEnum.java
incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/model/rdf/RdfResourceEnum.java
incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/query/ReferenceConstraint.java
incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/query/ValueConstraint.java
incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/it/AssertEntityhubJson.java
incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/QueryTestBase.java
incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/QueryTestCase.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/ReferencedSiteRootResource.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/query/clerezza/src/main/java/org/apache/stanbol/entityhub/query/clerezza/SparqlQueryUtils.java
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/defaults/SolrConst.java
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrFieldMapper.java
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrQueryFactory.java
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/AssignmentEncoder.java
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/DataTypeEncoder.java
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/FieldEncoder.java
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/GeEncoder.java
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/GtEncoder.java
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/LangEncoder.java
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/LeEncoder.java
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/LtEncoder.java
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/RegexEncoder.java
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/queryencoders/WildcardEncoder.java
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/FieldMapper.java
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/model/IndexField.java
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/EncodedConstraintParts.java
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/IndexConstraintTypeEncoder.java
incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/query/QueryUtils.java
incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/DbpediaDefaultdataConstants.java
incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/EntityhubTest.java
incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/ldpath/DbpediaLDPathTest.java
incubator/stanbol/trunk/integration-tests/src/test/java/org/apache/stanbol/entityhub/it/query/DbpediaQueryTest.java
Modified: incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/helper/NamespaceEnum.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/helper/NamespaceEnum.java?rev=1334950&r1=1334949&r2=1334950&view=diff
==============================================================================
--- incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/helper/NamespaceEnum.java (original)
+++ incubator/stanbol/trunk/cmsadapter/servicesapi/src/main/java/org/apache/stanbol/cmsadapter/servicesapi/helper/NamespaceEnum.java Mon May 7 10:32:08 2012
@@ -33,8 +33,8 @@ import org.slf4j.LoggerFactory;
public enum NamespaceEnum {
// Namespaces defined by the entityhub
- entityhubModel("entityhub", "http://www.iks-project.eu/ontology/rick/model/"),
- entityhubQuery("entityhub-query", "http://www.iks-project.eu/ontology/rick/query/"),
+ entityhubModel("entityhub", "http://stanbol.apache.org/ontology/entityhub/entityhub#"),
+ entityhubQuery("entityhub-query", "http://stanbol.apache.org/ontology/entityhub/query#"),
// Namespaces defined by the CMS Adapter
cms("http://www.apache.org/stanbol/cms#"),
// First the XML Namespaces
Modified: incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/format/NamespaceEnum.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/format/NamespaceEnum.java?rev=1334950&r1=1334949&r2=1334950&view=diff
==============================================================================
--- incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/format/NamespaceEnum.java (original)
+++ incubator/stanbol/trunk/commons/web/base/src/main/java/org/apache/stanbol/commons/web/base/format/NamespaceEnum.java Mon May 7 10:32:08 2012
@@ -20,8 +20,16 @@ public enum NamespaceEnum {
// TODO: change the namespace as soon as STANBOL-3 defines a namespace to be used for stanbol
enhancer("http://fise.iks-project.eu/ontology/"),
+ @Deprecated
rickModel("http://www.iks-project.eu/ontology/rick/model/"),
+ @Deprecated
rickQuery("http://www.iks-project.eu/ontology/rick/query/"),
+ entityhub("http://stanbol.apache.org/ontology/entityhub/entityhub#"),
+ /**
+ * The namespace used by the Entityhub to define query related concepts
+ * e.g. the full text search field, semantic context field, result score ...
+ */
+ entityhubQuery("entityhub-query","http://stanbol.apache.org/ontology/entityhub/query#"),
atom("http://www.w3.org/2005/Atom"),
bio("dc-bio","http://purl.org/vocab/bio/0.1/"),
Modified: incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/defaults/DataTypeEnum.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/defaults/DataTypeEnum.java?rev=1334950&r1=1334949&r2=1334950&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/defaults/DataTypeEnum.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/defaults/DataTypeEnum.java Mon May 7 10:32:08 2012
@@ -63,8 +63,8 @@ import org.apache.stanbol.entityhub.serv
*/
public enum DataTypeEnum {
//Entityhub specific
- Reference(NamespaceEnum.entityhubModel,"ref",Reference.class),
- Text(NamespaceEnum.entityhubModel,"text",Text.class),
+ Reference(NamespaceEnum.entityhub,"ref",Reference.class),
+ Text(NamespaceEnum.entityhub,"text",Text.class),
//xsd types
/**
* currently URIs are preferable mapped to {@link Reference}, because there
Modified: incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/defaults/NamespaceEnum.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/defaults/NamespaceEnum.java?rev=1334950&r1=1334949&r2=1334950&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/defaults/NamespaceEnum.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/defaults/NamespaceEnum.java Mon May 7 10:32:08 2012
@@ -29,11 +29,32 @@ import org.slf4j.LoggerFactory;
*
*/
public enum NamespaceEnum {
-
+ /*
+ * STANBOL internally used Namespaces
+ */
+ /**
+ * The Stanbol Enhancer namespace defining Enhancer, EnhancementEngine and
+ * EnhancementChain. This is NOT the namespace of the enhancement structure.
+ * As EnhancementStrucutre up to now still the old FISE namespace is used.
+ */
+ enhancer("http://stanbol.apache.org/ontology/enhancer/enhancer#"),
//Namespaces defined by the entityhub
- entityhubModel("entityhub","http://www.iks-project.eu/ontology/rick/model/"),
- entityhubQuery("entityhub-query","http://www.iks-project.eu/ontology/rick/query/"),
-
+ /**
+ * The Namespace used by the Entityhub to define its concepts such as
+ * Entity, Representation ...
+ */
+ entityhub("http://stanbol.apache.org/ontology/entityhub/entityhub#"),
+ /**
+ * The namespace used by the Entityhub to define query related concepts
+ * e.g. the full text search field, semantic context field, result score ...
+ */
+ entityhubQuery("entityhub-query","http://stanbol.apache.org/ontology/entityhub/query#"),
+ /**
+ * The FISE namespace (1st version of the Enhancement Structure).
+ * Will be replaced by the Stanbol Enhancement Structure by a future
+ * release (see STANBOL-3).
+ */
+ fise("http://fise.iks-project.eu/ontology/"),
//First the XML Namespaces
xsd("http://www.w3.org/2001/XMLSchema#"),
@@ -144,7 +165,26 @@ public enum NamespaceEnum {
/**
* Expression of Core FRBR Concepts in RDF (http://vocab.org/frbr/core)
*/
- frbr("http://purl.org/vocab/frbr/core#")
+ frbr("http://purl.org/vocab/frbr/core#"),
+
+ /*
+ * Old namespaces still kept for historical reasons
+ */
+ /**
+ * The old URI for the 'entityhub' namespace prefix as used by STANBOL
+ * 0.9.0-incubating.
+ * @see NamespaceEnum#entityhubModel
+ */
+ @Deprecated
+ rickModel("rick","http://www.iks-project.eu/ontology/rick/model/"),
+ /**
+ * The old URI for the 'entityhub-query' namespace prefix as used by STANBOL
+ * 0.9.0-incubating.
+ * @see NamespaceEnum#entityhubQuery
+ */
+ @Deprecated
+ rickQuery("rick-query","http://www.iks-project.eu/ontology/rick/query/"),
+
;
/**
* The logger
Added: incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/defaults/SpecialFieldEnum.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/defaults/SpecialFieldEnum.java?rev=1334950&view=auto
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/defaults/SpecialFieldEnum.java (added)
+++ incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/defaults/SpecialFieldEnum.java Mon May 7 10:32:08 2012
@@ -0,0 +1,84 @@
+package org.apache.stanbol.entityhub.servicesapi.defaults;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.stanbol.entityhub.servicesapi.model.Reference;
+import org.apache.stanbol.entityhub.servicesapi.model.Text;
+import org.apache.stanbol.entityhub.servicesapi.model.rdf.RdfResourceEnum;
+import org.apache.stanbol.entityhub.servicesapi.yard.Yard;
+
+/**
+ * Enumeration that defines fields that need to be treated specially by
+ * the Stanbol Entityhub.<p>
+ * All those field do use the {@link NamespaceEnum#entityhubQuery} namespace.
+ * Entries of this enumeration are equals to the local name of the URIs.
+ * and are also defined by the {@link RdfResourceEnum}. This enumeration is
+ * intended to be used by {@link Yard} implementations to efficiently work with
+ * special fields (e.g. decide if a field is a special field)
+ * @author Rupert Westenthaler
+ */
+public enum SpecialFieldEnum {
+ /**
+ * The full text field. Union over all {@link Text} and String values
+ * of any outgoing relation
+ */
+ fullText,
+ /**
+ * The semantic context field. Union over all {@link Reference} values
+ * of any outgoing relation
+ */
+ references
+ ;
+
+ private final String uri;
+ private final String qname;
+
+ private SpecialFieldEnum(){
+ this.uri = NamespaceEnum.entityhubQuery.getNamespace()+name();
+ this.qname = NamespaceEnum.entityhubQuery.getPrefix()+name();
+ }
+
+ public String getUri(){
+ return uri;
+ }
+ public String getQName(){
+ return qname;
+ }
+ public NamespaceEnum getNamespace(){
+ return NamespaceEnum.entityhubQuery;
+ }
+
+ private static final Map<String,SpecialFieldEnum> name2field;
+ static {
+ Map<String,SpecialFieldEnum> map = new TreeMap<String,SpecialFieldEnum>();
+ for(SpecialFieldEnum specialField : SpecialFieldEnum.values()){
+ map.put(specialField.getUri(), specialField);
+ map.put(specialField.getUri(), specialField);
+ map.put(specialField.name(), specialField);
+ }
+ name2field = Collections.unmodifiableMap(map);
+ }
+ /**
+ * Checks if the parsed name (local name or qname or full URI) is a
+ * special field
+ * @param name the local name, qname or URI
+ * @return <code>true</code> if the parsed name references to a special field
+ * or otherwise <code>false</code>
+ */
+ public static final boolean isSpecialField(String name){
+ return getSpecialField(name) != null;
+ }
+
+ /**
+ * Getter for the {@link SpecialFieldEnum} for the parsed name
+ * (local name or qname or full URI)
+ * @param name the local name, qname or URI
+ * @return the {@link SpecialFieldEnum} or <code>null</code> if the parsed
+ * name does not refer to a special field.
+ */
+ public static SpecialFieldEnum getSpecialField(String name) {
+ return name2field.get(name);
+ }
+}
Propchange: incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/defaults/SpecialFieldEnum.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/model/rdf/RdfResourceEnum.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/model/rdf/RdfResourceEnum.java?rev=1334950&r1=1334949&r2=1334950&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/model/rdf/RdfResourceEnum.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/model/rdf/RdfResourceEnum.java Mon May 7 10:32:08 2012
@@ -17,6 +17,11 @@
package org.apache.stanbol.entityhub.servicesapi.model.rdf;
import org.apache.stanbol.entityhub.servicesapi.defaults.NamespaceEnum;
+import org.apache.stanbol.entityhub.servicesapi.defaults.SpecialFieldEnum;
+import org.apache.stanbol.entityhub.servicesapi.model.Entity;
+import org.apache.stanbol.entityhub.servicesapi.model.Reference;
+import org.apache.stanbol.entityhub.servicesapi.query.FieldQuery;
+import org.apache.stanbol.entityhub.servicesapi.yard.Yard;
public enum RdfResourceEnum {
/**
@@ -183,17 +188,32 @@ public enum RdfResourceEnum {
* Tells if an returned Entity represents an locally cached version
*/
isChached,
+// /**
+// * Full text search field. This can be used in {@link FieldQuery} to
+// * indicate that a constraint should be applied to the full text field.
+// * {@link Yard} implementations will need to specially treat this field
+// * (e.g. in SPARQL one need to use a variable instead if this URI)
+// * @see SpecialFieldEnum#fullText
+// */
+// fullTextField(null,"fullText"),
+// /**
+// * Field that contains all {@link Reference}s of an {@link Entity}. {@link Yard}
+// * implementation will need to treat this field specially. (e.g. in
+// * SPARQL one needs to use a variable as property instead of this URI).
+// * @see SpecialFieldEnum#references
+// */
+// referencesField(null,"references")
;
private String uri;
/**
* Initialise a new property by using the parse URI. If <code>null</code> is
* parsed, the URI is generated by using the Entityhub model namespace (
- * {@link NamespaceEnum#entityhubModel}).
+ * {@link NamespaceEnum#entityhub}).
* @param uri the uri of the element
*/
RdfResourceEnum(String uri) {
if(uri == null){
- this.uri = NamespaceEnum.entityhubModel+name();
+ this.uri = NamespaceEnum.entityhub+name();
}
this.uri = uri;
}
@@ -216,7 +236,7 @@ public enum RdfResourceEnum {
RdfResourceEnum(NamespaceEnum ns, String localName){
String uri;
if(ns == null){
- uri = NamespaceEnum.entityhubModel.getNamespace();
+ uri = NamespaceEnum.entityhub.getNamespace();
} else {
uri = ns.getNamespace();
}
@@ -228,7 +248,7 @@ public enum RdfResourceEnum {
this.uri = uri;
}
/**
- * Initialise a new property with {@link NamespaceEnum#entityhubModel}) as namespace
+ * Initialise a new property with {@link NamespaceEnum#entityhub}) as namespace
* and the {@link #name()} as local name.
*/
RdfResourceEnum(){
Modified: incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/query/ReferenceConstraint.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/query/ReferenceConstraint.java?rev=1334950&r1=1334949&r2=1334950&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/query/ReferenceConstraint.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/query/ReferenceConstraint.java Mon May 7 10:32:08 2012
@@ -37,7 +37,10 @@ public class ReferenceConstraint extends
this(reference != null ? Collections.singleton(reference) : null);
}
public ReferenceConstraint(Collection<String> references) {
- super(references,Arrays.asList(DataTypeEnum.Reference.getUri()));
+ this(references,null);
+ }
+ public ReferenceConstraint(Collection<String> references, MODE mode) {
+ super(references,Arrays.asList(DataTypeEnum.Reference.getUri()),mode);
if(references == null){
throw new IllegalArgumentException("Parsed Reference(s) MUST NOT be NULL");
}
Modified: incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/query/ValueConstraint.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/query/ValueConstraint.java?rev=1334950&r1=1334949&r2=1334950&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/query/ValueConstraint.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/servicesapi/src/main/java/org/apache/stanbol/entityhub/servicesapi/query/ValueConstraint.java Mon May 7 10:32:08 2012
@@ -22,6 +22,8 @@ import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
+import org.apache.stanbol.entityhub.servicesapi.query.ValueConstraint.MODE;
+
/**
* A constraint the filters/selects based on the value and/or the parsed
* dataTypes. A valid constraint MUST define a value OR valid data type. A
@@ -34,14 +36,36 @@ import java.util.Set;
*/
public class ValueConstraint extends Constraint {
-
+ /**
+ * The mode how multiple values are treated
+ */
+ public static enum MODE {
+ /**
+ * Any of the parsed values is sufficient to select an entity. Similar
+ * to UNION in SPARQL
+ */
+ any,
+ /**
+ * All parsed values must be present.
+ */
+ all
+ };
+ /**
+ * The default {@link MODE} is {@link MODE#any}
+ */
+ public static final MODE DEFAULT_MODE = MODE.any;
private final Set<Object> values;
private final Collection<String> dataTypeUris;
+ private final MODE mode;
+
public ValueConstraint(Object value) {
this(value,null);
}
public ValueConstraint(Object value,Iterable<String> dataTypes) {
+ this(value,dataTypes,null);
+ }
+ public ValueConstraint(Object value,Iterable<String> dataTypes,MODE mode) {
super(ConstraintType.value);
if(value == null){
this.values = null;
@@ -90,15 +114,7 @@ public class ValueConstraint extends Con
} else {
this.dataTypeUris = null;
}
- //it's questionable if we should do that at this position, because
- //components that process that constraint might have better ways to
- //do that and than they can not know if the user parsed a data type or
- //this code has calculated it based on the java type of the value!
-// if(dataTypeUris.isEmpty()){ //meaning value != null
-// for(DataTypeEnum dataType : DataTypeEnum.getAllDataTypes(value.getClass())){
-// dataTypeUris.add(dataType.getUri());
-// }
-// }
+ this.mode = mode == null ? DEFAULT_MODE : mode;
}
/**
* Getter for the first parsed value
@@ -115,6 +131,13 @@ public class ValueConstraint extends Con
return values;
}
/**
+ * Getter for the {@link MODE} of this ValueConstraint
+ * @return the mode
+ */
+ public MODE getMode() {
+ return mode;
+ }
+ /**
* Getter for the list of the parsed data types URIs
* @return the list of dataType URIs or an empty list if not defined.
*/
Modified: incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/it/AssertEntityhubJson.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/it/AssertEntityhubJson.java?rev=1334950&r1=1334949&r2=1334950&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/it/AssertEntityhubJson.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/it/AssertEntityhubJson.java Mon May 7 10:32:08 2012
@@ -33,6 +33,7 @@ import java.util.Map;
import java.util.Set;
import org.apache.stanbol.commons.testing.http.RequestExecutor;
+import org.apache.stanbol.entityhub.servicesapi.defaults.NamespaceEnum;
import org.apache.stanbol.entityhub.test.query.QueryTestCase;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
@@ -185,11 +186,11 @@ public class AssertEntityhubJson {
JSONObject jMetadata = jEntity.getJSONObject("metadata");
assertNotNull("Metadata is not an JSON Object",jMetadata);
Map<String,Set<List<String>>> metadata = assertRepresentation(jMetadata, Arrays.asList(
- "http://www.iks-project.eu/ontology/rick/model/isChached",
- "http://www.iks-project.eu/ontology/rick/model/about",
- "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"),null);
+ NamespaceEnum.entityhub+"isChached",
+ NamespaceEnum.entityhub+"about",
+ NamespaceEnum.rdf+"type"),null);
assertTrue("The Metadata of an Entity MUST BE about the Entity",
- metadata.get("http://www.iks-project.eu/ontology/rick/model/about")
+ metadata.get(NamespaceEnum.entityhub+"about")
.contains(Arrays.asList(id,"xsd:anyURI")));
return jEntity;
}
Modified: incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/QueryTestBase.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/QueryTestBase.java?rev=1334950&r1=1334949&r2=1334950&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/QueryTestBase.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/QueryTestBase.java Mon May 7 10:32:08 2012
@@ -30,6 +30,7 @@ import java.util.Map.Entry;
import org.apache.stanbol.commons.testing.http.Request;
import org.apache.stanbol.commons.testing.http.RequestExecutor;
+import org.apache.stanbol.entityhub.servicesapi.defaults.NamespaceEnum;
import org.apache.stanbol.entityhub.test.it.EntityhubTestBase;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
@@ -63,7 +64,7 @@ public abstract class QueryTestBase exte
private final Logger log = LoggerFactory.getLogger(getClass());
- public static final String RDFS_LABEL = "http://www.w3.org/2000/01/rdf-schema#label";
+ public static final String RDFS_LABEL = NamespaceEnum.rdfs+"label";
protected final String endpointPath;
/**
* Constructs a FieldQueryServiceTest
@@ -209,7 +210,7 @@ public abstract class QueryTestBase exte
"'text': 'Paris' " + //NOTE: here the comma is missing here!
"'patternType' : 'none', " +
"'field': 'http:\\/\\/www.test.org\\/test#field', " +
- "'dataTypes': ['http:\\/\\/www.iks-project.eu\\/ontology\\/rick\\/model\\/text'] " +
+ "'dataTypes': ['http:\\/\\/stanbol.apache.org\\/ontology\\/entityhub\\/entityhub#text'] " +
"}]" +
"}",
400); //expect BadRequest
@@ -238,7 +239,7 @@ public abstract class QueryTestBase exte
"'text': 'Paris', " +
"'patternType' : 'none', " +
"'field': '', " +
- "'dataTypes': ['http:\\/\\/www.iks-project.eu\\/ontology\\/rick\\/model\\/text'] " +
+ "'dataTypes': ['http:\\/\\/stanbol.apache.org\\/ontology\\/entityhub\\/entityhub#text'] " +
"}]" +
"}",
400); //expect BadRequest
@@ -269,7 +270,7 @@ public abstract class QueryTestBase exte
"'text': 'Paris', " +
"'patternType' : 'none', " +
"'field': 'http:\\/\\/www.test.org\\/test#field', " +
- "'dataTypes': ['http:\\/\\/www.iks-project.eu\\/ontology\\/rick\\/model\\/text'] " +
+ "'dataTypes': ['http:\\/\\/stanbol.apache.org\\/ontology\\/entityhub\\/entityhub#text'] " +
"},{ "+
"'type': 'reference', "+
"'field': 'http:\\/\\/www.test.org\\/test#field', "+
@@ -365,7 +366,7 @@ public abstract class QueryTestBase exte
"'text': 'Paris', " +
"'patternType' : 'none', " +
//"'field': 'http:\\/\\/www.test.org\\/test#field', " +
- "'dataTypes': ['http:\\/\\/www.iks-project.eu\\/ontology\\/rick\\/model\\/text'] " +
+ "'dataTypes': ['http:\\/\\/stanbol.apache.org\\/ontology\\/entityhub\\/entityhub#text'] " +
"}]" +
"}",
400); //expect BadRequest
Modified: incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/QueryTestCase.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/QueryTestCase.java?rev=1334950&r1=1334949&r2=1334950&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/QueryTestCase.java (original)
+++ incubator/stanbol/trunk/entityhub/generic/test/src/main/java/org/apache/stanbol/entityhub/test/query/QueryTestCase.java Mon May 7 10:32:08 2012
@@ -24,6 +24,8 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import org.apache.stanbol.entityhub.servicesapi.defaults.NamespaceEnum;
+
public abstract class QueryTestCase {
/**
@@ -31,7 +33,7 @@ public abstract class QueryTestCase {
*/
public static final Set<String> DEFAULT_RESULT_FIELDS =
Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(
- "http://www.iks-project.eu/ontology/rick/query/score")));
+ NamespaceEnum.entityhubQuery+"score")));
public static final Map<? extends String,? extends String> DEFAULT_HEADER;
static {
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=1334950&r1=1334949&r2=1334950&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 Mon May 7 10:32:08 2012
@@ -52,6 +52,7 @@ import org.apache.stanbol.entityhub.serv
import org.apache.stanbol.entityhub.servicesapi.query.TextConstraint;
import org.apache.stanbol.entityhub.servicesapi.query.TextConstraint.PatternType;
import org.apache.stanbol.entityhub.servicesapi.query.ValueConstraint;
+import org.apache.stanbol.entityhub.servicesapi.query.ValueConstraint.MODE;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
@@ -496,9 +497,9 @@ public class FieldQueryReader implements
private static Constraint parseValueConstraint(JSONObject jConstraint) throws JSONException {
Constraint constraint;
Collection<String> dataTypes = parseDatatypeProperty(jConstraint);
+ final List<Object> valueList;
if(jConstraint.has("value") && !jConstraint.isNull("value")){
Object value = jConstraint.get("value");
- final List<Object> valueList;
if(value instanceof JSONArray){
valueList = new ArrayList<Object>(((JSONArray)value).length());
for(int i=0;i<((JSONArray)value).length();i++){
@@ -526,7 +527,6 @@ public class FieldQueryReader implements
} else {
valueList = Collections.singletonList(jConstraint.get("value"));
}
- constraint = new ValueConstraint(valueList,dataTypes);
} else {
log.warn("Parsed ValueConstraint does not define the required field \"value\"!");
StringBuilder message = new StringBuilder();
@@ -535,7 +535,41 @@ public class FieldQueryReader implements
message.append(jConstraint.toString(4));
throw new IllegalArgumentException(message.toString());
}
- return constraint;
+ MODE mode = parseConstraintValueMode(jConstraint);
+ return new ValueConstraint(valueList,dataTypes,mode);
+ }
+
+ /**
+ * Parses the {@link MODE} for {@link ValueConstraint}s and
+ * {@link ReferenceConstraint}s, by evaluating the 'mode' attribute of
+ * the parsed {@link JSONObject}
+ * @param jConstraint the JSON formatted constraint
+ * @return the parsed {@link MODE} or <code>null</code> if the 'mode'
+ * attribute is not present
+ * @throws JSONException if the value of the 'mode' is not an element of the
+ * {@link MODE} enumeration.
+ */
+ private static MODE parseConstraintValueMode(JSONObject jConstraint) throws JSONException {
+ MODE mode;
+ if(jConstraint.has("mode")){
+ String jmode = jConstraint.getString("mode");
+ try {
+ mode = MODE.valueOf(jmode);
+ } catch (IllegalArgumentException e) {
+ String message = String.format("Parsed ValueConstraint defines an " +
+ "unknown MODE %s (supported: %s)!", jmode,
+ Arrays.asList(MODE.values()));
+ log.warn(message,e);
+ StringBuilder errorMessage = new StringBuilder();
+ errorMessage.append(message).append('\n');
+ errorMessage.append("Parsed Constraint: \n");
+ errorMessage.append(jConstraint.toString(4));
+ throw new IllegalArgumentException(message.toString(),e);
+ }
+ } else {
+ mode = null;
+ }
+ return mode;
}
/**
@@ -587,9 +621,9 @@ public class FieldQueryReader implements
*/
private static Constraint parseReferenceConstraint(JSONObject jConstraint) throws JSONException {
Constraint constraint;
+ final List<String> refList;
if(jConstraint.has("value") && !jConstraint.isNull("value")){
Object value = jConstraint.get("value");
- final List<String> refList;
if(value instanceof JSONArray){
refList = new ArrayList<String>(((JSONArray)value).length());
for(int i=0;i<((JSONArray)value).length();i++){
@@ -607,7 +641,8 @@ public class FieldQueryReader implements
} else {
refList = Collections.singletonList(NamespaceEnum.getFullName(jConstraint.getString("value")));
}
- constraint = new ReferenceConstraint(refList);
+ MODE mode = parseConstraintValueMode(jConstraint);
+ return new ReferenceConstraint(refList,mode);
} else {
log.warn("Parsed ReferenceConstraint does not define the required field \"value\"!");
StringBuilder message = new StringBuilder();
@@ -616,6 +651,5 @@ public class FieldQueryReader implements
message.append(jConstraint.toString(4));
throw new IllegalArgumentException(message.toString());
}
- return constraint;
}
}
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=1334950&r1=1334949&r2=1334950&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 Mon May 7 10:32:08 2012
@@ -532,7 +532,7 @@ public class ReferencedSiteRootResource
private Representation site2Representation(String id){
RdfValueFactory valueFactory = RdfValueFactory.getInstance();
RdfRepresentation rep = valueFactory.createRepresentation(id);
- String namespace = NamespaceEnum.entityhubModel.getNamespace();
+ String namespace = NamespaceEnum.entityhub.getNamespace();
rep.add(namespace+"localMode", site.supportsLocalMode());
rep.add(namespace+"supportsSearch", site.supportsSearch());
SiteConfiguration config = site.getConfiguration();
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=1334950&r1=1334949&r2=1334950&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 Mon May 7 10:32:08 2012
@@ -117,6 +117,10 @@ final class FieldQueryToJSON {
}
}
}
+ //finally write the MODE
+ if(valueConstraint.getMode() != null){
+ jConstraint.put("mode", valueConstraint.getMode());
+ }
break;
case text:
TextConstraint textConstraint = (TextConstraint) constraint;
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=1334950&r1=1334949&r2=1334950&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 Mon May 7 10:32:08 2012
@@ -31,16 +31,23 @@ FieldQuery</a> is part of the java API d
<h3>Main Elements</h3>
<ul>
- <li><code>"selected"</code>:
+ <li><b><code>"selected"</code></b>:
json array with the name of the fields selected by this query </li>
- <li><code>"offset"</code>:
+ <li><b><code>"offset"</code></b>:
the offset of the first result returned by this query </li>
- <li><code>"limit"</code>:
+ <li><b><code>"limit"</code></b>:
the maximum number of results returned </li>
- <li><code>"constraints"</code>:
+ <li><b><code>"constraints"</code></b>:
json array holding all the constraints of the query </li>
+ <li><b><code>"ldpath"</code></b>:
+ <a href="http://code.google.com/p/ldpath/wiki/PathLanguage">LDpath program </a>
+ that is executed for all results of the query. More powerful alternative
+ to the <code>"selected"</code> parameter to define returned information
+ for query results.</li>
</ul>
-<h4>Example:</h4>
+<h4>Examples:</h4>
+<p>Simple Field Query that selects rdfs:label and rdf:type with no offset
+that returns at max three results. Constraints are skipped</p>
<code><pre>
{
"selected": [
@@ -51,36 +58,61 @@ FieldQuery</a> is part of the java API d
"constraints": [...]
}
</pre></code>
+<p>The following example uses an LDPath program to select the rdfs:type and
+the rdfs:labels as schema:name. The offset is set to 5 and a maximum of 5 results
+are returned. This is similar the 2nd page if the number of items is set to 5. <p>
+<code><pre>
+{
+ "ldpath": "schema:name = rdfs:label;rdf:type;",
+ "offset": "5",
+ "limit": "5",
+ "constraints": [...]
+}
+</pre></code>
<h3>FieldQuery Constraints:</h3>
<p>Constraints are always applied to a field. Currently the implementation is
limited to a single constraint/field. This is an limitation of the implementation
and not a theoretical one.</p>
+
+<p>While there are five different Constraint types the following attributes
+are required by all types.</p>
+<ul>
+ <li><b><code>field</code></b>: the field to apply the constraint.</li>
+ <li><b><code>type</code></b>: the type of the constraint.
+ One of <code>"reference"</code>, <code>"value"</code>,
+ <code>"text"</code>, <code>"range"</code> or <code>"similarity"</code>
+ </li>
+</ul>
+
<p>There are 4 different constraint types.</p>
<ol>
- <li><em>ValueConstraint:</em> Checks if the value of the field is equals to the parsed
- value and data type</li>
- <li><em>TextConstraint:</em> Checks if the value of the field is equals to the parsed
- value, language. It supports also wildcard and regex searches.</li>
- <li><em>RangeConstraint:</em> Checks if the value of the field is within the parsed range</li>
- <li><em>ReferenceConstraint:</em> A special form of the ValueConstraint that defaults the
- data type to references (links to other entities)</li>
+ <li><em><a href="#value-constraint">ValueConstraint</a>:</em>
+ Checks if the value of the field is equals to the parsed
+ value and data type</li>
+ <li><em><a href="#reference-constraint">ReferenceConstraint</a>:</em>
+ A special form of the ValueConstraint that defaults the
+ data type to references (links to other entities)</li>
+ <li><em><a href="#text-constraint">TextConstraint</a>:</em>
+ Checks if the value of the field is equals to the parsed
+ value, language. It supports also wildcard and regex searches.</li>
+ <li><em><a href="#range-constraint">RangeConstraint</a>:</em>
+ Checks if the value of the field is within the parsed range</li>
+ <li><em><a href="#similarity-constraint">SimilarityConstraint</a>:</em>
+ Checks if the value of the field is within the parsed range</li>
</ol>
-<p>Keys required by all Constraint types:</p>
-<ul>
- <li><code>field</code>: the field to apply the constraint</li>
- <li><code>type</code>: the type of the constraint.
- One of <code>"reference"</code>, <code>"value"</code>,
- <code>"text"</code> or <code>"range"</code></li>
-</ul>
-<h3>Reference Constraint: </h3>
+<h3 id="reference-constraint">Reference Constraint: </h3>
<p>Additional key:</p>
<ul>
- <li><code>value</code>: the value (usually an URI) (required) </li>
+ <li><b><code>value</code></b>(required): the URI value(s). For a single value a
+ string can be used. Multiple values need to be parsed as JSON array</li>
+ <li><b><code>mode</code></b>: If multiple values are parsed this can be used
+ to specify if query results must have "<code>any</code>" or "<code>all</code>"
+ parsed values (default: "<code>any</code>")
</ul>
<h4>Example:</h4>
@@ -95,7 +127,26 @@ and not a theoretical one.</p>
}
</pre></code>
-<h3>Value Constraint</h3>
+<p id="reference-constraint-example2">
+Search Entities that link to all of the following Entities. NOTE that the
+field "<code>http://stanbol.apache.org/ontology/entityhub/query#references</code>
+is special as it will cause a search in any outgoing relation. See the section
+<a href="#special-fields">special fields</a> for details</p>
+
+<code><pre>
+{
+ "type": "reference",
+ "field": "http:\/\/stanbol.apache.org\/ontology\/entityhub\/query#references",
+ "value": [
+ "http:\/\/dbpedia.org\/resource\/Category:Capitals_in_Europe",
+ "http:\/\/dbpedia.org\/resource\/Category:Host_cities_of_the_Summer_Olympic_Games",
+ "http:\/\/dbpedia.org\/ontology\/City"
+ ],
+ "mode": "all"
+}
+</pre></code>
+
+<h3 id="value-constraint">Value Constraint</h3>
<p>Value Constraints are very similar to Reference Constraints however they can
be used to check values of fields for any data type.<br>
@@ -104,15 +155,20 @@ JSON type of the value. For details plea
<p>Additional keys:</p>
<ul>
- <li><code>value</code>: the value (required)</li>
- <li><code>datatype</code>: the data type of the value as a string. Multiple
- data types can also be parsed by using a JSON array.
+ <li><b><code>value</code></b>(required): the value(s). For multiple values
+ a JSON array must be used.</li>
+ <li><b><code>datatype</code></b>: the data type of the value as a string.
+ Multiple data types can also be parsed by using a JSON array.
Note that if no datatype is define, the default is guessed based on the
type of the parsed value. <br>
Especially note that string values are mapped to "xsd:string" and not
"entityhub:text" as used for natural language texts within the entityhub.
- However users are encouraged anyway to use Text Constraints for filtering
- based on natural languages values.</li>
+ Users that want to query for natural language text values should use
+ TextConstraints instead.</li>
+ <li><b><code>mode</code></b>: If multiple values are parsed this can be used
+ to specify if query results must have "<code>any</code>" or "<code>all</code>"
+ parsed values (default: "<code>any</code>"). For an usage example see the
+ <a href="#reference-constraint-example2"> 2nd reference constraint example</a>
</ul>
<h4>Example:</h4>
@@ -150,16 +206,16 @@ value. Note however that this would not
<p>Expected Results on DBPedia.org for this query include Berlin and Baghdad
</p>
-<h3>Text Constraint</h3>
+<h3 id="text-constraint">Text Constraint</h3>
<p>Additional key:</p>
<ul>
- <li><code>text</code>: the text to search (required). If multiple values
- are parsed, that those values are connected by using OR.<br>
- Parsing "Barack Obama" returns Entities that contain "Barack Obama" as
- value for the field. Parsing ["Barack","Obama"] will return all Entities
- that contain any of the two words. Most Sites however will boost results
- that contain both values over such that only contain a single one.
+ <li><b><code>text</code></b>(required): the text to search. Multiple values
+ can be parsed by using a JSON array. Note that multiple values are
+ considerd optional. (e.g. parsing "Barack Obama" returns Entities that
+ contain both "Barack" and "Obama" while parsing ["Barack","Obama"]
+ will also return documents with any of the two words; Also combinations
+ like ["Barack Obama","USA","United States"] are allowed)
</li>
<li><code>language</code>: the language of the searched text as string.
Multiple languages can be parsed as JSON array. Parsing "" as language
@@ -200,7 +256,7 @@ contains all the optional terms.
the Airport of Frankfurt am Main, Frankfurt as well as Airport.
</p>
-<h3>Range Constraint:</h3>
+<h3 id="range-constraint">Range Constraint:</h3>
<p>Additional key:</p>
<ul>
@@ -277,6 +333,66 @@ because otherwise the parsed value would
<p>Expected Results on DBPedia.org include Bill Clinton, George W. Bush and
Donald Trump.</p>
+
+<h3 id="similarity-constraint">Similarity Constraint: </h3>
+<p>This constaint allows to select entities similar to the parsed context. This
+constraint is curretly only supported by the Solr based storage of the Entityhub.
+It can not be implemented on storages that use SPARQL for search.<br>
+NOTE also that only a single Similarity Constraint can be used per Field Query.</p>
+<p>Additional key:</p>
+<ul>
+ <li><b><code>context</code></b>(required): The text used as context to search
+ for similar entities. Users can parse values form single words up to
+ the text of the current section or an whole document.</li>
+ <li><b><code>addFields</code></b>: This allows to parse additional fields
+ (properties) used for the similarity search. This fields will be added to
+ the value of the "<code>field</code>".
+</ul>
+
+<h4>Example:</h4>
+
+<p>This example combines a filter for Entities with the type Place with an
+similarity search for "Wolfgang Amadeus Mozart". The field
+<code>http://stanbol.apache.org/ontology/entityhub/query#fullText</code> is
+a <a href="#special-fields">special field</a> that allows to search the full
+text (all textual and <code>xsd:string</code> values) of an Entity.</p>
+
+<code><pre>
+{
+ "type": "reference",
+ "value": "http:\/\/dbpedia.org\/ontology\/Place",
+ "field": "http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#type",
+},
+{
+ "type": "similarity",
+ "context": "Wolfgang Amadeus Mozart",
+ "field": "http:\/\/stanbol.apache.org\/ontology\/entityhub\/query#fullText",
+}
+</pre></code>
+
+<p>Expected results with the default DBpedia dataset include Salzurg. However
+because the default dataset only includes the short rdfs:comment texts results
+of similarity searches are very limited. Typically the use of similarity
+searches needs already considered when indexing data sets.</p>
+
+<h3 id="special-fields">Special Fields</h3>
+
+<p>Currently the following special fields are defined</p>
+<ul>
+<li><b><code>http://stanbol.apache.org/ontology/entityhub/query#fullText</code></b>:
+ Allows to search within the all natuaral langauge and <code>xsd:string</code>
+ values that are linked with the Entity. This field is especially usefull for
+ <a href="#text-constraint">Text Constraints</a> and
+ <a href="#similarity-constraint">Similarity Constraint</a> searches.<br>
+ NOTE that for text queries language constrains may be ignored as the full text
+ field MAY NOT be able to support language constraints.</li>
+<li><b><code>http://stanbol.apache.org/ontology/entityhub/query#references</code></b>:
+ Allows to search far all entities referenced by this Entity. This includes
+ other entities and <code>xsd:anyURI</code> values (e.g. foaf:homepage values).
+ Because if this <a href="#reference-constraint">Reference Constraints</a>
+ applied to this field are queries for the semantic context of an Entity.</li>
+</ul>
+
</div>
</div>
</div>
Modified: incubator/stanbol/trunk/entityhub/query/clerezza/src/main/java/org/apache/stanbol/entityhub/query/clerezza/SparqlQueryUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/query/clerezza/src/main/java/org/apache/stanbol/entityhub/query/clerezza/SparqlQueryUtils.java?rev=1334950&r1=1334949&r2=1334950&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/query/clerezza/src/main/java/org/apache/stanbol/entityhub/query/clerezza/SparqlQueryUtils.java (original)
+++ incubator/stanbol/trunk/entityhub/query/clerezza/src/main/java/org/apache/stanbol/entityhub/query/clerezza/SparqlQueryUtils.java Mon May 7 10:32:08 2012
@@ -16,6 +16,8 @@
*/
package org.apache.stanbol.entityhub.query.clerezza;
+import static org.apache.stanbol.entityhub.servicesapi.defaults.SpecialFieldEnum.isSpecialField;
+
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -36,6 +38,8 @@ import org.apache.stanbol.entityhub.core
import org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation;
import org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory;
import org.apache.stanbol.entityhub.servicesapi.defaults.DataTypeEnum;
+import org.apache.stanbol.entityhub.servicesapi.defaults.NamespaceEnum;
+import org.apache.stanbol.entityhub.servicesapi.defaults.SpecialFieldEnum;
import org.apache.stanbol.entityhub.servicesapi.model.Reference;
import org.apache.stanbol.entityhub.servicesapi.model.rdf.RdfResourceEnum;
import org.apache.stanbol.entityhub.servicesapi.query.Constraint;
@@ -44,6 +48,7 @@ import org.apache.stanbol.entityhub.serv
import org.apache.stanbol.entityhub.servicesapi.query.TextConstraint;
import org.apache.stanbol.entityhub.servicesapi.query.ValueConstraint;
import org.apache.stanbol.entityhub.servicesapi.query.TextConstraint.PatternType;
+import org.apache.stanbol.entityhub.servicesapi.query.ValueConstraint.MODE;
import org.apache.stanbol.entityhub.servicesapi.util.PatternUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -505,20 +510,20 @@ public final class SparqlQueryUtils {
if(dataTypes.size()<=1){
addDataTypeValueConstraint(queryString, rootVarName, field,
dataTypes.isEmpty()?null:dataTypes.iterator().next(),
- constraint.getValues(),intend);
- } else { //we have multiple dataTypes -> ned to use union!
+ constraint.getValues(),constraint.getMode(),varPrefix,varNum,intend);
+ } else { //we have multiple dataTypes -> need to use union!
boolean first = true;
for(Iterator<String> it = dataTypes.iterator();it.hasNext();){
String dataType = it.next();
if(first){
- //queryString.append(intend);
+ queryString.append('{');
first = false;
} else {
- queryString.append(" UNION \n");
+ queryString.append("} UNION {\n");
}
- addDataTypeValueConstraint(queryString, rootVarName, field, dataType, constraint.getValues(),intend);
+ addDataTypeValueConstraint(queryString, rootVarName, field, dataType, constraint.getValues(),constraint.getMode(),varPrefix,varNum,intend);
}
- //queryString.append('}');
+ queryString.append('}');
}
} else { // no constraint for the value
// filter all instances that define any value for the given dataTypes
@@ -565,7 +570,7 @@ public final class SparqlQueryUtils {
* @param dataType the dataType constraint or <code>null</code> if none
* @param value the value. MUST NOT be <code>null</code>.
*/
- private static void addDataTypeValueConstraint(StringBuilder queryString, String rootVarName, String field, String dataType, Collection<Object> values, String intend) {
+ private static void addDataTypeValueConstraint(StringBuilder queryString, String rootVarName, String field, String dataType, Collection<Object> values,MODE mode, String varPrefix,int[] varNum,String intend) {
String addIntend = intend;
queryString.append(intend);
if(values.size() > 1){
@@ -575,29 +580,59 @@ public final class SparqlQueryUtils {
boolean first = true;
for(Object value : values){
if(first){
- //queryString.append(intend);
+ if(mode == MODE.any){
+ queryString.append('{');
+ }
first = false;
} else {
- queryString.append(" UNION\n").append(addIntend);
+ if(mode == MODE.any){
+ queryString.append("} UNION {\n");
+ } else {
+ queryString.append(" .\n");
+ }
+ queryString.append(addIntend);
+ }
+ String fieldVar;
+ if(isSpecialField(field)){
+ //in case of a special field replace the field URI with an
+ //variable to allow searching all outgoing properties
+ fieldVar = varPrefix+varNum[0];
+ varNum[0]++;
+ } else {
+ fieldVar = null;
}
if(DataTypeEnum.Reference.getUri().equals(dataType) ||
value instanceof Reference){
- queryString.append(String.format("?%s <%s> <%s>",
- rootVarName,field,value));
+ if(fieldVar != null){
+ queryString.append(String.format("?%s ?%s <%s>",
+ rootVarName,fieldVar,value));
+ } else {
+ queryString.append(String.format("?%s <%s> <%s>",
+ rootVarName,field,value));
+ }
} else {
- queryString.append(String.format("?%s <%s> \"%s\"%s",
- rootVarName,field,value,
+ if(fieldVar != null){
+ queryString.append(String.format("?%s ?%s \"%s\"%s",
+ rootVarName,fieldVar,value,
dataType!=null?String.format("^^<%s>",dataType):""));
+ } else {
+ queryString.append(String.format("?%s <%s> \"%s\"%s",
+ rootVarName,field,value,
+ dataType!=null?String.format("^^<%s>",dataType):""));
+ }
}
}
if(values.size() > 1){
+ if(mode == MODE.any){ //close the union
+ queryString.append('}');
+ }
queryString.append(" }");
}
}
/**
* Adds an text constraint to the SPARQL query string
* @param queryString the query string to add the constraint
- * @param var the variable name to constrain
+ * @param var the variable name to constraint
* @param constraint the constraint
* @param endpointType The type of the Endpoint (used to write optimized
* queries for endpoint type specific extensions
@@ -823,8 +858,17 @@ public final class SparqlQueryUtils {
var = varPrefix+varNum[0];
varNum[0]++;
}
- queryString.append(String.format("%s?%s <%s> ?%s ",
- intend,selectedFields.get(null),field,var));
+ if(isSpecialField(field)){
+ //in case of a special field replace the field URI with an
+ //variable to allow searching all outgoing properties
+ String fieldVar = varPrefix+varNum[0];
+ varNum[0]++;
+ queryString.append(String.format("%s?%s ?%s ?%s ",
+ intend,selectedFields.get(null),fieldVar,var));
+ } else {
+ queryString.append(String.format("%s?%s <%s> ?%s ",
+ intend,selectedFields.get(null),field,var));
+ }
return var;
}
@@ -876,8 +920,10 @@ public final class SparqlQueryUtils {
public static void main(String[] args) {
SparqlFieldQuery query = SparqlFieldQueryFactory.getInstance().createFieldQuery();
// query.setConstraint("urn:field1", new ReferenceConstraint("urn:testReference"));
- query.setConstraint("urn:field1", new ReferenceConstraint(
- Arrays.asList("urn:testReference","urn:testReference1","urn:testReference3")));
+// query.setConstraint("urn:field1", new ReferenceConstraint(
+// Arrays.asList("urn:testReference","urn:testReference1","urn:testReference3"),MODE.any));
+// query.setConstraint(SpecialFieldEnum.references.getUri(), new ReferenceConstraint(
+// Arrays.asList("urn:testReference","urn:testReference1","urn:testReference3")));
// query.setConstraint("urn:field1a", new ValueConstraint(null, Arrays.asList(
// DataTypeEnum.Float.getUri())));
// query.addSelectedField("urn:field1a");
@@ -885,7 +931,7 @@ public final class SparqlQueryUtils {
// query.setConstraint("urn:field1b", new ValueConstraint(9, Arrays.asList(
// DataTypeEnum.Float.getUri())));
// query.setConstraint("urn:field1b", new ValueConstraint(Arrays.asList(9,10,11), Arrays.asList(
-// DataTypeEnum.Float.getUri())));
+// DataTypeEnum.Float.getUri()),MODE.any));
// query.setConstraint("urn:field1c", new ValueConstraint(null, Arrays.asList(
// DataTypeEnum.Float.getUri(),DataTypeEnum.Double.getUri(),DataTypeEnum.Decimal.getUri())));
// query.addSelectedField("urn:field1c");
@@ -896,6 +942,8 @@ public final class SparqlQueryUtils {
// query.setConstraint("urn:field2", new TextConstraint("test value"));
// query.setConstraint("urn:field3", new TextConstraint(Arrays.asList(
// "text value","anothertest","some more values"),true));
+// query.setConstraint(SpecialFieldEnum.fullText.getUri(), new TextConstraint(Arrays.asList(
+// "text value","anothertest","some more values"),true));
// query.setConstraint("urn:field2a", new TextConstraint(":-]")); //tests escaping of REGEX
// query.setConstraint("urn:field3", new TextConstraint("language text","en"));
// query.setConstraint("urn:field4", new TextConstraint("multi language text","en","de",null));
Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/defaults/SolrConst.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/defaults/SolrConst.java?rev=1334950&r1=1334949&r2=1334950&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/defaults/SolrConst.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/defaults/SolrConst.java Mon May 7 10:32:08 2012
@@ -83,7 +83,14 @@ public final class SolrConst {
* updated.
*/
public static final String DEPENDENT_DOCUMENT_FIELD = SPECIAL_FIELD_PREFIX + "dep";
-
+ /**
+ * The field indexing all textual values of an Entity.<p>
+ * This field is created by copyfield configurations in the Solr schema.xml
+ */
+ public static final String FULL_TEXT_FIELD = SPECIAL_FIELD_PREFIX + "text";
+ /**
+ * Prefix used for fields that store meta information about the index.
+ */
public static final String SPECIAL_CONFIG_FIELD = SPECIAL_FIELD_PREFIX + "config";
/**
* The name of the field that indicates the domain of a document.
Modified: incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrFieldMapper.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrFieldMapper.java?rev=1334950&r1=1334949&r2=1334950&view=diff
==============================================================================
--- incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrFieldMapper.java (original)
+++ incubator/stanbol/trunk/entityhub/yard/solr/src/main/java/org/apache/stanbol/entityhub/yard/solr/impl/SolrFieldMapper.java Mon May 7 10:32:08 2012
@@ -19,6 +19,7 @@ package org.apache.stanbol.entityhub.yar
import static org.apache.stanbol.entityhub.yard.solr.defaults.SolrConst.DEPENDENT_DOCUMENT_FIELD;
import static org.apache.stanbol.entityhub.yard.solr.defaults.SolrConst.DOCUMENT_ID_FIELD;
import static org.apache.stanbol.entityhub.yard.solr.defaults.SolrConst.DOMAIN_FIELD;
+import static org.apache.stanbol.entityhub.yard.solr.defaults.SolrConst.FULL_TEXT_FIELD;
import static org.apache.stanbol.entityhub.yard.solr.defaults.SolrConst.PATH_SEPERATOR;
import static org.apache.stanbol.entityhub.yard.solr.defaults.SolrConst.REFERRED_DOCUMENT_FIELD;
import static org.apache.stanbol.entityhub.yard.solr.defaults.SolrConst.SPECIAL_CONFIG_FIELD;
@@ -46,15 +47,14 @@ import org.apache.solr.common.SolrExcept
import org.apache.solr.common.SolrInputDocument;
import org.apache.stanbol.commons.solr.utils.SolrUtil;
import org.apache.stanbol.entityhub.servicesapi.defaults.NamespaceEnum;
+import org.apache.stanbol.entityhub.servicesapi.defaults.SpecialFieldEnum;
import org.apache.stanbol.entityhub.servicesapi.model.rdf.RdfResourceEnum;
import org.apache.stanbol.entityhub.servicesapi.util.ModelUtils;
import org.apache.stanbol.entityhub.yard.solr.defaults.IndexDataTypeEnum;
import org.apache.stanbol.entityhub.yard.solr.defaults.SolrConst;
import org.apache.stanbol.entityhub.yard.solr.model.FieldMapper;
-import org.apache.stanbol.entityhub.yard.solr.model.IndexDataType;
import org.apache.stanbol.entityhub.yard.solr.model.IndexField;
import org.apache.stanbol.entityhub.yard.solr.model.IndexValue;
-import org.apache.stanbol.entityhub.yard.solr.query.QueryUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -321,25 +321,41 @@ public class SolrFieldMapper implements
}
Collection<String> fieldNames = indexFieldMappings.get(indexField);
if (fieldNames == null) {
- IndexDataTypeEnum dataTypeConfig = IndexDataTypeEnum.forIndexType(indexField.getDataType());
- if (dataTypeConfig == null) {
- throw new IllegalStateException(String.format(
- "No Config found for the parsed IndexDataType %s", indexField.getDataType()));
- }
- fieldNames = new HashSet<String>();
- // Three things need to be done
- // 1) Encode the Path
- String pathName = encodePathName(indexField.getPath());
- // 2) Encode the DataType
- fieldNames.addAll(encodeDataType(pathName, dataTypeConfig));
- // 3) Encode the Languages
- if (indexField.hasLanguage()) {
- fieldNames.addAll(encodeLanguages(pathName, indexField.getLanguages()));
- }
- // 4) add the language merger field (in case the dataType represent natural
- // language texts)
- if (dataTypeConfig.isLanguageType()) {
- fieldNames.add(SolrConst.LANG_MERGER_FIELD + pathName);
+ SpecialFieldEnum specialField = indexField.getSpecialField();//check for special field;
+ if(specialField != null){
+ switch (specialField) {
+ case fullText:
+ fieldNames = Collections.singleton(getFullTextSearchField());
+ break;
+ case references:
+ fieldNames = Collections.singleton(getReferredDocumentField());
+ default:
+ throw new IllegalStateException("Unsupported Special Field '"
+ +specialField.getUri()+"! Please report this to the "
+ + "Stanbol Developer Mailing list or create an according"
+ + "JIRA issue at https://issues.apache.org/jira/browse/STANBOL!");
+ }
+ } else {
+ fieldNames = new HashSet<String>(2); //typically onle 1 or 2 values
+ IndexDataTypeEnum dataTypeConfig = IndexDataTypeEnum.forIndexType(indexField.getDataType());
+ if (dataTypeConfig == null) {
+ throw new IllegalStateException(String.format(
+ "No Config found for the parsed IndexDataType %s", indexField.getDataType()));
+ }
+ // Three things need to be done
+ // 1) Encode the Path
+ String pathName = encodePathName(indexField);
+ // 2) Encode the DataType
+ fieldNames.addAll(encodeDataType(pathName, dataTypeConfig));
+ // 3) Encode the Languages
+ if (indexField.hasLanguage()) {
+ fieldNames.addAll(encodeLanguages(pathName, indexField.getLanguages()));
+ }
+ // 4) add the language merger field (in case the dataType represent natural
+ // language texts)
+ if (dataTypeConfig.isLanguageType()) {
+ fieldNames.add(SolrConst.LANG_MERGER_FIELD + pathName);
+ }
}
// cache the mappings
indexFieldMappings.put(indexField, fieldNames);
@@ -352,42 +368,64 @@ public class SolrFieldMapper implements
* within the path with <code>prefix+NAMESPACE_PREFIX_SEPERATOR_CHAR+localName</code>. In addition it
* places the <code>PATH_SEPERATOR</code> char between the elements.
* <p>
- * NOTE: This Method assumes that both Parameters are not NULL and that the Path is not empty and contains
- * no NULL nor emtpy element!
- *
+ * NOTES: <ul>
+ * <li>This Method assumes that no empty or <code>null</code> elements are
+ * containted in the parsed list.
+ * <li>This Method supports special encoding of fields registered in the
+ * {@link SpecialFieldEnum}. However those fields are only allowed to be
+ * used in paths with the length <code>1</code>.
+ * An {@link IllegalArgumentException} is thrown if a special field is used
+ * in a longer path.
+ * </ul>
* @param path
* the path to encode
* @return the path name
- */
- private String encodePathName(List<String> path) {
- StringBuilder pathName = new StringBuilder();
- // Now Iterate over the Path
- pathName.append(PATH_SEPERATOR); // add the leading PathSeperator
- Iterator<String> fields = path.iterator();
- while (fields.hasNext()) {
- String field = fields.next();
- // PathElement element = it.next();
- String[] namespaceLocalName = ModelUtils.getNamespaceLocalName(field);
- // QName qName = getQName(field);
- if (namespaceLocalName[0] != null && !namespaceLocalName[0].isEmpty()) {
- pathName.append(getPrefix(namespaceLocalName[0], true));
- // second the local name
- pathName.append(NAMESPACE_PREFIX_SEPERATOR_CHAR);
- }
- pathName.append(namespaceLocalName[1]);
- // third add Path Separator if there are additional Elements
- if (fields.hasNext()) {
- pathName.append(PATH_SEPERATOR);
- }
- }
- pathName.append(PATH_SEPERATOR); // add the tailing PathSeperator
- return pathName.toString();
+ * @throws IllegalArgumentException if <code>null</code> or an empty list is
+ * parsed as path or a special field is used in a path with a length > 1
+ * @throws IllegalStateException if an unknown {@link SpecialFieldEnum
+ * special field} is encountered.
+ */
+ private String encodePathName(IndexField indexField) {
+ SpecialFieldEnum specialField = indexField.getSpecialField();
+ if(specialField != null){ //handel special fields
+ switch (specialField) {
+ case fullText:
+ return getFullTextSearchField();
+ case references:
+ return getReferredDocumentField();
+ default:
+ throw new IllegalStateException("Unsupported Special Field '"
+ + specialField.getUri()+"'! Please report this to"
+ + "the Apache Stanbol Developer Mailing List!");
+ }
+ } else { //normal field
+ StringBuilder pathName = new StringBuilder();
+ // Now Iterate over the Path
+ pathName.append(PATH_SEPERATOR); // add the leading PathSeperator
+ Iterator<String> fields = indexField.getPath().iterator();
+ while (fields.hasNext()) {
+ String field = fields.next();
+ String[] namespaceLocalName = ModelUtils.getNamespaceLocalName(field);
+ // QName qName = getQName(field);
+ if (namespaceLocalName[0] != null && !namespaceLocalName[0].isEmpty()) {
+ pathName.append(getPrefix(namespaceLocalName[0], true));
+ // second the local name
+ pathName.append(NAMESPACE_PREFIX_SEPERATOR_CHAR);
+ }
+ pathName.append(namespaceLocalName[1]);
+ // third add Path Separator if there are additional Elements
+ if (fields.hasNext()) {
+ pathName.append(PATH_SEPERATOR);
+ }
+ }
+ pathName.append(PATH_SEPERATOR); // add the tailing PathSeperator
+ return pathName.toString();
+ }
}
@Override
- public String encodePath(List<String> path) throws IllegalArgumentException {
- IndexField.validatePath(path);
- return encodePathName(path);
+ public String encodePath(IndexField indexField) throws IllegalArgumentException {
+ return encodePathName(indexField);
}
/**
@@ -415,11 +453,11 @@ public class SolrFieldMapper implements
}
@Override
- public String[] encodeDataType(IndexDataType dataType) throws IllegalArgumentException {
- IndexDataTypeEnum dataTypeConfig = IndexDataTypeEnum.forIndexType(dataType);
+ public String[] encodeDataType(IndexField indexField) throws IllegalArgumentException {
+ IndexDataTypeEnum dataTypeConfig = IndexDataTypeEnum.forIndexType(indexField.getDataType());
if (dataTypeConfig == null) {
throw new IllegalStateException(String.format("No Config found for the parsed IndexDataType %s",
- dataType));
+ indexField.getDataType()));
}
return encodeDataType(dataTypeConfig);
}
@@ -470,6 +508,10 @@ public class SolrFieldMapper implements
}
}
+ @Override
+ public Collection<String> encodeLanguages(IndexField indexField) {
+ return encodeLanguages(indexField.getLanguages());
+ }
/**
* Internally used instead of {@link #encodeLanguages(String...)}
*
@@ -478,7 +520,7 @@ public class SolrFieldMapper implements
* @return the prefixes
* @see FieldMapper#encodeLanguages(String...)
*/
- public Collection<String> encodeLanguages(Collection<String> languages) {
+ private Collection<String> encodeLanguages(Collection<String> languages) {
if (languages == null || languages.isEmpty()) { // no language
return Collections.emptySet();// just return the field
} else if (languages.size() == 1) {
@@ -532,6 +574,10 @@ public class SolrFieldMapper implements
public String getDependentDocumentField() {
return DEPENDENT_DOCUMENT_FIELD;
}
+ @Override
+ public String getFullTextSearchField() {
+ return FULL_TEXT_FIELD;
+ }
/*--------------------------------------------------------------------------
* Helper Methods to store/read the Mapping Config within the index.