Commit d554731c authored by Vid's avatar Vid

first commit of MUSE workflow package and components

parent 0b6228fe
......@@ -207,6 +207,7 @@ INSTALLED_APPS_WORKFLOWS_SUB = (
'workflows.bio3graph',
'workflows.noise',
'workflows.vipercharts',
'workflows.MUSE',
#WORKFLOWS_SUBAPP_PLACEHOLDER
)
......
#import requests
import urllib
import urllib2
import HTMLParser
from xml.sax import saxutils as su
TERENCE_SERVICE_URL = 'http://ariadne.cs.kuleuven.be/TERENCEStoryService/rest/auto'
def invoke_terence_service(text):
submitVars = {'text': text}
submitVarsUrlencoded = urllib.urlencode(submitVars)
req = urllib2.Request(TERENCE_SERVICE_URL, submitVarsUrlencoded)
response = urllib2.urlopen(req)
xml = response.read()
#print repr(xml)
#xml = su.unescape(xml)
#print '----------'
#print repr(xml)
#html_parser = HTMLParser.HTMLParser()
#xml = html_parser.unescape(xml)
return xml
[
{
"pk": 44,
"model": "workflows.category",
"fields": {
"uid": "1f5cbe19-0df7-44de-91d8-1ffdae9a1645",
"parent": null,
"workflow": null,
"user": null,
"order": 1,
"name": "MUSE"
}
},
{
"pk": 45,
"model": "workflows.category",
"fields": {
"uid": "cf46e990-42b6-4027-b2f4-a95acaaed210",
"parent": 44,
"workflow": null,
"user": null,
"order": 1,
"name": "NLP components"
}
},
{
"pk": 233,
"model": "workflows.abstractwidget",
"fields": {
"category": 45,
"treeview_image": "",
"name": "Event extraction",
"is_streaming": false,
"uid": "5e5aa91e-090a-43c9-97c6-6064380b09eb",
"interaction_view": "",
"image": "",
"package": "MUSE",
"static_image": "",
"post_interact_action": "",
"user": null,
"visualization_view": "",
"streaming_visualization_view": "",
"action": "MUSE_annotate",
"wsdl_method": "",
"wsdl": "",
"interactive": false,
"has_progress_bar": false,
"order": 1,
"description": "Calls the LIIR NLP annotation (TERENCE NLP service)"
}
},
{
"pk": 484,
"model": "workflows.abstractinput",
"fields": {
"widget": 233,
"name": "Raw text",
"short_name": "txt",
"uid": "7e5b5533-d21c-4955-8fb8-417d5030793f",
"default": "",
"required": true,
"multi": false,
"parameter_type": null,
"variable": "raw_text",
"parameter": false,
"order": 1,
"description": "Input document as raw text"
}
},
{
"pk": 240,
"model": "workflows.abstractoutput",
"fields": {
"widget": 233,
"name": "Annotated text",
"short_name": "xml",
"variable": "annotations_xml",
"uid": "c677e844-9f9b-4d09-8e08-9b9335895bac",
"order": 1,
"description": "XML document with all annotations"
}
},
{
"pk": 47,
"model": "workflows.category",
"fields": {
"uid": "2ea309eb-3f82-45cb-8b33-9d00cf3f5a35",
"parent": 44,
"workflow": null,
"user": null,
"order": 1,
"name": "Utilities"
}
},
{
"pk": 234,
"model": "workflows.abstractwidget",
"fields": {
"category": 47,
"treeview_image": "",
"name": "View XML",
"is_streaming": false,
"uid": "ca337532-ab9d-4554-afca-b4d14216b156",
"interaction_view": "",
"image": "",
"package": "MUSE",
"static_image": "",
"post_interact_action": "",
"user": null,
"visualization_view": "MUSE_view_xml",
"streaming_visualization_view": "",
"action": "MUSE_view_xml",
"wsdl_method": "",
"wsdl": "",
"interactive": false,
"has_progress_bar": false,
"order": 1,
"description": "Displays XML in a modal window"
}
},
{
"pk": 485,
"model": "workflows.abstractinput",
"fields": {
"widget": 234,
"name": "XML document",
"short_name": "xml",
"uid": "2e451b23-c11d-4614-aa4f-57521a42ef83",
"default": "",
"required": true,
"multi": false,
"parameter_type": null,
"variable": "xml_data",
"parameter": false,
"order": 1,
"description": "XML document as string"
}
}
]
\ No newline at end of file
from django.shortcuts import render
def MUSE_filter_integers(request,input_dict,output_dict,widget):
return render(request, 'interactions/MUSE_filter_integers.html',{'widget':widget,'intList':input_dict['intList']})
\ No newline at end of file
import re
def MUSE_annotate(input_dict):
from NLP_interface import invoke_terence_service
text = input_dict['raw_text']
xml = invoke_terence_service(text)
#xml = xml.replace('\n', ' ')
#xml = xml.replace('\t', ' ')
return {'annotations_xml': xml}
def MUSE_view_xml(input_dict):
return {'xml_data': input_dict.get('xml_data', None)}
import os
# === STANDARD PACKAGE SETTINGS ===
PACKAGE_ROOT = os.path.dirname(__file__)
# === AUTO IMPORT OPTIONS ===
#If auto_import_package_data is true then given data file is automatically imported when ClowdFlows project is newly deployed or refreshed from git
AUTO_IMPORT_DB = False
#For auto_import_package_data_replace_option description see the 'replace' option in workflows/import_package command
AUTO_IMPORT_DB_REPLACE_OPTION = True
#If file(s) other than ./db/package_data.json should be imported, auto_import_package_data_files should be corrected
AUTO_IMPORT_DB_FILES = [os.path.join(PACKAGE_ROOT,'db/package_data.json')]
@charset "utf-8";
/* CSS Document */
.Utility {
color: black;
}
.NodeName {
font-weight:bold;
color: #800080;
}
.AttributeName
{
font-weight:bold;
color: black;
}
.AttributeValue
{
color:blue;
}
.NodeValue
{
color: black;
}
.Element {
border-left-color:#00FF66;
border-left-width:thin;
border-left-style:solid;
padding-top:0px;
margin-top:10px;
}
.Clickable {
font-weight:900;
font-size:large;
color: #800080;
cursor:pointer;
vertical-align:middle;
}
/* Copyright (c) 2007 Lev Muchnik <LevMuchnik@gmail.com>. All rights reserved.
* You may copy and modify this script as long as the above copyright notice,
* this condition and the following disclaimer is left intact.
* This software is provided by the author "AS IS" and no warranties are
* implied, including fitness for a particular purpose. In no event shall
* the author be liable for any damages arising in any way out of the use
* of this software, even if advised of the possibility of such damage.
* $Date: 2007-10-03 19:08:15 -0700 (Wed, 03 Oct 2007) $
*/
function LoadXML(ParentElementID,URL)
{
var xmlHolderElement = GetParentElement(ParentElementID);
if (xmlHolderElement==null) { return false; }
ToggleElementVisibility(xmlHolderElement);
return RequestURL(URL,URLReceiveCallback,ParentElementID);
}
function LoadXMLDom(ParentElementID,xmlDoc)
{
if (xmlDoc) {
var xmlHolderElement = GetParentElement(ParentElementID);
if (xmlHolderElement==null) { return false; }
while (xmlHolderElement.childNodes.length) { xmlHolderElement.removeChild(xmlHolderElement.childNodes.item(xmlHolderElement.childNodes.length-1)); }
var Result = ShowXML(xmlHolderElement,xmlDoc.documentElement,0);
var ReferenceElement = document.createElement('div');
/* var Link = document.createElement('a');
Link.setAttribute('href','http://www.levmuchnik.net/Content/ProgrammingTips/WEB/XMLDisplay/DisplayXMLFileWithJavascript.html');
var TextNode = document.createTextNode('Source: Lev Muchnik');
Link.appendChild(TextNode);
*/
xmlHolderElement.appendChild(Link);
return Result;
}
else { return false; }
}
function LoadXMLString(ParentElementID,XMLString)
{
xmlDoc = CreateXMLDOM(XMLString);
return LoadXMLDom(ParentElementID,xmlDoc) ;
}
////////////////////////////////////////////////////////////
// HELPER FUNCTIONS - SHOULD NOT BE DIRECTLY CALLED BY USERS
////////////////////////////////////////////////////////////
function GetParentElement(ParentElementID)
{
if (typeof(ParentElementID)=='string') { return document.getElementById(ParentElementID); }
else if (typeof(ParentElementID)=='object') { return ParentElementID;}
else { return null; }
}
function URLReceiveCallback(httpRequest,xmlHolderElement)
{
try {
if (httpRequest.readyState == 4) {
if (httpRequest.status == 200) {
var xmlDoc = httpRequest.responseXML;
if (xmlHolderElement && xmlHolderElement!=null) {
xmlHolderElement.innerHTML = '';
return LoadXMLDom(xmlHolderElement,xmlDoc);
}
} else {
return false;
}
}
}
catch( e ) {
return false;
}
}
function RequestURL(url,callback,ExtraData) { // based on: http://developer.mozilla.org/en/docs/AJAX:Getting_Started
var httpRequest;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
httpRequest = new XMLHttpRequest();
if (httpRequest.overrideMimeType) { httpRequest.overrideMimeType('text/xml'); }
}
else if (window.ActiveXObject) { // IE
try { httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e) {
try { httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) {}
}
}
if (!httpRequest) { return false; }
httpRequest.onreadystatechange = function() { callback(httpRequest,ExtraData); };
httpRequest.open('GET', url, true);
httpRequest.send('');
return true;
}
function CreateXMLDOM(XMLStr)
{
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.loadXML(XMLStr);
return xmlDoc;
}
else if (document.implementation && document.implementation.createDocument) {
var parser=new DOMParser();
return parser.parseFromString(XMLStr,"text/xml");
}
else {
return null;
}
}
var IDCounter = 1;
var NestingIndent = 15;
function ShowXML(xmlHolderElement,RootNode,indent)
{
if (RootNode==null || xmlHolderElement==null) { return false; }
var Result = true;
var TagEmptyElement = document.createElement('div');
TagEmptyElement.className = 'Element';
TagEmptyElement.style.position = 'relative';
TagEmptyElement.style.left = NestingIndent+'px';
if (RootNode.childNodes.length==0) {
var ClickableElement = AddTextNode(TagEmptyElement,'','Clickable') ;
ClickableElement.id = 'div_empty_' + IDCounter;
AddTextNode(TagEmptyElement,'<','Utility') ;
AddTextNode(TagEmptyElement,RootNode.nodeName ,'NodeName')
for (var i = 0; RootNode.attributes && i < RootNode.attributes.length; ++i) {
CurrentAttribute = RootNode.attributes.item(i);
AddTextNode(TagEmptyElement,' ' + CurrentAttribute.nodeName ,'AttributeName') ;
AddTextNode(TagEmptyElement,'=','Utility') ;
AddTextNode(TagEmptyElement,'"' + CurrentAttribute.nodeValue + '"','AttributeValue') ;
}
AddTextNode(TagEmptyElement,' />') ;
xmlHolderElement.appendChild(TagEmptyElement);
//SetVisibility(TagEmptyElement,true);
}
else { // mo child nodes
var ClickableElement = AddTextNode(TagEmptyElement,'+','Clickable') ;
ClickableElement.onclick = function() {ToggleElementVisibility(this); }
ClickableElement.id = 'div_empty_' + IDCounter;
AddTextNode(TagEmptyElement,'<','Utility') ;
AddTextNode(TagEmptyElement,RootNode.nodeName ,'NodeName')
for (var i = 0; RootNode.attributes && i < RootNode.attributes.length; ++i) {
CurrentAttribute = RootNode.attributes.item(i);
AddTextNode(TagEmptyElement,' ' + CurrentAttribute.nodeName ,'AttributeName') ;
AddTextNode(TagEmptyElement,'=','Utility') ;
AddTextNode(TagEmptyElement,'"' + CurrentAttribute.nodeValue + '"','AttributeValue') ;
}
AddTextNode(TagEmptyElement,'> </','Utility') ;
AddTextNode(TagEmptyElement,RootNode.nodeName,'NodeName') ;
AddTextNode(TagEmptyElement,'>','Utility') ;
xmlHolderElement.appendChild(TagEmptyElement);
SetVisibility(TagEmptyElement,false);
//----------------------------------------------
var TagElement = document.createElement('div');
TagElement.className = 'Element';
TagElement.style.position = 'relative';
TagElement.style.left = NestingIndent+'px';
ClickableElement = AddTextNode(TagElement,'-','Clickable') ;
ClickableElement.onclick = function() {ToggleElementVisibility(this); }
ClickableElement.id = 'div_content_' + IDCounter;
++IDCounter;
AddTextNode(TagElement,'<','Utility') ;
AddTextNode(TagElement,RootNode.nodeName ,'NodeName') ;
for (var i = 0; RootNode.attributes && i < RootNode.attributes.length; ++i) {
CurrentAttribute = RootNode.attributes.item(i);
AddTextNode(TagElement,' ' + CurrentAttribute.nodeName ,'AttributeName') ;
AddTextNode(TagElement,'=','Utility') ;
AddTextNode(TagElement,'"' + CurrentAttribute.nodeValue + '"','AttributeValue') ;
}
AddTextNode(TagElement,'>','Utility') ;
TagElement.appendChild(document.createElement('br'));
var NodeContent = null;
for (var i = 0; RootNode.childNodes && i < RootNode.childNodes.length; ++i) {
if (RootNode.childNodes.item(i).nodeName != '#text') {
Result &= ShowXML(TagElement,RootNode.childNodes.item(i),indent+1);
}
else {
NodeContent =RootNode.childNodes.item(i).nodeValue;
}
}
if (RootNode.nodeValue) {
NodeContent = RootNode.nodeValue;
}
if (NodeContent) {
var ContentElement = document.createElement('div');
ContentElement.style.position = 'relative';
ContentElement.style.left = NestingIndent+'px';
AddTextNode(ContentElement,NodeContent ,'NodeValue') ;
TagElement.appendChild(ContentElement);
}
AddTextNode(TagElement,' </','Utility') ;
AddTextNode(TagElement,RootNode.nodeName,'NodeName') ;
AddTextNode(TagElement,'>','Utility') ;
xmlHolderElement.appendChild(TagElement);
}
// if (indent==0) { ToggleElementVisibility(TagElement.childNodes(0)); } - uncomment to collapse the external element
return Result;
}
function AddTextNode(ParentNode,Text,Class)
{
NewNode = document.createElement('span');
if (Class) { NewNode.className = Class;}
if (Text) { NewNode.appendChild(document.createTextNode(Text)); }
if (ParentNode) { ParentNode.appendChild(NewNode); }
return NewNode;
}
function CompatibleGetElementByID(id)
{
if (!id) { return null; }
if (document.getElementById) { // DOM3 = IE5, NS6
return document.getElementById(id);
}
else {
if (document.layers) { // Netscape 4
return document.id;
}
else { // IE 4
return document.all.id;
}
}
}
function SetVisibility(HTMLElement,Visible)
{
if (!HTMLElement) { return; }
var VisibilityStr = (Visible) ? 'block' : 'none';
if (document.getElementById) { // DOM3 = IE5, NS6
HTMLElement.style.display =VisibilityStr;
}
else {
if (document.layers) { // Netscape 4
HTMLElement.display = VisibilityStr;
}
else { // IE 4
HTMLElement.id.style.display = VisibilityStr;
}
}
}
function ToggleElementVisibility(Element)
{
if (!Element|| !Element.id) { return; }
try {
ElementType = Element.id.slice(0,Element.id.lastIndexOf('_')+1);
ElementID = parseInt(Element.id.slice(Element.id.lastIndexOf('_')+1));
}
catch(e) { return ; }
var ElementToHide = null;
var ElementToShow= null;
if (ElementType=='div_content_') {
ElementToHide = 'div_content_' + ElementID;
ElementToShow = 'div_empty_' + ElementID;
}
else if (ElementType=='div_empty_') {
ElementToShow= 'div_content_' + ElementID;
ElementToHide = 'div_empty_' + ElementID;
}
ElementToHide = CompatibleGetElementByID(ElementToHide);
ElementToShow = CompatibleGetElementByID(ElementToShow);
if (ElementToHide) { ElementToHide = ElementToHide.parentNode;}
if (ElementToShow) { ElementToShow = ElementToShow.parentNode;}
SetVisibility(ElementToHide,false);
SetVisibility(ElementToShow,true);
}
<div id="widgetinteract-{{widget.pk}}" rel="{{widget.pk}}" class="widgetinteractdialog" title="{{widget.name}} wants your input!">
<form id="interactionform-{{widget.pk}}" name="interactionform-{{widget.pk}}">
{% for i in intList %}
<input type="checkbox" name="intListOut" value="{{i}}" style="display:inline;width:auto;">{{i}}<br>
{% endfor %}
<input type="hidden" name="widget_id" value="{{widget.pk}}">
</form>
</div>
\ No newline at end of file
<div id="widgetvisualization-{{widget.pk}}" rel="{{widget.pk}}" class="widgetvisualizationdialog" title="{{widget.name}} visualization">
<div style="width:400px;font-family:monospace;">
<table style="width:auto; border-collapse:collapse;">
{% for i in input_dict.intList %}
<tr style="width:auto">
<td style="text-align: right; width:auto; line-height: 0.5em; padding: 2px; padding-bottom: 4px; padding-top: 0; margin:2px;">
{% if forloop.first %} {% else %}+{% endif %}
</td>
<td style="text-align: right; width:auto; line-height: 0.5em; padding: 2px; padding-bottom: 4px; padding-top: 0; margin:2px;">
{{ i }}
</td>
</tr>
{% endfor %}
<tr style="width:auto">
<td style="text-align: right; width:auto; line-height: 0.5em; border-top: 1px solid black; padding: 2px; padding-top: 4px; margin:2px;">
=
</td>
<td style="text-align: right; width:auto; line-height: 0.5em; border-top: 1px solid black; padding: 2px;margin:2px;">
{{ input_dict.sum }}
</td>
</tr>
</table>
<br/>
{{ check }}
</div>
</div>
\ No newline at end of file
<div id="widgetvisualization-{{widget.pk}}" rel="{{widget.pk}}" class="widgetvisualizationdialog" title="{{widget.name}} visualization">
<div id="XMLHolder" style="width:100%;font-family:monospace;"></div>
<link href="{{STATIC_URL}}MUSE/XMLDisplay.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="{{STATIC_URL}}MUSE/XMLDisplay.js"> </script>
<script> LoadXML('XMLHolder', '{{ MEDIA_URL }}{{ filename }}'); </script>
</div>
<div id="widgetvisualization-{{widget.pk}}" rel="{{widget.pk}}" class="widgetvisualizationdialog" title="{{widget.name}} visualization">
<div id="XMLHolder"></div>
<link href="{{STATIC_URL}}MUSE/XMLDisplay.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="{{STATIC_URL}}MUSE/XMLDisplay.js"> </script>
<script> LoadXMLString('XMLHolder', "{{xml_data}}"); </script>
<!--<div style="width:100%;font-family:monospace;">-->
<!-- xml_data -->
<!--</div>-->
</div>
<div id="widgetvisualization-{{widget.pk}}" rel="{{widget.pk}}" class="widgetvisualizationdialog" title="{{widget.name}} visualization" width=700 height=600>
<applet code="biomine.bmvis.BMVis"
archive="{{STATIC_URL}}bio3graph/bmvis.jar"
width="100%" height="100%">
<param name="graph" value="{{ MEDIA_URL }}{{ filename }}">
</applet>
</div>
\ No newline at end of file