From 9fd851d7dd960a7912e1aae2d852f0bb3676ed13 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 8 Mar 2023 09:41:46 -0500 Subject: [PATCH 1/2] feat: add filesystem.covid_symptoms_path to get bsv path directly (Also add umls_semantic_groups_path.) filesystem.covid_symptoms() was intended to be the primary way to ask for the covid symptoms list, but there are also use cases where it's easiest to directly access the bsv file. So here it is. --- .gitignore | 3 ++- ctakesclient/__init__.py | 2 +- ctakesclient/filesystem.py | 14 ++++++++++++-- tests/test_filesystem.py | 16 ++++++++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 50959b4..e6090c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Project specific +/.idea/ example-output/ example-phi-build/ @@ -233,4 +234,4 @@ fabric.properties .idea/httpRequests # Android studio 3.1+ serialized cache file -.idea/caches/build_file_checksums.ser \ No newline at end of file +.idea/caches/build_file_checksums.ser diff --git a/ctakesclient/__init__.py b/ctakesclient/__init__.py index f4eede3..394780b 100644 --- a/ctakesclient/__init__.py +++ b/ctakesclient/__init__.py @@ -1,6 +1,6 @@ """Public API""" -__version__ = "2.0.0" +__version__ = "2.1.0" from . import client from . import filesystem diff --git a/ctakesclient/filesystem.py b/ctakesclient/filesystem.py index c8371a4..079e2fc 100644 --- a/ctakesclient/filesystem.py +++ b/ctakesclient/filesystem.py @@ -218,9 +218,19 @@ def _resource_file(filename: str) -> str: return os.path.join(os.path.dirname(__file__), "resources", filename) +def covid_symptoms_path() -> str: + """Returns the path to a bsv file of covid symptoms""" + return _resource_file("covid_symptoms.bsv") + + def covid_symptoms() -> List[BsvConcept]: """Returns a list of known covid symptoms""" - return list_bsv_concept(_resource_file("covid_symptoms.bsv")) + return list_bsv_concept(covid_symptoms_path()) + + +def umls_semantic_groups_path() -> str: + """Returns the path to a bsv file of UMLS semantic groups""" + return _resource_file("SemGroups_2018.bsv") def umls_semantic_groups() -> List[BsvSemanticType]: @@ -229,4 +239,4 @@ def umls_semantic_groups() -> List[BsvSemanticType]: See https://lhncbc.nlm.nih.gov/ii/tools/MetaMap/documentation/SemanticTypesAndGroups.html """ - return list_bsv_semantics(_resource_file("SemGroups_2018.bsv")) + return list_bsv_semantics(umls_semantic_groups_path()) diff --git a/tests/test_filesystem.py b/tests/test_filesystem.py index 28cca91..1afceee 100644 --- a/tests/test_filesystem.py +++ b/tests/test_filesystem.py @@ -1,14 +1,30 @@ """Tests for the filesystem module""" +import os import unittest +import ddt + from ctakesclient import filesystem from tests.test_resources import PathResource +@ddt.ddt class TestCovidSymptomsBSV(unittest.TestCase): """Test case for files loaded from bsv""" + @ddt.data( + filesystem.covid_symptoms_path, + filesystem.umls_semantic_groups_path, + ) + def test_path_methods(self, method): + """Verify we hand out a bsv path correctly""" + path = method() + self.assertIsInstance(path, str) + self.assertTrue(path.endswith(".bsv")) + self.assertTrue(os.path.isabs(path)) + self.assertTrue(os.path.isfile(path)) + def test_covid_symptom_concepts(self): """ Symptoms of COVID-19 From 691a563afae625106e7f95f884d2305a881ebbf4 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 8 Mar 2023 09:46:08 -0500 Subject: [PATCH 2/2] chore: update code for recent pylints --- .pylintrc | 6 +++--- ctakesclient/text2fhir.py | 2 +- ctakesclient/typesystem.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.pylintrc b/.pylintrc index 514d1a4..98c6c6b 100644 --- a/.pylintrc +++ b/.pylintrc @@ -432,6 +432,6 @@ valid-metaclass-classmethod-first-arg=mcs # Exceptions that will emit a warning when being caught. Defaults to # "Exception" -overgeneral-exceptions=StandardError, - Exception, - BaseException +overgeneral-exceptions=builtins.StandardError, + builtins.Exception, + builtins.BaseException diff --git a/ctakesclient/text2fhir.py b/ctakesclient/text2fhir.py index babea4a..39d5bfb 100644 --- a/ctakesclient/text2fhir.py +++ b/ctakesclient/text2fhir.py @@ -237,7 +237,7 @@ def _nlp_polarity(polarity: Polarity) -> Extension: def _nlp_derivation_span(docref_id, span: Span) -> Extension: - return _nlp_derivation(docref_id=docref_id, offset=span.begin, length=(span.end - span.begin)) + return _nlp_derivation(docref_id=docref_id, offset=span.begin, length=span.end - span.begin) def _nlp_derivation(docref_id, offset=None, length=None) -> Extension: diff --git a/ctakesclient/typesystem.py b/ctakesclient/typesystem.py index 83c73ad..ffc3e30 100644 --- a/ctakesclient/typesystem.py +++ b/ctakesclient/typesystem.py @@ -137,7 +137,7 @@ def parse_polarity(polarity) -> Polarity: elif polarity == 0: return Polarity.pos else: - raise Exception(f"polarity unknown: {polarity}") + raise ValueError(f"polarity unknown: {polarity}") @staticmethod def parse_mention(mention: str) -> UmlsTypeMention: