Commit e0e4926982dec15818a6981a291e5e34e0c6e423

Authored by Killian
1 parent ac1275835c
Exists in master and in 1 other branch soap

Passage au processor Step 1

Showing 2 changed files with 14 additions and 26 deletions Inline Diff

static/js/application.js
1 // Some general UI pack related JS 1 // Some general UI pack related JS
2 $(document).ready(function() { 2 $(document).ready(function() {
3 tagging(); 3 tagging();
4 }); 4 });
5 5
6 6
7 7
8 function tagging(){ 8 function tagging(){
9 $('#go').click(function(){ 9 $('#go').click(function(){
10 data=JSON.stringify({ "string" : $('#data').val() }); 10 data=JSON.stringify({ "string" : $('#data').val() });
11 console.log(data); 11 console.log(data);
12 $.ajax({ 12 $.ajax({
13 type: "POST", 13 type: "POST",
14 url: "tagger", 14 url: "tagger",
15 data: data, 15 data: data,
16 success: function(data){ 16 success: function(data){
17 data = JSON.parse(data); 17 //data = JSON.parse(data);
18 result=$('#result'); 18 result=$('#result');
19 19
20 _.each(data, function(element, index, list){ 20 //_.each(data, function(element, index, list){
21 console.log(element); 21 // console.log(element);
22 result.append(_.escape(element["word"])+" "); 22 // result.append(_.escape(element["word"])+" ");
23 result.append(_.escape(element["markup"]+" ")); 23 // result.append(_.escape(element["markup"]+" "));
24 result.append(_.escape(element["lemm"]+"\n")); 24 // result.append(_.escape(element["lemm"]+"\n"));
25 }); 25 //});
26 result.append(_.escape(data));
26 console.log(_.escape(data)); 27 console.log(_.escape(data));
27 console.log("resultat"); 28 console.log("resultat");
28 }, 29 },
29 error: function(){ 30 error: function(){
30 alert("error"); 31 alert("error");
31 }, 32 },
32 dataType: "text", 33 dataType: "text",
33 contentType:"application/json; charset=UTF-8" 34 contentType:"application/json; charset=UTF-8"
34 }); 35 });
35 }); 36 });
36 } 37 }
37 38
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 import subprocess 2 import subprocess
3 import os 3 import os
4 import json 4 import json
5 from flask import Flask, request, render_template 5 from flask import Flask, request, render_template
6 from processor.LiaTools import *
6 app = Flask(__name__) 7 app = Flask(__name__)
7 8
8 @app.route("/") 9 @app.route("/")
9 def docs(): 10 def docs():
10 return render_template('index.html') 11 return render_template('index.html')
11 12
12 @app.route("/tagger",methods=['POST']) 13 @app.route("/tagger",methods=['POST'])
13 def cleaner(): 14 def cleaner():
15 tagger = Tagger()
14 # Receive String from post parametre Raw text ( Json ) 16 # Receive String from post parametre Raw text ( Json )
15 dirtyString= request.json[u'string'] 17 dirtyString= request.json[u'string']
16 # send the String throught LIA_TAGG script thank's to pipe 18 # send the String throught LIA_TAGG script thank's to pip
17 # lia_clean split a word by line et markup the sentences 19 # lia_clean split a word by line et markup the sentences
18 p=subprocess.Popen([os.environ["LIA_TAGG"]+'/script/lia_clean'],stdin=subprocess.PIPE,stdout=subprocess.PIPE) 20 cleanString= tagger.clean(dirtyString)
19 (cleanString, err) = p.communicate(input=dirtyString.encode('iso8859-1','backslashreplace')) 21 taggedString= tagger.tagg(cleanString)
20 #lia_tagg+lemm tagg words with function and give the lemm for each word 22 return taggedString
21 p2=subprocess.Popen([os.environ["LIA_TAGG"]+'/script/lia_tagg+lemm','-guess'],stdin=subprocess.PIPE,stdout=subprocess.PIPE)
22 (taggedString,err) =p2.communicate(input=cleanString)
23 # This is used beceause lia_tagg deal with iso8859 only
24 taggedString = taggedString.decode('iso8859').encode("utf8")
25 textTable = taggedString.split('\n')
26 # Creating a dictionary in order to encode it into Json
27 textDictionary = list()
28 for line in textTable :
29 lineTable =line.split()
30 #print lineTable
31 if lineTable:
32 wordDict=dict([('word',lineTable[0]),('markup',lineTable[1]),('lemm',lineTable[2])])
33 textDictionary.append(wordDict)
34 textJson = json.JSONEncoder().encode(textDictionary)
35 return textJson
36 if __name__ == '__main__': 23 if __name__ == '__main__':
37 app.debug = True 24 app.debug = True