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

Implements NER - to use send http get request to {domain}/ner with form data...

Implements NER  - to use send http get request to {domain}/ner with form data key = page / value = document/s sends back json success with output containing ner results
parent a8227382
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.9 (cognistance)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
......
from flask import make_response, jsonify
from func.ner.ner import *
from func.usas.usas import *
......@@ -7,7 +9,11 @@ from func.usas.usas import *
# Returns NER results
def get_ner_for_data(page):
result = run_ner_on_text(page)
return result
if result["code"] == "SUCCESS":
return make_response(jsonify(result), 201)
return make_response(jsonify(result), 400)
def get_usas_for_data():
......
......@@ -5,14 +5,18 @@ from transformers import pipeline
# Perform NER on Text
def run_ner_on_text(page):
ner_driver = CkipNerChunker(model="bert-base")
ws_driver = CkipWordSegmenter(device=-1)
txt = [
"傅達仁今將執行安樂死,卻突然爆出自己20年前遭緯來體育台封殺,他不懂自己哪裡得罪到電視台。",
"美國參議院針對今天總統布什所提名的勞工部長趙小蘭展開認可聽證會,預料她將會很順利通過參議院支持,成為該國有史以來第一位的華裔女性內閣成員。",
"空白 也是可以的~",
]
data = []
ner = ner_driver([page])
ner = ner_driver(txt)
print(ner)
return "hello ner"
for item in ner[0]:
word = item.word
ner = item.ner
idx = item.idx
obj = {"word":word, "translation": "" , "ner":ner, "idx":idx}
data.append(obj)
result = {'output': data,'message': 'Done', 'code': 'SUCCESS'}
return result
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