Skip to content

Commit 8c50916

Browse files
authored
Merge pull request #48 from Machine-Learning-for-Medical-Language/mikix/expose-bsv-paths
feat: add filesystem.covid_symptoms_path to get bsv path directly
2 parents 9938543 + 691a563 commit 8c50916

File tree

7 files changed

+36
-9
lines changed

7 files changed

+36
-9
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Project specific
22

3+
/.idea/
34
example-output/
45
example-phi-build/
56

@@ -233,4 +234,4 @@ fabric.properties
233234
.idea/httpRequests
234235

235236
# Android studio 3.1+ serialized cache file
236-
.idea/caches/build_file_checksums.ser
237+
.idea/caches/build_file_checksums.ser

.pylintrc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,6 @@ valid-metaclass-classmethod-first-arg=mcs
432432

433433
# Exceptions that will emit a warning when being caught. Defaults to
434434
# "Exception"
435-
overgeneral-exceptions=StandardError,
436-
Exception,
437-
BaseException
435+
overgeneral-exceptions=builtins.StandardError,
436+
builtins.Exception,
437+
builtins.BaseException

ctakesclient/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Public API"""
22

3-
__version__ = "2.0.0"
3+
__version__ = "2.1.0"
44

55
from . import client
66
from . import filesystem

ctakesclient/filesystem.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,19 @@ def _resource_file(filename: str) -> str:
218218
return os.path.join(os.path.dirname(__file__), "resources", filename)
219219

220220

221+
def covid_symptoms_path() -> str:
222+
"""Returns the path to a bsv file of covid symptoms"""
223+
return _resource_file("covid_symptoms.bsv")
224+
225+
221226
def covid_symptoms() -> List[BsvConcept]:
222227
"""Returns a list of known covid symptoms"""
223-
return list_bsv_concept(_resource_file("covid_symptoms.bsv"))
228+
return list_bsv_concept(covid_symptoms_path())
229+
230+
231+
def umls_semantic_groups_path() -> str:
232+
"""Returns the path to a bsv file of UMLS semantic groups"""
233+
return _resource_file("SemGroups_2018.bsv")
224234

225235

226236
def umls_semantic_groups() -> List[BsvSemanticType]:
@@ -229,4 +239,4 @@ def umls_semantic_groups() -> List[BsvSemanticType]:
229239
230240
See https://lhncbc.nlm.nih.gov/ii/tools/MetaMap/documentation/SemanticTypesAndGroups.html
231241
"""
232-
return list_bsv_semantics(_resource_file("SemGroups_2018.bsv"))
242+
return list_bsv_semantics(umls_semantic_groups_path())

ctakesclient/text2fhir.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def _nlp_polarity(polarity: Polarity) -> Extension:
237237

238238

239239
def _nlp_derivation_span(docref_id, span: Span) -> Extension:
240-
return _nlp_derivation(docref_id=docref_id, offset=span.begin, length=(span.end - span.begin))
240+
return _nlp_derivation(docref_id=docref_id, offset=span.begin, length=span.end - span.begin)
241241

242242

243243
def _nlp_derivation(docref_id, offset=None, length=None) -> Extension:

ctakesclient/typesystem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def parse_polarity(polarity) -> Polarity:
137137
elif polarity == 0:
138138
return Polarity.pos
139139
else:
140-
raise Exception(f"polarity unknown: {polarity}")
140+
raise ValueError(f"polarity unknown: {polarity}")
141141

142142
@staticmethod
143143
def parse_mention(mention: str) -> UmlsTypeMention:

tests/test_filesystem.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
"""Tests for the filesystem module"""
22

3+
import os
34
import unittest
45

6+
import ddt
7+
58
from ctakesclient import filesystem
69
from tests.test_resources import PathResource
710

811

12+
@ddt.ddt
913
class TestCovidSymptomsBSV(unittest.TestCase):
1014
"""Test case for files loaded from bsv"""
1115

16+
@ddt.data(
17+
filesystem.covid_symptoms_path,
18+
filesystem.umls_semantic_groups_path,
19+
)
20+
def test_path_methods(self, method):
21+
"""Verify we hand out a bsv path correctly"""
22+
path = method()
23+
self.assertIsInstance(path, str)
24+
self.assertTrue(path.endswith(".bsv"))
25+
self.assertTrue(os.path.isabs(path))
26+
self.assertTrue(os.path.isfile(path))
27+
1228
def test_covid_symptom_concepts(self):
1329
"""
1430
Symptoms of COVID-19

0 commit comments

Comments
 (0)