Revision: 19726
http://sourceforge.net/p/gate/code/19726
Author: domrout
Date: 2016-11-08 13:09:38 +0000 (Tue, 08 Nov 2016)
Log Message:
-----------
Add support for default annotations in annotation jobs.
Modified Paths:
--------------
gate/trunk/plugins/Crowd_Sourcing/src/gate/crowdsource/ne/EntityAnnotationJobBuilder.java
gate/trunk/plugins/Crowd_Sourcing/src/gate/crowdsource/rest/CrowdFlowerClient.java
gate/trunk/plugins/Crowd_Sourcing/src/gate/crowdsource/rest/gate-crowdflower.js
Modified:
gate/trunk/plugins/Crowd_Sourcing/src/gate/crowdsource/ne/EntityAnnotationJobBuilder.java
===================================================================
---
gate/trunk/plugins/Crowd_Sourcing/src/gate/crowdsource/ne/EntityAnnotationJobBuilder.java
2016-11-08 02:23:16 UTC (rev 19725)
+++
gate/trunk/plugins/Crowd_Sourcing/src/gate/crowdsource/ne/EntityAnnotationJobBuilder.java
2016-11-08 13:09:38 UTC (rev 19726)
@@ -55,6 +55,8 @@
private String detailFeatureName;
+ private String defaultsASName;
+
private String goldFeatureName;
private String goldFeatureValue;
@@ -148,6 +150,19 @@
this.detailFeatureName = detailFeatureName;
}
+ public String getDefaultsASName() {
+ return defaultsASName;
+ }
+
+ @Optional
+ @RunTime
+ @CreoleParameter(defaultValue = "crowdDefaults", comment = "Annotation set
used" +
+ "to mark the default values where available.")
+ public void setDefaultsASName(String defaultsASName) {
+ this.defaultsASName = defaultsASName;
+ }
+
+
public String getEntityAnnotationType() {
return entityAnnotationType;
}
@@ -171,6 +186,7 @@
this.entityASName = entityASName;
}
+
public String getGoldFeatureName() {
return goldFeatureName;
}
@@ -239,6 +255,11 @@
AnnotationSet snippetAnnotations =
getDocument().getAnnotations(snippetASName).get(
snippetAnnotationType);
+
+ AnnotationSet defaultAnnotations =
+ getDocument().getAnnotations(defaultsASName)
+ .get(entityAnnotationType);
+
AnnotationSet goldAS =
getDocument().getAnnotations(entityASName).get(
entityAnnotationType);
@@ -268,6 +289,7 @@
detail = detailObj.toString();
}
}
+
AnnotationSet goldAnnots = null;
String goldReason = null;
if(goldFeatureValue.equals(snippet.getFeatures().get(goldFeatureName))) {
@@ -280,10 +302,12 @@
}
}
+ AnnotationSet snippetDefaults =
Utils.getContainedAnnotations(defaultAnnotations, snippet);
+
long unitId =
crowdFlowerClient.createAnnotationUnit(jobId, getDocument(),
snippetASName, snippet, detail, snippetTokens,
- goldAnnots, goldReason);
+ goldAnnots, snippetDefaults, goldReason);
// store the unit ID - we use the entity annotation type as part
// of this feature
// name so the same sentences can hold units for different
Modified:
gate/trunk/plugins/Crowd_Sourcing/src/gate/crowdsource/rest/CrowdFlowerClient.java
===================================================================
---
gate/trunk/plugins/Crowd_Sourcing/src/gate/crowdsource/rest/CrowdFlowerClient.java
2016-11-08 02:23:16 UTC (rev 19725)
+++
gate/trunk/plugins/Crowd_Sourcing/src/gate/crowdsource/rest/CrowdFlowerClient.java
2016-11-08 13:09:38 UTC (rev 19726)
@@ -457,7 +457,7 @@
cml.append("<div class=\"gate-snippet\">\n"
+ " <cml:checkboxes validates=\"required\" label=\"");
StringEscapeUtils.escapeXml(cml, caption);
- cml.append("\" name=\"answer\">\n"
+ cml.append("\" name=\"answer\" data-default=\"{{ answer_default | join:
',' }}\">\n"
+ " {% for tok in tokens %}\n"
+ " <cml:checkbox label=\"{{ tok }}\" value=\"{{
forloop.index0 }}\" />\n"
+ " {% endfor %}\n" + " </cml:checkboxes>\n" + "</div>\n"
@@ -522,7 +522,8 @@
*/
public long createAnnotationUnit(long jobId, Document doc, String asName,
Annotation snippet, String detail, AnnotationSet tokens,
- AnnotationSet correctAnnotations, String goldReason) {
+ AnnotationSet correctAnnotations, AnnotationSet defaultAnnotations,
+ String goldReason) {
String documentId = String.valueOf(doc.getLRPersistenceId());
int formDataSize = 6; // docId + asName + annId
List<Annotation> tokensList = Utils.inDocumentOrder(tokens);
@@ -531,6 +532,8 @@
formDataSize += 2;
}
Set<Integer> answerGold = null;
+ HashSet<Integer> answerDefault = null;
+
if(correctAnnotations != null) {
// gold unit
answerGold = new HashSet<Integer>();
@@ -556,6 +559,23 @@
}
}
+ if(defaultAnnotations != null) {
+ // Add default annotations
+
+ answerDefault = new HashSet<Integer>();
+ for(Annotation a : defaultAnnotations) {
+ for(int i = 0; i < tokensList.size(); i++) {
+ Annotation tokenI = tokensList.get(i);
+ if (Utils.start(tokenI) >= Utils.start(a)
+ && Utils.end(tokenI) <= Utils.end(a)) {
+ answerDefault.add(i);
+ }
+ }
+ }
+ formDataSize += 2 * answerDefault.size(); // answer=N for each
+
+ }
+
String[] formData = new String[formDataSize];
int i = 0;
formData[i++] = "unit[data][documentId]";
@@ -596,6 +616,12 @@
}
}
}
+ if (answerDefault != null) {
+ for(int answer : answerDefault) {
+ formData[i++] = "unit[data][answer_default][]";
+ formData[i++] = String.valueOf(answer);
+ }
+ }
try {
JsonElement json = post("/jobs/" + jobId + "/units", formData);
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-11-08 02:23:16 UTC (rev 19725)
+++
gate/trunk/plugins/Crowd_Sourcing/src/gate/crowdsource/rest/gate-crowdflower.js
2016-11-08 13:09:38 UTC (rev 19726)
@@ -4,4 +4,13 @@
// the "selected" class on its containing label to match
var parent = $$(target).getParents('label')[0];
parent.toggleClass('selected', target.checked);
+});
+
+$$(".gate-snippet .cml_field").each(function(target) {
+ Array.each(target.data("default").split(","), function(index) {
+ var checkbox = target.getElement("input.answer[value=\""+index+"\"]")
+ var parent = $$(checkbox).getParents('label')[0];
+ checkbox.checked = true;
+ parent.toggleClass('selected', true);
+ });
});
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs