Package: drug-named-entity-recognition
🌐 fastdatascience.comDrug named entity recognition Python library by Fast Data Science💊 Drug named entity recognitionDeveloped by Fast Data Science,https://fastdatascience.comSource code athttps://github.com/fastdatascience/drug_named_entity_recognitionTutorial athttps://fastdatascience.com/drug-named-entity-recognition-python-library/This is a lightweight Python library for finding drug names in a string, otherwise known asnamed entity recognition (NER)and named entity linking.Please note this library finds only high confidence drugs and doesn't support misspellings at present.It also only finds the English names of these drugs. Names in other languages are not supported.It also doesn't find short code names of drugs, such as abbreviations commonly used in medicine, such as "Ceph" for "Cephradin" - as these are highly ambiguous.Interested in other kinds of named entity recognition (NER)? 💸Finances, 🎩company names, 🌎countries, 🗺️locations, proteins, 🧬genes, 🧪molecules?If your NER problem is common across industries and likely to have been seen before, there may be an off-the-shelf NER tool for your purposes, such as ourCountry Named Entity RecognitionPython library. Dictionary-based named entity recognition is not always the solution, as sometimes the total set of entities is an open set and can't be listed (e.g. personal names), so sometimes a bespoke trained NER model is the answer. For tasks like finding email addresses or phone numbers, regular expressions (simple rules) are sufficient for the job.If your named entity recognition or named entity linking problem is very niche and unusual, and a product exists for that problem, that product is likely to only solve your problem 80% of the way, and you will have more work trying to fix the final mile than if you had done the whole thing manually. Pleasecontact Fast Data Scienceand we'll be glad to discuss. For example, we've worked ona consultancy engagement to find molecule names in papers, and match author names to customerswhere the goal was to trace molecule samples ordered from a pharma company and identify when the samples resulted in a publication. For this case, there was no off-the-shelf library that we could use.For a problem like identifying country names in English, which is a closed set with well-known variants and aliases, and an off-the-shelf library is usually available.For identifying a set of molecules manufactured by a particular company, this is the kind of task more suited to aconsulting engagement.RequirementsPython 3.9 and above✉️Who to contact?You can contact Thomas Wood or the Fast Data Science team athttps://fastdatascience.com/.💻Installing drug named entity recognition Python packageYou can install fromPyPI.pip install drug-named-entity-recognition💡Usage examplesYou must first tokenise your input text using a tokeniser of your choice (NLTK, spaCy, etc).You pass a list of strings to thefind_drugsfunction.Example 1from drug_named_entity_recognition import find_drugs

