webtagger.py 1.54 KB
# -*- coding: utf-8 -*- 
import subprocess
import os
import json
from flask import Flask, request, render_template
app = Flask(__name__)

def docs():
    return render_template('index.html')

def cleaner():
    # Receive String from post parametre Raw text ( Json )
    dirtyString= request.json[u'string']
    # send the String throught LIA_TAGG script  thank's to pipe
    # lia_clean split a word by line et markup the sentences
    (cleanString, err) = p.communicate(input=dirtyString.encode('iso8859-1','backslashreplace'))
    #lia_tagg+lemm tagg words with function and give the lemm for each word
    (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:
    textJson = json.JSONEncoder().encode(textDictionary) 
    return textJson
if __name__ == '__main__':
    app.debug = True