Example #1
0
 def setUpClass(cls):
     metamap = MetaMap(
         metamap_path=
         "/home/share/programs/metamap/2016/public_mm/bin/metamap",
         cache_output=False)
     cls.pipeline = ClinicalPipeline(
         metamap)  # Will fail as MetaMap isn't installed
Example #2
0
    def test_with_metamap(self):
        """
        Constructs a model that memorizes an entity, predicts it on same file, writes to ann
        :return:
        """

        train_loader = DataLoader(self.train_dir)
        test_loader = DataLoader(self.test_dir)
        metamap = MetaMap(metamap_path="/home/share/programs/metamap/2016/public_mm/bin/metamap",
                          cache_output=False)

        train_loader.metamap(metamap)
        test_loader.metamap(metamap)

        pipeline = ClinicalPipeline(metamap, entities=['Strength'])

        learner = Learner(pipeline, train_loader)

        model = learner.train()

        predictor = Predictor(pipeline, test_loader, model=model)

        predictor.predict()

        with open(predictor.prediction_directory+"predict_test.ann") as f:
            self.assertEqual(f.read(), "T1	Strength 7 11	5 mg\n")
Example #3
0
    def test_with_metamap(self):

        loader = DataLoader(self.test_dir)
        metamap = MetaMap(
            metamap_path=
            "/home/share/programs/metamap/2016/public_mm/bin/metamap")

        loader.metamap(metamap)  #pre-cache metamap files

        pipeline = ClinicalPipeline(metamap, entities=['Strength'])

        learner = Learner(pipeline, loader)

        model = learner.train()

        self.assertIsInstance(learner, Learner)
Example #4
0
    def test_fit_with_clinical_pipeline(self):
        """
        Loads in training data and uses it to fit a model using the Clinical Pipeline
        :return:
        """
        train_loader = DataLoader(self.train_dir)
        metamap = MetaMap(
            metamap_path=
            "/home/share/programs/metamap/2016/public_mm/bin/metamap",
            cache_output=False)

        train_loader.metamap(metamap)

        pipeline = ClinicalPipeline(metamap, entities=['Strength'])

        model = Model(pipeline)
        model.fit(train_loader)

        self.assertIsInstance(model, Model)
        self.assertIsNot(model.model, None)
    def test_metamapping(self):
        with open(os.path.join(self.test_dir, 'test.txt'), 'w') as f:
            f.write("Contents of test file")

        with open(os.path.join(self.test_dir, 'test.ann'), 'w') as f:
            f.write("Example Ann File")

        loader = DataLoader(self.test_dir)

        metamap = MetaMap(
            metamap_path=
            "/home/share/programs/metamap/2016/public_mm/bin/metamap",
            cache_output=False)

        loader.metamap(metamap)
        """
        Metamap output cannot be tested through this wrapper due to how unit tests work (they override input/output
        streams which the wrapper relies on for calling the Metamap server). Instead we test that metamap works
        correctly and throws no errors - it will however output a null body for the metamapped contents in this test.
        """

        with open(self.test_dir + "/metamapped/test.metamapped", 'r') as f:
            self.assertEqual("{\"metamap\": null}", f.read())
Example #6
0
    def test_prediction_with_clinical_pipeline(self):
        """
        Constructs a model that memorizes an entity, predicts it on same file, writes to ann
        :return:
        """

        train_loader = DataLoader(self.train_dir)
        test_loader = DataLoader(self.test_dir)
        metamap = MetaMap(
            metamap_path=
            "/home/share/programs/metamap/2016/public_mm/bin/metamap",
            cache_output=False)

        train_loader.metamap(metamap)
        test_loader.metamap(metamap)

        pipeline = ClinicalPipeline(metamap, entities=['Strength'])

        model = Model(pipeline)
        model.fit(train_loader)
        model.predict(test_loader)

        with open(self.test_dir + "/predictions/" + "predict_test.ann") as f:
            self.assertEqual(f.read(), "T1	Strength 7 11	5 mg\n")
Example #7
0
import logging, sys

# print logs
logging.basicConfig(
    stream=sys.stdout,
    level=logging.DEBUG)  #set level=logging.DEBUG for more information

#entity types
entities = ['Reason', 'ADE', 'Drug']
# entities = ['Symptom', 'Form', 'Route', 'Frequency', 'Duration', 'Dosage', 'Strength', 'Drug']
# dirPred = '/home/mahendrand/VE/Predictions/CV/N2C2'
training_dataset = Dataset('/home/mahendrand/VE/Data/N2C2/data')

#set metamap path
metamap = MetaMap(
    metamap_path="/home/share/programs/metamap/2016/public_mm/bin/metamap",
    convert_ascii=True)
training_dataset.metamap(metamap)

# pipeline = ClinicalPipeline(metamap=metamap, entities=entities)
pipeline = SystematicReviewPipeline(metamap=metamap, entities=entities)
model = Model(
    pipeline, n_jobs=1
)  #distribute documents between 30 processes during training and prediction

model.fit(training_dataset)

#cross validation
# model.cross_validate(num_folds = 5, training_dataset = training_dataset, prediction_directory=dirPred, groundtruth_directory=True)

#location to store the clinical model
Example #8
0
 def setUpClass(cls):
     cls.metamap = MetaMap(
         metamap_path=
         "/home/share/programs/metamap/2016/public_mm/bin/metamap")
from medacy.pipeline_components import MetaMap

metamap = MetaMap(metamap_path="/home/share/programs/metamap/2016/public_mm/bin/metamap", cache_output=True)


file_to_map = "/home/aymulyar/development/medaCy/medacy/tests/pipeline_components/metamap/test.txt"
file = metamap.map_file(file_to_map)
print(file)