Requires the installation of PyMedExt_core PyMedExt_core
It can be done using requirements.txt
pip install -r requirements.txt
Installation via pip:
pip install git+git://github.com/equipe22/pymedext_eds.git@master#egg=pymedext_eds
Cloning the repository:
git clone https://github.com/equipe22/pymedext_eds.git
cd pymedext_eds
pip install .
All the annotators are defined in the pymedext_eds.annotators module. You will find a description of the existing annotators in the next section.
from pymedext_eds.utils import rawtext_loader
from pymedext_eds.annotators import Endlines, SentenceTokenizer, \
RegexMatcher, Pipeline
from pymedext_eds.viz import display_annotations
data_path = pkg_resources.resource_filename('pymedext_eds', 'data/demo')
file_list = glob(data_path + '/*.txt')
docs = [rawtext_loader(x) for x in file_list]
endlines = Endlines(['raw_text'], 'endlines', 'endlines:v1')
sentences = SentenceTokenizer(['endlines'], 'sentence', 'sentenceTokenizer:v1')
regex = RegexMatcher(['endlines','syntagme'], 'regex', 'RegexMatcher:v1', 'list_regexp.json')
pipeline = Pipeline(pipeline = [endlines, sentences, regex])
annotated_docs = pipeline.annotate(docs)
from pprint import pprint
pprint(annotated_docs[0].get_annotations('regex')[10].to_dict())
display_annotations(chunk[0], ['regex'])
Installation
pip install quickuml
s or python setup.py install
. On macOS, using anaconda is strongly recommended†.Create a QuickUMLS installation Initialize the system by running python -m quickumls.install <umls_installation_path> <destination_path>
, where <umls_installation_path>
is where the installation files are (in particular, we need MRCONSO.RRF
and MRSTY.RRF
) and <destination_path>
is the directory where the QuickUmls data files should be installed. This process will take between 5 and 30 minutes depending how fast the CPU and the drive where UMLS and QuickUMLS files are stored are (on a system with a Intel i7 6700K CPU and a 7200 RPM hard drive, initialization takes 8.5 minutes).
python -m quickumls.install
supports the following optional arguments:
†: If the installation fails on macOS when using Anaconda, install leveldb first by running conda install -c conda-forge python-leveldb
.
import flask
from flask import Flask, render_template, request
from pymedext_eds.annotators import Endlines, SentenceTokenizer, Hypothesis, \
ATCDFamille, SyntagmeTokenizer, Negation, RegexMatcher, \
Pipeline
endlines = Endlines(['raw_text'], 'endlines', 'endlines:v1')
sentences = SentenceTokenizer(['endlines'], 'sentence', 'sentenceTokenizer:v1')
hypothesis = Hypothesis(['sentence'], 'hypothesis', 'hypothesis:v1')
family = ATCDFamille(['sentence'], 'context', 'ATCDfamily:v1')
syntagmes = SyntagmeTokenizer(['sentence'], 'syntagme', 'SyntagmeTokenizer:v1')
negation = Negation(['syntagme'], 'negation', 'Negation:v1')
regex = RegexMatcher(['endlines','syntagme'], 'regex', 'RegexMatcher:v1', 'list_regexp.json')
pipeline = Pipeline(pipeline = [endlines, sentences, hypothesis, family, syntagmes, negation, regex])
app=Flask(__name__)
@app.route('/annotate',methods = ['POST'])
def result():
if request.method == 'POST':
return pipeline.__call__(request)
if __name__ == '__main__':
app.run(port = 6666, debug=True)
Save this code in demo_flask_server.py
and run it using:
python demo_flask_server.py
import requests
from pymedextcore.document import Document
data_path = pkg_resources.resource_filename('pymedext_eds', 'data/demo')
file_list = glob(data_path + '/*.txt')
docs = [rawtext_loader(x) for x in file_list]
json_doc = [doc.to_dict() for doc in docs]
res = requests.post(f"http://127.0.0.1:6666/annotate", json = json_doc)
if res.status_code == 200:
res = res.json()['result']
docs = [Document.from_dict(doc) for doc in res ]
first create a file .git-credentials and replace user and pass by your github credentials such has
https://user:pass@github.com
WARNING :never add it on the git !!!
docker build -f eds_apps/Dockerfile_backend -t pymedext-eds:v1 .
#if proxy add
docker build -f eds_apps/Dockerfile_backend -t pymedext-eds:v1 \
--buildargs http_proxy="proxy" \
--buildargs https_proxy="proxy" .
docker run --rm -d -p 6666:6666 pymedext-eds:v1 python3 demo_flask.py