Skip to content
Snippets Groups Projects
Commit cc1be73c authored by Thomas Edwards's avatar Thomas Edwards
Browse files

Work towards USAS + ner + translation + sentiment analysis

parent 85589304
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ from flask import make_response, jsonify ...@@ -2,6 +2,7 @@ from flask import make_response, jsonify
from func.ner.ner import * from func.ner.ner import *
from func.sentiment.sentiment import * from func.sentiment.sentiment import *
from func.translation.translation import run_translation_on_text
from func.usas.usas import * from func.usas.usas import *
...@@ -16,6 +17,18 @@ def get_ner_for_data(page): ...@@ -16,6 +17,18 @@ def get_ner_for_data(page):
return make_response(jsonify(result), 400) return make_response(jsonify(result), 400)
# Perform translation on a file
# TAKES XML text page
# Returns english translation results
def get_translation_for_data(page):
result = run_translation_on_text(page)
if result["code"] == "SUCCESS":
return make_response(jsonify(result), 201)
return make_response(jsonify(result), 400)
# Perform USAS analysis on a file # Perform USAS analysis on a file
# TAKES XML text page # TAKES XML text page
......
import torch
from ckip_transformers.nlp import CkipWordSegmenter, CkipPosTagger, CkipNerChunker
from transformers import pipeline
import pandas as pd
from shared.translate import translate
#page = '尼罗河 是一条流經非洲東部與北部的河流,與中非地區的剛果河、非洲南部的赞比西河以及西非地区的尼日尔河並列非洲最大的四個河流系統。'
# Perform NER on Text
def run_translation_on_text(page):
translation = '<p>Translation</p>'
translation = translation + '<span>'
translation = translation + translate(page).text
translation = translation +'</span>'
result = {'output': translation,'message': 'Done', 'code': 'SUCCESS'}
return result
...@@ -11,7 +11,7 @@ app.config['CORS_HEADERS'] = 'Content-Type' ...@@ -11,7 +11,7 @@ app.config['CORS_HEADERS'] = 'Content-Type'
@app.route("/") @app.route("/")
def home(): def home():
return "Hello World!" return "Success!"
@app.route("/system-check") @app.route("/system-check")
...@@ -23,17 +23,23 @@ def test(): ...@@ -23,17 +23,23 @@ def test():
def ner(): def ner():
request_data = request.get_json() request_data = request.get_json()
#print(request_data)
page = request_data['page'] page = request_data['page']
result = get_ner_for_data(page) result = get_ner_for_data(page)
return result return result
@app.route("/translate", methods=['POST'])
def translate():
request_data = request.get_json()
page = request_data['page']
result = get_translation_for_data(page)
return result
@app.route("/usas", methods=['POST']) @app.route("/usas", methods=['POST'])
def usas(): def usas():
print('hello')
request_data = request.get_json() request_data = request.get_json()
print(request_data)
page = request_data['page'] page = request_data['page']
result = get_usas_for_data(page) result = get_usas_for_data(page)
...@@ -43,7 +49,6 @@ def usas(): ...@@ -43,7 +49,6 @@ def usas():
def sentiment(): def sentiment():
request_data = request.get_json() request_data = request.get_json()
print(request_data)
page = request_data['page'] page = request_data['page']
result = get_sentiment_for_data(page) result = get_sentiment_for_data(page)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment