Commit bd8e557b authored by Anze Vavpetic's avatar Anze Vavpetic
Browse files

reverted the nlp widgets to currently working version

parent 945b13a6
This diff is collapsed.
import nlp import nlp
import os.path import os.path
import base64 import base64
from services.webservice import WebService
from workflows.security import safeOpen from workflows.security import safeOpen
import requests
import json
def merge_sentences(input_dict): def merge_sentences(input_dict):
""" """
...@@ -41,20 +41,11 @@ def load_corpus(input_dict): ...@@ -41,20 +41,11 @@ def load_corpus(input_dict):
''' '''
f = safeOpen(input_dict['file']) f = safeOpen(input_dict['file'])
fname = os.path.basename(input_dict['file']) fname = os.path.basename(input_dict['file'])
wsdl = input_dict.get('wsdl', 'http://vihar.ijs.si:8095/totale?wsdl')
data = base64.b64encode(f.read()) data = base64.b64encode(f.read())
ws = WebService(wsdl, 60000)
#define web service response = ws.client.parseFile(fileName=fname, inFile=data)
webservice_url = 'http://192.168.57.110:8080/parseFile' return {'corpus': response['parsedFile']}
params = {"fileName": fname, "text":data} #set params
#call web service
resp = requests.post(webservice_url, params=params)
content = json.loads(resp.content)[u'parseFileResponse'][u'parseFileResult']
if content[u"error"] != "":
raise Exception(content[u"error"])
else:
return {'corpus': content[u"resp"]}
def nlp_totrtale(input_dict): def nlp_totrtale(input_dict):
...@@ -63,22 +54,23 @@ def nlp_totrtale(input_dict): ...@@ -63,22 +54,23 @@ def nlp_totrtale(input_dict):
''' '''
corpus = input_dict['corpus'] corpus = input_dict['corpus']
lang = input_dict['lang'] lang = input_dict['lang']
xml = input_dict['xml'] wsdl = input_dict.get('wsdl', 'http://vihar.ijs.si:8095/totale?wsdl')
postprocess = input_dict['postprocess'] xml = input_dict['xml'] == 'true'
bohoricica = input_dict['bohoricica'] postprocess = input_dict['postprocess'] == 'true'
antique = input_dict['antique'] bohoricica = input_dict['bohoricica'] == 'true'
antique = input_dict['antique'] == 'true'
print lang, wsdl, xml, postprocess, bohoricica, antique
#define web service ws = WebService(wsdl, 60000)
webservice_url = 'http://192.168.57.110:8080/runToTrTaLe' response = ws.client.runTotale(inFile=corpus, language=lang,
params = {"text":corpus, "language": lang, "postProcessing":postprocess, "bohoricica":bohoricica, "antique": antique, "outputAsXML":xml} postProcessing=postprocess,
bohoricica=bohoricica,
response = requests.post(webservice_url, params = params) antiqueSlovenian=antique,
content = json.loads(response.content)[u'runToTrTaLeResponse'][u'runToTrTaLeResult'] outputAsXML=xml)
if content[u"error"] != "": errors = response['error']
print "error in nlp_totrtale", content[u"error"] if errors:
# todo report this as warning
return {'annotations': content[u'resp']} print errors
return {'annotations': response['annotatedFile']}
def nlp_term_extraction(input_dict): def nlp_term_extraction(input_dict):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment