forked from CogStack/MedCAT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
130 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
house 34444 0.3232 0.123213 1.231231 | ||
dog 14444 0.76762 0.76767 1.45454 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import os | ||
import unittest | ||
from medcat.vocab import Vocab | ||
from medcat.cdb import CDB | ||
from medcat.cat import CAT | ||
|
||
|
||
class CATTests(unittest.TestCase): | ||
|
||
def setUp(self) -> None: | ||
self.cdb = CDB.load(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "examples", "cdb.dat")) | ||
self.vocab = Vocab.load(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "examples", "vocab.dat")) | ||
self.cdb.config.ner['min_name_len'] = 2 | ||
self.cdb.config.ner['upper_case_limit_len'] = 3 | ||
self.cdb.config.general['spell_check'] = True | ||
self.cdb.config.linking['train_count_threshold'] = 10 | ||
self.cdb.config.linking['similarity_threshold'] = 0.3 | ||
self.cdb.config.linking['train'] = True | ||
self.cdb.config.linking['disamb_length_limit'] = 5 | ||
self.cdb.config.general['full_unlink'] = True | ||
self.undertest = CAT(cdb=self.cdb, config=self.cdb.config, vocab=self.vocab) | ||
|
||
def test_pipeline(self): | ||
text = "The dog is sitting outside the house." | ||
doc = self.undertest(text) | ||
self.assertEqual(text, doc.text) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import os | ||
import shutil | ||
import unittest | ||
from medcat.config import Config | ||
from medcat.cdb_maker import CDBMaker | ||
|
||
|
||
class CDBTests(unittest.TestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls) -> None: | ||
config = Config() | ||
config.general["spacy_model"] = "en_core_sci_md" | ||
cls.cdb_maker = CDBMaker(config) | ||
|
||
def setUp(self) -> None: | ||
cdb_csv = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "examples", "cdb.csv") | ||
cdb_2_csv = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "examples", "cdb_2.csv") | ||
self.tmp_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "tmp") | ||
os.makedirs(self.tmp_dir, exist_ok=True) | ||
self.undertest = CDBTests.cdb_maker.prepare_csvs([cdb_csv, cdb_2_csv], full_build=True) | ||
|
||
def tearDown(self) -> None: | ||
shutil.rmtree(self.tmp_dir) | ||
|
||
def test_name2cuis(self): | ||
self.assertEqual({ | ||
'second~csv': ['C0000239'], | ||
'virus': ['C0000039', 'C0000139'], | ||
'virus~k': ['C0000039', 'C0000139'], | ||
'virus~m': ['C0000039', 'C0000139'], | ||
'virus~z': ['C0000039', 'C0000139'] | ||
}, self.undertest.name2cuis) | ||
|
||
def test_cui2names(self): | ||
self.assertEqual({ | ||
'C0000039': {'virus~z', 'virus~k', 'virus~m', 'virus'}, | ||
'C0000139': {'virus~z', 'virus', 'virus~m', 'virus~k'}, | ||
'C0000239': {'second~csv'} | ||
}, self.undertest.cui2names) | ||
|
||
def test_cui2preferred_name(self): | ||
self.assertEqual({'C0000039': 'Virus', 'C0000139': 'Virus Z'}, self.undertest.cui2preferred_name) | ||
|
||
def test_cui2type_ids(self): | ||
self.assertEqual({'C0000039': {'T109', 'T234', 'T123'}, 'C0000139': set(), 'C0000239': set()}, self.undertest.cui2type_ids) | ||
|
||
def test_save_and_load(self): | ||
cdb_path = f"{self.tmp_dir}/cdb.dat" | ||
self.undertest.save(cdb_path) | ||
self.undertest.load(cdb_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import os | ||
import shutil | ||
import unittest | ||
from medcat.vocab import Vocab | ||
|
||
|
||
class CATTests(unittest.TestCase): | ||
|
||
def setUp(self) -> None: | ||
self.undertest = Vocab() | ||
self.tmp_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "tmp") | ||
os.makedirs(self.tmp_dir, exist_ok=True) | ||
|
||
def tearDown(self) -> None: | ||
shutil.rmtree(self.tmp_dir) | ||
|
||
def test_add_words(self): | ||
self.undertest.add_words(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "examples", "vocab_data.txt")) | ||
self.assertEqual(["house", "dog"], list(self.undertest.vocab.keys())) | ||
|
||
def test_add_word(self): | ||
self.undertest.add_word("test", cnt=31, vec=[1.42, 1.44, 1.55]) | ||
self.assertEqual(["test"], list(self.undertest.vocab.keys())) | ||
self.assertTrue("test" in self.undertest) | ||
|
||
def test_count(self): | ||
self.undertest.add_words(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "examples", "vocab_data.txt")) | ||
self.assertEqual(34444, self.undertest.count("house")) | ||
|
||
def test_save_and_load(self): | ||
self.undertest.add_words(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "examples", "vocab_data.txt")) | ||
self.undertest.add_word("test", cnt=31, vec=[1.42, 1.44, 1.55]) | ||
vocab_path = f"{self.tmp_dir}/vocab.dat" | ||
self.undertest.save(vocab_path) | ||
vocab = Vocab.load(vocab_path) | ||
self.assertEqual(["house", "dog", "test"], list(vocab.vocab.keys())) | ||
|
||
|
||
|