find_drugs("i bought some Prednisone".split(" "))outputs a list of tuples.[({'name': 'Prednisone', 'synonyms': {'Sone', 'Sterapred', 'Deltasone', 'Panafcort', 'Prednidib', 'Cortan', 'Rectodelt', 'Prednisone', 'Cutason', 'Meticorten', 'Panasol', 'Enkortolon', 'Ultracorten', 'Decortin', 'Orasone', 'Winpred', 'Dehydrocortisone', 'Dacortin', 'Cortancyl', 'Encorton', 'Encortone', 'Decortisyl', 'Kortancyl', 'Pronisone', 'Prednisona', 'Predniment', 'Prednisonum', 'Rayos'}, 'medline_plus_id': 'a601102', 'mesh_id': 'D018931', 'drugbank_id': 'DB00635'}, 3, 3)]You can ignore case with:find_drugs("i bought some prednisone".split(" "), is_ignore_case=True)🤝Compatibility with other natural language processing librariesThe Drug Named Entity Recognition library is independent of other NLP tools and has no dependencies. You don't need any advanced system requirements and the tool is lightweight. However, it combines well with other libraries  such asspaCyor theNatural Language Toolkit (NLTK).Using Drug Named Entity Recognition together with spaCyHere is an example call to the tool with aspaCyDoc object:from drug_named_entity_recognition import find_drugs
import spacy
nlp = spacy.blank("en")
doc = nlp("i routinely rx rimonabant and pts prefer it")
find_drugs([t.text for t in doc], is_ignore_case=True)outputs:[({'name': 'Rimonabant', 'synonyms': {'Acomplia', 'Rimonabant', 'Zimulti'}, 'mesh_id': 'D063387', 'drugbank_id': 'DB06155'}, 3, 3)]Using Drug Named Entity Recognition together with NLTKYou can also use the tool together with theNatural Language Toolkit (NLTK):from drug_named_entity_recognition import find_drugs
from nltk.tokenize import wordpunct_tokenize
tokens = wordpunct_tokenize("i routinely rx rimonabant and pts prefer it")
find_drugs(tokens, is_ignore_case=True)📁Data sourcesThe main data source is from Drugbank, augmented by datasets from the NHS, MeSH, Medline Plus and Wikipedia.Update the Drugbank dictionaryIf you want to update the dictionary, you can use the data dump from Drugbank and replace the filedrugbank vocabulary.csv:Download the open data dump fromhttps://go.drugbank.com/releases/latest#open-dataUpdate the Wikipedia dictionaryIf you want to update the Wikipedia dictionary, download the dump from:https://meta.wikimedia.org/wiki/Data_dump_torrents#English_Wikipediaand runextract_drug_names_and_synonyms_from_wikipedia_dump.pyUpdate the MeSH dictionaryIf you want to update the dictionary, runpython download_mesh_dump_and_extract_drug_names_and_synonyms.pyThis will download the latest XML file from NIH.If the link doesn't work, download the open data dump manually fromhttps://www.nlm.nih.gov/. It should be called something likedesc2023.xml. And comment out the Wget/Curl commands in the code.License information for external data sourcesData from Drugbank is licensed underCC0.To the extent possible under law, the person who associated CC0 with the DrugBank Open Data has waived all copyright and related or neighboring rights to the DrugBank Open Data. This work is published from: Canada.Text from Wikipedia data dump is licensed underGNU Free Documentation LicenseandCreative Commons Attribution-Share-Alike 3.0 License.More information.Contributing to the Drug Named Entity Recognition libraryIf you'd like to contribute to this project, you can contact us athttps://fastdatascience.com/or make a pull request on ourGithub repository. You can alsoraise an issue.Developing the Drug Named Entity Recognition libraryAutomated testsTest code is intests/folder usingunittest.The testing tooltoxis used in the automation with GitHub Actions CI/CD.Use tox locallyInstall tox and run it:pip install tox
toxIn our configuration, tox runs a check of source distribution usingcheck-manifest(which requires your repo to be git-initialized (git init) and added (git add .) at least), setuptools's check, and unit tests using pytest. You don't need to install check-manifest and pytest though, tox will install them in a separate environment.The automated tests are run against several Python versions, but on your machine, you might be using only one version of Python, if that is Python 3.9, then run:tox -e py39Thanks to GitHub Actions' automated process, you don't need to generate distribution files locally. But if you insist, click to read the "Generate distribution files" section.🤖 Continuous integration/deployment to PyPIThis package is based on the templatehttps://pypi.org/project/example-pypi-package/This packageuses GitHub Actions for both testing and publishingis tested when pushingmasterormainbranch, and is published when create a releaseincludes test files in the source distributionusessetup.cfgforversion single-sourcing(setuptools 46.4.0+)🧍Re-releasing the package manuallyThe code to re-release Harmony on PyPI is as follows:source activate py311
pip install twine
rm -rf dist
python setup.py sdist
twine upload dist/*😊 Who worked on the Drug Named Entity Recognition library?The tool was developed:Thomas Wood (Fast Data Science)📜License of Drug Named Entity Recognition libraryMIT License. Copyright (c) 2023Fast Data Science✍️ Citing the Drug Named Entity Recognition libraryWood, T.A., Drug Named Entity Recognition [Computer software], Version 1.0.2, accessed athttps://fastdatascience.com/drug-named-entity-recognition-python-library, Fast Data Science Ltd (2023)@unpublished{drugnamedentityrecognition,
    AUTHOR = {Wood, T.A.},
    TITLE  = {Drug Named Entity Recognition (Computer software), Version 1.0.2},
    YEAR   = {2023},
    Note   = {To appear},
}