Пример #1
0
def key(a):
    if "effectiveInstant" in a:
        return Just("effectiveInstant")
    elif "effectiveDateTime" in a:
        return Just("effectiveDateTime")
    elif "onsetDateTime" in a:
        return Just("onsetDateTime")
    elif "authoredOn" in a:
        return Just("authoredOn")
    elif "dispenseRequest" in a:
        return Just(["dispenseRequest", "validityPeriod", "start"])
    return Nothing
Пример #2
0
def result(source_id, source_curie, edge_id, node_name, target_id, table,
           filter_regex, score, score_name):
    node_ids = name_to_ids(table, filter_regex, node_name)
    if len(node_ids) == 0:
        return Nothing
    else:
        node_id, *equivalent_ids = gen_node_id_and_equivalent_ids(node_ids)

        return Just({
            "node_bindings": [{
                "qg_id": source_id,
                "kg_id": source_curie
            }, {
                "qg_id": target_id,
                "kg_id": node_id
            }],
            "edge_bindings": [{
                "qg_id":
                edge_id,
                "kg_id":
                gen_edge_id(source_curie, node_name, node_id)
            }],
            "score":
            score,
            "score_name":
            score_name
        })
Пример #3
0
def knowledge_graph_node(node_name, table, filter_regex, biolink_class):
    node_ids = name_to_ids(table, filter_regex, node_name)
    if len(node_ids) == 0:
        return Nothing
    else:
        node_id, equivalent_ids = gen_node_id_and_equivalent_ids(node_ids)

        return Just({
            "name": node_name,
            "id": node_id,
            "equivalent_identifiers": equivalent_ids,
            "type": [biolink_class]
        })
Пример #4
0
def get_cohort_definition_by_id(conn, cohort_id):
    s = select([
        cohort.c.cohort_id, cohort.c.features, cohort.c.size, cohort.c.table,
        cohort.c.year
    ]).where(cohort.c.cohort_id == cohort_id)
    for cohort_id, features, size, table, year in conn.execute((s)):
        return Just({
            "cohort_id": cohort_id,
            "size": size,
            "features": json.loads(features),
            "table": table,
            "year": year
        })
    return Nothing
Пример #5
0
def knowledge_graph_edge(source_id, node_name, table, filter_regex,
                         feature_property):
    node_ids = name_to_ids(table, filter_regex, node_name)
    if len(node_ids) == 0:
        return Nothing
    else:
        node_id, *equivalent_ids = gen_node_id_and_equivalent_ids(node_ids)

        edge_name = "correlated_with"

        return Just({
            "type": edge_name,
            "id": gen_edge_id(source_id, node_name, node_id),
            "source_id": source_id,
            "target_id": node_id,
            "edge_attributes": feature_property
        })
Пример #6
0
def get_cohort_definition_by_id(conn, cohort_id):
    s = select([
        column("cohort_id"),
        column("features"),
        column("size"),
        column("table"),
        column("year"),
    ]).select_from(table("cohort"))\
        .where(column("cohort_id") == cohort_id)
    for cohort_id, features, size, table, year in conn.execute((s)):
        return Just({
            "cohort_id": cohort_id,
            "size": size,
            "features": json.loads(features),
            "table": table,
            "year": year
        })
    return Nothing 
Пример #7
0
def test_bind_on_Just():
    assert Just(1).bind(lambda x: Just(x + 1)) == Just(2)
Пример #8
0
def test_rec():
    assert Nothing.rec(lambda x: x + 2, 3) == 3
    assert Just(2).rec(lambda x: x + 2, 3) == 4
Пример #9
0
def extract_key(a):
    return key(a).bind(lambda k: Just(
        reduce(lambda a, i: a[i], k, a) if isinstance(k, list) else a[k]))
Пример #10
0
def test_bind_on_Nothing():
    assert Nothing.bind(lambda x: Just(1)) == Nothing
Пример #11
0
def test_map_on_Just():
    assert Just(1).map(lambda x: 2) == Just(2)
Пример #12
0
def test_pure():
    assert maybe_monad.pure(1) == Just(1)
Пример #13
0
def test_sequenceA2(list_traversable_maybe_applicative):
    assert list_traversable_maybe_applicative.sequenceA([Just(1)]) == Just([1])
Пример #14
0
def test_bind_on_Just0():
    assert Just(1).bind(lambda x: x) == 1
Пример #15
0
def test_mapM2(list_traversable_maybe_monad):
    assert list_traversable_maybe_monad.mapM(
        lambda a: Just(1) if a else Nothing, [True]) == Just([1])
Пример #16
0
def test_sequence(list_traversable_maybe_monad):
    assert list_traversable_maybe_monad.sequence([Just(1), Nothing]) == Nothing
Пример #17
0
def test_maybe_from_python():
    assert maybe.from_python(None) == Nothing
    assert maybe.from_python(1) == Just(1)
Пример #18
0
def test_maybe_to_python():
    assert maybe.to_python(Nothing) == None
    assert maybe.to_python(Just(1)) == 1
Пример #19
0
def test_eq_on_Just():
    assert Just(1) == Just(1)
Пример #20
0
def test_sequence2(list_traversable_maybe_monad):
    assert list_traversable_maybe_monad.sequence([Just(1)]) == Just([1])
Пример #21
0
def test_iter_Nothing():
    assert [i for i in Just(True)] == [True]
Пример #22
0
def test_sequenceA(list_traversable_maybe_applicative):
    assert list_traversable_maybe_applicative.sequenceA([Just(1),
                                                         Nothing]) == Nothing
Пример #23
0
def test_ne_on_Just():
    assert Just(1) != Just(2)
    assert Just(1) != Nothing
Пример #24
0
def test_traverse2(list_traversable_maybe_applicative):
    assert list_traversable_maybe_applicative.traverse(
        lambda a: Just(1) if a else Nothing, [True]) == Just([1])
Пример #25
0
def test_ne_on_Nothing():
    assert Nothing != Just(1)