From e0e4926982dec15818a6981a291e5e34e0c6e423 Mon Sep 17 00:00:00 2001 From: Admin Date: Tue, 4 Jun 2013 15:46:31 +0200 Subject: [PATCH] Passage au processor Step 1 --- static/js/application.js | 15 ++++++++------- webtagger.py | 25 ++++++------------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/static/js/application.js b/static/js/application.js index 46daa84..765e3b8 100644 --- a/static/js/application.js +++ b/static/js/application.js @@ -14,15 +14,16 @@ $('#go').click(function(){ url: "tagger", data: data, success: function(data){ - data = JSON.parse(data); + //data = JSON.parse(data); result=$('#result'); - _.each(data, function(element, index, list){ - console.log(element); - result.append(_.escape(element["word"])+" "); - result.append(_.escape(element["markup"]+" ")); - result.append(_.escape(element["lemm"]+"\n")); - }); + //_.each(data, function(element, index, list){ + // console.log(element); + // result.append(_.escape(element["word"])+" "); + // result.append(_.escape(element["markup"]+" ")); + // result.append(_.escape(element["lemm"]+"\n")); + //}); + result.append(_.escape(data)); console.log(_.escape(data)); console.log("resultat"); }, diff --git a/webtagger.py b/webtagger.py index 6a6178a..eb600ac 100644 --- a/webtagger.py +++ b/webtagger.py @@ -3,6 +3,7 @@ import subprocess import os import json from flask import Flask, request, render_template +from processor.LiaTools import * app = Flask(__name__) @app.route("/") @@ -11,28 +12,14 @@ def docs(): @app.route("/tagger",methods=['POST']) def cleaner(): + tagger = Tagger() # Receive String from post parametre Raw text ( Json ) dirtyString= request.json[u'string'] - # send the String throught LIA_TAGG script thank's to pipe + # send the String throught LIA_TAGG script thank's to pip # lia_clean split a word by line et markup the sentences - p=subprocess.Popen([os.environ["LIA_TAGG"]+'/script/lia_clean'],stdin=subprocess.PIPE,stdout=subprocess.PIPE) - (cleanString, err) = p.communicate(input=dirtyString.encode('iso8859-1','backslashreplace')) - #lia_tagg+lemm tagg words with function and give the lemm for each word - p2=subprocess.Popen([os.environ["LIA_TAGG"]+'/script/lia_tagg+lemm','-guess'],stdin=subprocess.PIPE,stdout=subprocess.PIPE) - (taggedString,err) =p2.communicate(input=cleanString) - # This is used beceause lia_tagg deal with iso8859 only - taggedString = taggedString.decode('iso8859').encode("utf8") - textTable = taggedString.split('\n') - # Creating a dictionary in order to encode it into Json - textDictionary = list() - for line in textTable : - lineTable =line.split() - #print lineTable - if lineTable: - wordDict=dict([('word',lineTable[0]),('markup',lineTable[1]),('lemm',lineTable[2])]) - textDictionary.append(wordDict) - textJson = json.JSONEncoder().encode(textDictionary) - return textJson + cleanString= tagger.clean(dirtyString) + taggedString= tagger.tagg(cleanString) + return taggedString if __name__ == '__main__': app.debug = True app.run(host='0.0.0.0') -- 1.8.2.3