Revision: 19664
          http://sourceforge.net/p/gate/code/19664
Author:   domrout
Date:     2016-10-10 11:07:00 +0000 (Mon, 10 Oct 2016)
Log Message:
-----------
Allow a "default" attribute to be added to an annotation to select a default 
value.

Modified Paths:
--------------
    
gate/trunk/plugins/Crowd_Sourcing/src/gate/crowdsource/rest/CrowdFlowerClient.java
    
gate/trunk/plugins/Crowd_Sourcing/src/gate/crowdsource/rest/gate-crowdflower.js

Added Paths:
-----------
    
gate/trunk/plugins/Crowd_Sourcing/src/gate/crowdsource/rest/gate-crowdflower-classification.js

Modified: 
gate/trunk/plugins/Crowd_Sourcing/src/gate/crowdsource/rest/CrowdFlowerClient.java
===================================================================
--- 
gate/trunk/plugins/Crowd_Sourcing/src/gate/crowdsource/rest/CrowdFlowerClient.java
  2016-10-10 08:44:57 UTC (rev 19663)
+++ 
gate/trunk/plugins/Crowd_Sourcing/src/gate/crowdsource/rest/CrowdFlowerClient.java
  2016-10-10 11:07:00 UTC (rev 19664)
@@ -96,13 +96,23 @@
     }
     StringWriter cml = new StringWriter();
 
+    // load the javascript that selects a default option if one is provided.
+    InputStream jsStream =
+            
CrowdFlowerClient.class.getResourceAsStream("gate-crowdflower-classification.js");
+    StringWriter js = new StringWriter();
+    try {
+      js.append(IOUtils.toString(jsStream, "UTF-8"));
+    } finally {
+      jsStream.close();
+    }
+
     // construct the CML with the specified caption and common radio
     // options
     cml.append("<h2 id=\"unit_text\">{{text}}</h2>\n\n"
             + "{% unless detail == \"No data available\" %}\n"
             + "  <div class=\"well\">{{detail}}</div>\n"
             + "{% endunless %}\n"
-            + "<cml:radios validates=\"required\" label=\"");
+            + "<cml:radios validates=\"required\" data-default=\"{{default}}\" 
label=\"");
     StringEscapeUtils.escapeXml(cml, caption);
     cml.append("\" name=\"answer\">\n"
             + "  {% unless options == \"No data available\" %}\n"
@@ -135,7 +145,8 @@
     log.debug("POSTing to CrowdFlower");
     JsonElement json =
             post("/jobs", "job[title]", title, "job[instructions]",
-                    instructions, "job[cml]", cml.toString(), "job[css]", css);
+                    instructions, "job[cml]", cml.toString(), "job[css]", css,
+                    "job[js]", js.toString());
     log.debug("CrowdFlower returned " + json);
     try {
       return json.getAsJsonObject().get("id").getAsLong();
@@ -261,10 +272,13 @@
       entity = Utils.stringFor(doc, target);
     }
 
+
+    String defaultSelection = (String) target.getFeatures().get("default");
+
     String text = createClassificationUnitText(doc, context, target);
 
     String documentId = String.valueOf(doc.getLRPersistenceId());
-    int formDataSize = 10; // text + entity + docId + asName + annId
+    int formDataSize = 12; // text + entity + docId + asName + default + annId
 
 
     Object options = target.getFeatures().get("options");
@@ -299,6 +313,8 @@
     formData[i++] = documentId;
     formData[i++] = "unit[data][asName]";
     formData[i++] = (asName == null ? "" : asName);
+    formData[i++] = "unit[data][default]";
+    formData[i++] = (defaultSelection == null ? "" : defaultSelection);
     formData[i++] = "unit[data][annId]";
     formData[i++] = String.valueOf(target.getId());
     if(options != null) {
@@ -322,6 +338,7 @@
       formData[i++] = target.getFeatures().get("detail").toString();
     }
 
+
     if(correctAnswer != null) {
       formData[i++] = "unit[golden]";
       formData[i++] = "true";

Added: 
gate/trunk/plugins/Crowd_Sourcing/src/gate/crowdsource/rest/gate-crowdflower-classification.js
===================================================================
--- 
gate/trunk/plugins/Crowd_Sourcing/src/gate/crowdsource/rest/gate-crowdflower-classification.js
                              (rev 0)
+++ 
gate/trunk/plugins/Crowd_Sourcing/src/gate/crowdsource/rest/gate-crowdflower-classification.js
      2016-10-10 11:07:00 UTC (rev 19664)
@@ -0,0 +1,15 @@
+require(['jquery-noconflict'], function($) {
+ //Ensure MooTools is where it must be
+  Window.implement('$', function(el, nc){
+    return document.id(el, nc, this.document);
+  });
+
+  var $ = window.jQuery;
+  //jQuery goes here
+
+  $(".radios").each(function() {
+    var def = $(this).data("default");
+    $(this).find("[value=\""+def+"\"]").attr("checked", "checked");
+    }
+  );
+});

Modified: 
gate/trunk/plugins/Crowd_Sourcing/src/gate/crowdsource/rest/gate-crowdflower.js
===================================================================
--- 
gate/trunk/plugins/Crowd_Sourcing/src/gate/crowdsource/rest/gate-crowdflower.js 
    2016-10-10 08:44:57 UTC (rev 19663)
+++ 
gate/trunk/plugins/Crowd_Sourcing/src/gate/crowdsource/rest/gate-crowdflower.js 
    2016-10-10 11:07:00 UTC (rev 19664)
@@ -4,4 +4,4 @@
   // the "selected" class on its containing label to match
   var parent = $$(target).getParents('label')[0];
   parent.toggleClass('selected', target.checked);
-});
+});
\ No newline at end of file

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to