Author: rwesten
Date: Thu Jun 13 09:12:59 2013
New Revision: 1492586

URL: http://svn.apache.org/r1492586
Log:
STANBOL-1105, STANBOL-1106: Added proximity ranking and boost features support 
to the JSON parser/serializer for FieldQueries; Also updated the FieldQuery 
documetnation accordingly

Modified:
    stanbol/trunk/entityhub/jersey/pom.xml
    
stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/parsers/FieldQueryReader.java
    
stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/writers/FieldQueryToJSON.java
    
stanbol/trunk/entityhub/jersey/src/main/resources/templates/imports/fieldquerydocumentation.ftl

Modified: stanbol/trunk/entityhub/jersey/pom.xml
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/entityhub/jersey/pom.xml?rev=1492586&r1=1492585&r2=1492586&view=diff
==============================================================================
--- stanbol/trunk/entityhub/jersey/pom.xml (original)
+++ stanbol/trunk/entityhub/jersey/pom.xml Thu Jun 13 09:12:59 2013
@@ -109,6 +109,11 @@
     <!-- dependencies on other Entityhub modules -->
     <dependency>
       <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.entityhub.servicesapi</artifactId>
+      <version>0.12.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.stanbol</groupId>
       <artifactId>org.apache.stanbol.entityhub.core</artifactId>
       <version>0.11.0</version>
     </dependency>

Modified: 
stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/parsers/FieldQueryReader.java
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/parsers/FieldQueryReader.java?rev=1492586&r1=1492585&r2=1492586&view=diff
==============================================================================
--- 
stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/parsers/FieldQueryReader.java
 (original)
+++ 
stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/parsers/FieldQueryReader.java
 Thu Jun 13 09:12:59 2013
