Revision: 17797
http://sourceforge.net/p/gate/code/17797
Author: ian_roberts
Date: 2014-04-10 12:53:19 +0000 (Thu, 10 Apr 2014)
Log Message:
-----------
JAPE grammars to build the required "detail" feature values to give a list of
links within the sentence being annotated.
Modified Paths:
--------------
gate/trunk/plugins/Crowd_Sourcing/resources/lookupsToMention.groovy
Added Paths:
-----------
gate/trunk/plugins/Crowd_Sourcing/resources/add-url-list-to-mentions.jape
gate/trunk/plugins/Crowd_Sourcing/resources/add-url-list-to-sentences.jape
Property Changed:
----------------
gate/trunk/plugins/Crowd_Sourcing/resources/lookupsToMention.groovy
Added: gate/trunk/plugins/Crowd_Sourcing/resources/add-url-list-to-mentions.jape
===================================================================
--- gate/trunk/plugins/Crowd_Sourcing/resources/add-url-list-to-mentions.jape
(rev 0)
+++ gate/trunk/plugins/Crowd_Sourcing/resources/add-url-list-to-mentions.jape
2014-04-10 12:53:19 UTC (rev 17797)
@@ -0,0 +1,61 @@
+/*
+ * add-url-list-to-mentions.jape
+ *
+ * JAPE grammar to find all the annotations of type "Url" within the
+ * Sentence that contains each Mention annotation. If the sentence contains
+ * any URLs then construct an HTML list of links (<a> tags) and store this
+ * HTML as the "detail" feature on the Mention. This can then be picked up
+ * by the EntityClassificationJobBuilder PR to allow workers to quickly
+ * explore any links from the snippet they are looking at.
+ *
+ * Copyright (c) 2014, The University of Sheffield. See the file
+ * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
+ *
+ * This file is part of GATE (see http://gate.ac.uk/), and is free
+ * software, licenced under the GNU Library General Public License,
+ * Version 3, June 2007 (in the distribution as file licence.html,
+ * and also available at http://gate.ac.uk/gate/licence.html).
+ *
+ * $Id$
+ */
+Imports: {
+ import static gate.Utils.*;
+ import org.apache.commons.lang.StringEscapeUtils;
+}
+
+Phase: AddUrlListToMentions
+Options: control = all
+Input: Mention
+
+Rule: AddUrls
+({Mention}):mention
+-->
+:mention {
+ Annotation mention = getOnlyAnn(mentionAnnots);
+ // find all the Sentence annotations that cover this mention (there will
+ // probably only be one of them but the logic works whatever)
+ AnnotationSet coveringSentences = getCoveringAnnotations(
+ inputAS, mention, "Sentence");
+ // find all Url annotations in the covering sentence(s)
+ List<Annotation> urls = inDocumentOrder(
+ getContainedAnnotations(inputAS, coveringSentences, "Url"));
+ if(urls.size() > 0) {
+ // build an HTML list of links for the Url annotations we found and store
+ // it as a feature on the Mention.
+ StringBuilder buf = new StringBuilder(
+ "<p>You may wish to refer to the following links:</p>\n<ul>\n");
+
+ for(Annotation u : urls) {
+ String urlString = StringEscapeUtils.escapeHtml(stringFor(doc, u));
+ buf.append(" <li><a target=\"_blank\" href=\"");
+ buf.append(urlString);
+ buf.append("\">");
+ buf.append(urlString);
+ buf.append("</a></li>\n");
+ }
+
+ buf.append("</ul>");
+
+ mention.getFeatures().put("detail", buf.toString());
+ }
+}
Property changes on:
gate/trunk/plugins/Crowd_Sourcing/resources/add-url-list-to-mentions.jape
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Added:
gate/trunk/plugins/Crowd_Sourcing/resources/add-url-list-to-sentences.jape
===================================================================
--- gate/trunk/plugins/Crowd_Sourcing/resources/add-url-list-to-sentences.jape
(rev 0)
+++ gate/trunk/plugins/Crowd_Sourcing/resources/add-url-list-to-sentences.jape
2014-04-10 12:53:19 UTC (rev 17797)
@@ -0,0 +1,57 @@
+/*
+ * add-url-list-to-sentences.jape
+ *
+ * JAPE grammar to find all the annotations of type "Url" within each
+ * Sentence. If the sentence contains any URLs then construct an HTML list of
+ * links (<a> tags) and store this HTML as the "detail" feature on the
+ * Sentence. This can then be picked up by the EntityAnnotationJobBuilder PR
+ * to allow annotators to quickly explore any links from the snippet they are
+ * annotating.
+ *
+ * Copyright (c) 2014, The University of Sheffield. See the file
+ * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
+ *
+ * This file is part of GATE (see http://gate.ac.uk/), and is free
+ * software, licenced under the GNU Library General Public License,
+ * Version 3, June 2007 (in the distribution as file licence.html,
+ * and also available at http://gate.ac.uk/gate/licence.html).
+ *
+ * $Id$
+ */
+Imports: {
+ import static gate.Utils.*;
+ import org.apache.commons.lang.StringEscapeUtils;
+}
+
+Phase: AddUrlListToSentences
+Options: control = all
+Input: Sentence
+
+Rule: AddUrls
+({Sentence}):sent
+-->
+:sent {
+ Annotation sentence = getOnlyAnn(sentAnnots);
+ // find all Url annotations in this sentence
+ List<Annotation> urls = inDocumentOrder(
+ getContainedAnnotations(inputAS, sentence, "Url"));
+ if(urls.size() > 0) {
+ // build an HTML list of links for the Url annotations contained in this
+ // sentence, and store it as a sentence feature.
+ StringBuilder buf = new StringBuilder(
+ "<p>You may wish to refer to the following links:</p>\n<ul>\n");
+
+ for(Annotation u : urls) {
+ String urlString = StringEscapeUtils.escapeHtml(stringFor(doc, u));
+ buf.append(" <li><a target=\"_blank\" href=\"");
+ buf.append(urlString);
+ buf.append("\">");
+ buf.append(urlString);
+ buf.append("</a></li>\n");
+ }
+
+ buf.append("</ul>");
+
+ sentence.getFeatures().put("detail", buf.toString());
+ }
+}
Property changes on:
gate/trunk/plugins/Crowd_Sourcing/resources/add-url-list-to-sentences.jape
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Modified: gate/trunk/plugins/Crowd_Sourcing/resources/lookupsToMention.groovy
===================================================================
--- gate/trunk/plugins/Crowd_Sourcing/resources/lookupsToMention.groovy
2014-04-10 12:28:34 UTC (rev 17796)
+++ gate/trunk/plugins/Crowd_Sourcing/resources/lookupsToMention.groovy
2014-04-10 12:53:19 UTC (rev 17797)
@@ -33,7 +33,7 @@
* Version 3, June 2007 (in the distribution as file licence.html,
* and also available at http://gate.ac.uk/gate/licence.html).
*
- * $Id: CrowdFlowerConstants.java 17412 2014-02-24 17:30:09Z ian_roberts $
+ * $Id$
*/
import org.apache.commons.lang.StringEscapeUtils as SEU
Property changes on:
gate/trunk/plugins/Crowd_Sourcing/resources/lookupsToMention.groovy
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs