Exemplo n.º 1
0
    def test_init_from_sqlite3_conn_specific_cols(self):
        from medspacy.io.db_connect import DbConnect
        import sqlite3

        sq_conn = sqlite3.connect(db)
        cursor = sq_conn.cursor()
        db_conn = DbConnect(conn=sq_conn)

        cols = ["label_", "text", "is_negated", "section_category"]

        db_dtypes = [
            "varchar(100)",
            "varchar(100)",
            "int",
            "varchar(100)",
        ]

        from medspacy.io.db_writer import DbWriter

        writer = DbWriter(db_conn,
                          "ents",
                          cols=cols,
                          col_types=db_dtypes,
                          create_table=True,
                          drop_existing=True)
        writer.write(doc)
        cursor.execute("SELECT * FROM ents;")
        rslts = cursor.fetchone()
        assert rslts == ("CONDITION", "pneumonia", True, None)
        db_conn.close()
Exemplo n.º 2
0
 def test_init_from_sqlite3_conn(self):
     from medspacy.io.db_connect import DbConnect
     import sqlite3
     sq_conn = sqlite3.connect(db)
     db_conn = DbConnect(conn=sq_conn)
     assert db_conn is not None
     db_conn.close()
Exemplo n.º 3
0
 def test_init_from_sqlite3_conn_defaults(self):
     """Test writing with default values for ent attributes."""
     sq_conn = sqlite3.connect(db)
     cursor = sq_conn.cursor()
     db_conn = DbConnect(conn=sq_conn)
     from medspacy.io.db_writer import DbWriter
     writer = DbWriter(db_conn, "ents", cols=None, col_types=None,
                       create_table=True, drop_existing=False)
     writer.write(doc)
     cursor.execute("SELECT * FROM ents;")
     rslts = cursor.fetchone()
     assert rslts == ('pneumonia', 24, 33, 'CONDITION', 1, 0, 0, 0, 0, None, None)
     db_conn.close()
Exemplo n.º 4
0
    def test_init_from_sqlite3_conn(self):
        from medspacy.io.db_connect import DbConnect
        import sqlite3
        create_test_db(db)
        sq_conn = sqlite3.connect(db)

        db_conn = DbConnect(conn=sq_conn)
        from medspacy.io.db_reader import DbReader
        reader = DbReader(db_conn, "SELECT text_id, text FROM texts")
        rslts = reader.read()
        assert rslts[0] == (1, "Patient with a history of breast ca")
        assert rslts[1] == (2, "There is no evidence of pneumonia.")
        db_conn.close()
Exemplo n.º 5
0
    def test_init_from_sqlite3_conn(self):
        from medspacy.io.db_connect import DbConnect
        import sqlite3
        create_test_db(db)
        sq_conn = sqlite3.connect(db)

        db_conn = DbConnect(conn=sq_conn)

        from medspacy.io.db_reader import DbReader
        reader = DbReader(db_conn, "SELECT text_id, text FROM texts")

        from medspacy.io.db_writer import DbWriter
        writer = DbWriter(db_conn,
                          "ents",
                          ["text_id"] + doc_consumer.dtype_attrs["ent"],
                          ["int"] + db_dtypes,
                          create_table=True,
                          drop_existing=False)

        from medspacy.io.pipeline import Pipeline
        pipeline = Pipeline(reader, writer, nlp, "ent")
        pipeline.process()

        sq_conn = sqlite3.connect(db)
        cursor = sq_conn.cursor()
        cursor.execute("SELECT * FROM ents;")
        rslts = cursor.fetchall()
        assert rslts[0] == (1, "pneumonia", "CONDITION", True, None)
        assert rslts[1] == (2, "breast ca", "CONDITION", False, None)
        sq_conn.close()
Exemplo n.º 6
0
    "pattern": [{
        "LOWER": "=",
        "OP": "+"
    }]
}])
consumer = DocConsumer(
    nlp, context=True,
    sectionizer=True)  # DocConsumer has optional bool context and sectionizer
nlp.add_pipe(sectionizer)
nlp.add_pipe(context)
nlp.add_pipe(consumer)
#####################################################

#####################################################
# CREATING DB CONNECTIONS
db_read_conn = DbConnect(driver, server, db, user, pwd)
db_write_conn = DbConnect(driver, server, db, user, pwd)
#####################################################

#####################################################
# CREATING DB READ/WRITERS
db_reader = DbReader(db_read_conn, read_query, start, end,
                     read_batch_size)  # start, end, read_batch_size optional
db_writer = DbWriter(db_write_conn, destination_table, create_table,
                     drop_existing, write_batch_size, cols, col_types)
#####################################################

#####################################################
# CREATING PIPELINE
pipeline = Pipeline(db_reader, db_writer, nlp, row_type)
#####################################################
Exemplo n.º 7
0
    def test_init_from_conn_info(self):
        from medspacy.io.db_connect import DbConnect

        db_conn = DbConnect(driver, server, db, user, pwd)
        assert db_conn is not None