Commit 9aab1de7383750179acc696485ad651e5c2b4bb2
1 parent
6c1479b8b7
Exists in
soap
Tentative Soap infructueuse
Showing 2 changed files with 17 additions and 6 deletions Inline Diff
processor/Orkis.py
1 | from BaseProcessor import baseProcessor | 1 | from BaseProcessor import baseProcessor |
2 | import nltk | 2 | import nltk |
3 | from LiaTools import * | 3 | from LiaTools import * |
4 | class Orkis(baseProcessor): | 4 | class Orkis(baseProcessor): |
5 | """ Processor for Orkis """ | 5 | """ Processor for Orkis """ |
6 | def __init__(self,dirtyString): | 6 | def __init__(self,dirtyString): |
7 | self.tagger=Tagger() | 7 | self.tagger=Tagger() |
8 | self.phoner=Phoner() | 8 | self.phoner=Phoner() |
9 | self.dico ={} | 9 | self.dico ={} |
10 | self.string=dirtyString | 10 | self.string=dirtyString |
11 | def isReady(self): | 11 | def isReady(self): |
12 | self.phoner.isReady() | 12 | self.phoner.isReady() |
13 | self.tagger.isReady() | 13 | self.tagger.isReady() |
14 | def __str__(self): | ||
15 | string="" | ||
16 | for word in self.dico: | ||
17 | string += (word+';') | ||
18 | for lemWord in self.dico[word][0]: | ||
19 | string += (lemWord+" ") | ||
20 | string +=";" | ||
21 | for phonWord in self.dico[word][1]: | ||
22 | string += (phonWord+" ") | ||
23 | string += ';' | ||
24 | string+='\n' | ||
25 | return string | ||
14 | def clean(self): | 26 | def clean(self): |
15 | stopword=StopWord() | 27 | stopword=StopWord() |
16 | self.string=stopword.RemoveStopList(self.string) | 28 | self.string=stopword.RemoveStopList(self.string) |
17 | def insertLem(self): | 29 | def insertLem(self): |
18 | self.cleanString=self.tagger.clean(self.string) | 30 | self.cleanString=self.tagger.clean(self.string) |
19 | taggedString=self.tagger.tagg(self.cleanString) | 31 | taggedString=self.tagger.tagg(self.cleanString) |
20 | self.tableLem = taggedString.rstrip().split("\n") | 32 | self.tableLem = taggedString.rstrip().split("\n") |
21 | for line in taggedString.rstrip().split("\n"): | 33 | for line in taggedString.rstrip().split("\n"): |
22 | table = line.rstrip().split(" ") | 34 | table = line.rstrip().split(" ") |
23 | if not table[0] in self.dico : | 35 | if not table[0] in self.dico : |
24 | self.dico[table[0]]=[set(),set()] | 36 | self.dico[table[0]]=[set(),set()] |
25 | self.dico[table[0]][0].add(table[2]) | 37 | self.dico[table[0]][0].add(table[2]) |
26 | def insertPhon(self): | 38 | def insertPhon(self): |
27 | phonedString=self.phoner.phon(self.cleanString) | 39 | phonedString=self.phoner.phon(self.cleanString) |
28 | self.tablephon= phonedString.rstrip().split("\n") | 40 | self.tablephon= phonedString.rstrip().split("\n") |
29 | for line in phonedString.rstrip().split("\n"): | 41 | for line in phonedString.rstrip().split("\n"): |
30 | table = line.rstrip().split(" ") | 42 | table = line.rstrip().split(" ") |
31 | if table[0] in self.dico: | 43 | if table[0] in self.dico: |
32 | self.dico[table[0]][1].add(table[1]) | 44 | self.dico[table[0]][1].add(table[1]) |
33 | def getDico(self): | 45 | def getDico(self): |
34 | self.clean() | 46 | self.clean() |
35 | self.insertLem() | 47 | self.insertLem() |
36 | self.insertPhon() | 48 | self.insertPhon() |
37 | table=[] | 49 | table=[] |
38 | for i in self.dico: | 50 | for i in self.dico: |
39 | if not i == "<s>": | 51 | if not i == "<s>": |
40 | list=[] | 52 | list=[] |
41 | list.append(i) | 53 | list.append(i) |
42 | for indice in self.dico[i][0]: | 54 | for indice in self.dico[i][0]: |
43 | list.append(indice) | 55 | list.append(indice) |
44 | for indice in self.dico[i][1]: | 56 | for indice in self.dico[i][1]: |
45 | list.append(indice) | 57 | list.append(indice) |
46 | ligne= " ".join(list) | 58 | ligne= " ".join(list) |
47 | table.append(ligne) | 59 | table.append(ligne) |
48 | return "\n".join(table) | 60 | return "\n".join(table) |
49 | 61 |
webtagger.py
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 lxml import etree | ||
5 | from flask import Flask, request, render_template | 6 | from flask import Flask, request, render_template |
6 | from processor.LiaTools import * | 7 | from processor.LiaTools import * |
7 | from processor.Orkis import Orkis | 8 | from processor.Orkis import Orkis |
8 | from flaskext.enterprise import Enterprise | 9 | from flaskext.enterprise import Enterprise |
9 | 10 | from time import ctime | |
10 | app = Flask(__name__) | 11 | app = Flask(__name__) |
11 | enterprise = Enterprise(app) | 12 | enterprise = Enterprise(app) |
12 | 13 | ||
13 | @app.route("/") | 14 | @app.route("/") |
14 | def docs(): | 15 | def docs(): |
15 | return render_template('index.html') | 16 | return render_template('index.html') |
16 | 17 | ||
17 | @app.route("/tagger",methods=['POST']) | 18 | @app.route("/tagger",methods=['POST']) |
18 | def cleaner(): | 19 | def cleaner(): |
19 | # Receive String from post parametre Raw text | 20 | # Receive String from post parametre Raw text |
20 | dirtyString= request.values[u'string'] | 21 | dirtyString= request.values[u'string'] |
21 | # Charging Processor et check if they are okay ( aim is to dynamic charge later ) | 22 | # Charging Processor et check if they are okay ( aim is to dynamic charge later ) |
22 | orkisProc = Orkis(dirtyString) | 23 | orkisProc = Orkis(dirtyString) |
23 | # Processing | 24 | # Processing |
24 | # Adding lemm of each words cause we went ther phonem too | 25 | # Adding lemm of each words cause we went ther phonem too |
25 | taggedTable= orkisProc.getDico() | 26 | taggedTable= orkisProc.getDico() |
26 | # Returning a row text to be parse client side | 27 | # Returning a row text to be parse client side |
27 | return unicode(taggedTable) | 28 | return unicode(taggedTable) |
28 | 29 | ||
29 | class OrkisService(enterprise.SOAPService): | 30 | class OrkisService(enterprise.SOAPService): |
30 | @enterprise.soap(enterprise.String,_returns=enterprise._sp.String) | 31 | @enterprise.soap(returns=enterprise._sp.String) |
31 | def get_phon(self,string): | 32 | def get_phon(self): |
32 | orkisProc=Orkis(string) | 33 | return ctime() |
33 | return orkisProc.getDico() | ||
34 | |||
35 | 34 | ||
36 | if __name__ == '__main__': | 35 | if __name__ == '__main__': |
37 | app.debug = True | 36 | app.debug = True |
38 | app.run(host='0.0.0.0') | 37 | app.run(host='0.0.0.0') |