@@ -266,6 +266,7 @@ public class FieldQueryReader implements
     }
 
     private static Constraint parseConstraint(JSONObject jConstraint, 
NamespacePrefixService nsPrefixService) throws JSONException {
+        final Constraint constraint;
         if(jConstraint.has("type") && !jConstraint.isNull("type")) {
             String type = jConstraint.getString("type");
             //Event that internally "reference" is not part of the
@@ -274,15 +275,15 @@ public class FieldQueryReader implements
             //Value constraints with the dataType Reference and AnyURI are
             //considered to represent reference constraints
             if(type.equals("reference")){
-                return parseReferenceConstraint(jConstraint,nsPrefixService);
+                constraint = 
parseReferenceConstraint(jConstraint,nsPrefixService);
             } else if (type.equals(ConstraintType.value.name())){
-                return parseValueConstraint(jConstraint, nsPrefixService);
+                constraint = parseValueConstraint(jConstraint, 
nsPrefixService);
             } else if (type.equals(ConstraintType.text.name())){
-                return parseTextConstraint(jConstraint);
+                constraint = parseTextConstraint(jConstraint);
             } else if (type.equals(ConstraintType.range.name())){
-                return parseRangeConstraint(jConstraint,nsPrefixService);
+                constraint = parseRangeConstraint(jConstraint,nsPrefixService);
             } else if(type.equals(ConstraintType.similarity.name())){
-                return parseSimilarityConstraint(jConstraint, nsPrefixService);
+                constraint = parseSimilarityConstraint(jConstraint, 
nsPrefixService);
             } else {
                 log.warn(String.format("Unknown Constraint Type %s. Supported 
values are %s",               
                     Arrays.asList("reference",ConstraintType.values())));
@@ -307,6 +308,20 @@ public class FieldQueryReader implements
             message.append(jConstraint.toString(4));
             throw new IllegalArgumentException(message.toString());
         }
+        //finally parse the optional boost
+        if(jConstraint.has("boost")){
+            double boost = jConstraint.optDouble("boost");
+            if(boost == Double.NaN || boost <= 0){
+                StringBuilder message = new StringBuilder("The Boost of a 
Constraint " +
+                               "MUST BE a double AND >= 0 (parsed: '");
+                message.append(jConstraint.get("boost")).append("')!");
+                log.warn(message.toString());
+                throw new IllegalArgumentException(message.toString());
+            } else {
+                constraint.setBoost(boost);
+            }
+        } //else no boost defined
+        return constraint;
     }
 
     private static Constraint parseSimilarityConstraint(JSONObject 
jConstraint, NamespacePrefixService nsPrefixService) throws JSONException {
@@ -414,7 +429,7 @@ public class FieldQueryReader implements
      * @throws JSONException
      */
     private static Constraint parseTextConstraint(JSONObject jConstraint) 
throws JSONException {
-        Constraint constraint;
+        final TextConstraint constraint;
         boolean caseSensitive = jConstraint.optBoolean("caseSensitive", false);
         //parse patternType
         PatternType patternType;
@@ -502,6 +517,10 @@ public class FieldQueryReader implements
             constraint = new TextConstraint(textConstraints,
                 patternType,caseSensitive,
                 languages == null?null:languages.toArray(new 
String[languages.size()]));
+            //finally parse the optional termProximity
+            if(jConstraint.has("proximityRanking")){
+                
constraint.setProximityRanking(jConstraint.optBoolean("proximityRanking", 
false));
+            }
         } else {
             StringBuilder message = new StringBuilder();
             message.append("Parsed TextConstraint doese not define the 
required field 'text'!\n");

Modified: 
stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/writers/FieldQueryToJSON.java
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/writers/FieldQueryToJSON.java?rev=1492586&r1=1492585&r2=1492586&view=diff
==============================================================================
--- 
stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/writers/FieldQueryToJSON.java
 (original)
+++ 
stanbol/trunk/entityhub/jersey/src/main/java/org/apache/stanbol/entityhub/jersey/writers/FieldQueryToJSON.java
 Thu Jun 13 09:12:59 2013
@@ -59,6 +59,11 @@ final class FieldQueryToJSON {
         for (Entry<String, Constraint> fieldConstraint : query) {
             JSONObject jFieldConstraint = 
convertConstraintToJSON(fieldConstraint.getValue(),nsPrefixService);
             jFieldConstraint.put("field", fieldConstraint.getKey()); //add the 
field
+            //write the boost if present
+            Double boost = fieldConstraint.getValue().getBoost();
+            if(boost != null){
+                jFieldConstraint.put("boost", boost);
+            }
             constraints.put(jFieldConstraint); //add fieldConstraint
         }
         if(query.getLimit() != null){
@@ -148,6 +153,10 @@ final class FieldQueryToJSON {
                 if(textConstraint.isCaseSensitive()){
                     jConstraint.put("caseSensitive", true);
                 } //else default is false
+                //write the proximity ranking state (if defined)
+                if(textConstraint.isProximityRanking() != null){
+                    jConstraint.put("proximityRanking", 
textConstraint.isProximityRanking());
+                }
                 break;
             case range:
                 RangeConstraint rangeConstraint = (RangeConstraint) constraint;

Modified: 
stanbol/trunk/entityhub/jersey/src/main/resources/templates/imports/fieldquerydocumentation.ftl
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/entityhub/jersey/src/main/resources/templates/imports/fieldquerydocumentation.ftl?rev=1492586&r1=1492585&r2=1492586&view=diff
==============================================================================
--- 
stanbol/trunk/entityhub/jersey/src/main/resources/templates/imports/fieldquerydocumentation.ftl
 (original)
+++ 
stanbol/trunk/entityhub/jersey/src/main/resources/templates/imports/fieldquerydocumentation.ftl
 Thu Jun 13 09:12:59 2013
@@ -86,6 +86,15 @@ are required by all types.</p>
     </li>
 </ul>
 
+<p> In addition the following optional attributes are supported by all 
constraints </p>
+<ul>
+    <li><b><code>boost</code></b>: Allows to define a boost for a constraint. 
If
+    supported boosts will influence the ranking of query results. The boost 
value
+    MUST BE a number <code>&gt;= 0</code>. The default is <code>1</code>.</li>
+</ul>
+
+
+
 <p>There are 4 different constraint types.</p>
 <ol>
  <li><em><a href="#value-constraint">ValueConstraint</a>:</em> 
@@ -224,6 +233,10 @@ value. Note however that this would not 
     <li><code>patternType</code>: one of "wildcard", "regex" or "none" 
         (default is "none") </li>
     <li><code>caseSensitive</code>: boolean (default is "false")</li>
+    <li><code>proximityRanking</code>: boolean (default is undefined). This 
tells
+        Sites that the proximity of parsed texts should be used for ranking. 
The
+        default is undefined and may depend on the actual Site executing the
+        query</li>
 </ul>
 
 <h4>Example:</h4>


Reply via email to