コード例 #1
0
def test_mutable():
    """
    Test mutability of ontology class
    """
    ont = Ontology()
    ont.add_node('TEST:1', 'foo bar')
    ont.add_node('TEST:2', 'bar foo')
    ont.add_node('TEST:3', 'foo bar')
    ont.add_node('TEST:4', 'wiz')
    syn = Synonym('TEST:4', val='bar foo', pred='hasExactSynonym')
    ont.add_synonym(syn)
    w = GraphRenderer.create('obo')
    w.write(ont)
    for n in ont.nodes():
        meta = ont._meta(n)
        print('{} -> {}'.format(n, meta))

    assert ont.label('TEST:1') == 'foo bar'
    assert ont.synonyms('TEST:1') == []
    assert ont.synonyms('TEST:4')[0].val == 'bar foo'
コード例 #2
0
def _get_single_sentence(node_ids: List[str],
                         ontology: Ontology,
                         aspect: str,
                         evidence_group: str,
                         qualifier: str,
                         prepostfix_sentences_map: Dict[Tuple[str, str, str],
                                                        Tuple[str, str]],
                         terms_merged: bool = False,
                         add_others: bool = False,
                         truncate_others_generic_word: str = "several",
                         truncate_others_aspect_words: Dict[str, str] = None,
                         ancestors_with_multiple_children: Set[str] = None,
                         rename_cell: bool = False,
                         trimmed: bool = False) -> Union[Sentence, None]:
    """build a sentence object

    Args:
        node_ids (List[str]): list of ids for the terms to be combined in the sentence
        ontology (Ontology): the ontology containing the nodes
        aspect (str): aspect
        evidence_group (str): evidence group
        qualifier (str): qualifier
        prepostfix_sentences_map (Dict[Tuple[str, str, str], Tuple[str, str]]): map for prefix and postfix phrases
        terms_merged (bool): whether the terms set has been merged to reduce its size
        add_others (bool): whether to say that there are other terms which have been omitted from the sentence
        truncate_others_generic_word (str): a generic word to indicate that the set of terms reported in the sentence is
            only a subset of the original terms, e.g., 'several'
        truncate_others_aspect_words (Dict[str, str]): one word for each aspect describing the kind of terms that are
            included in the aspect
        ancestors_with_multiple_children (Set[str]): set containing labels of terms that cover more than one children
            term in the original set and which will appear with the label '(multiple)'
        rename_cell (bool): whether to rename the term 'cell'
    Returns:
        Union[Sentence,None]: the combined go sentence
    """
    if len(node_ids) > 0:
        prefix = prepostfix_sentences_map[(aspect, evidence_group,
                                           qualifier)][0]
        additional_prefix = ""
        others_word = "entities"
        if aspect in truncate_others_aspect_words:
            others_word = truncate_others_aspect_words[aspect]
        if add_others:
            additional_prefix += " " + truncate_others_generic_word + " " + others_word + ", including"
        if aspect == "C":
            additional_prefix += " the"
        postfix = prepostfix_sentences_map[(aspect, evidence_group,
                                            qualifier)][1]
        term_labels = [
            ontology.label(node_id, id_if_null=True) for node_id in node_ids
        ]
        return Sentence(
            prefix=prefix,
            terms_ids=node_ids,
            postfix=postfix,
            text=compose_sentence(prefix=prefix,
                                  term_names=term_labels,
                                  postfix=postfix,
                                  additional_prefix=additional_prefix,
                                  ancestors_with_multiple_children=
                                  ancestors_with_multiple_children,
                                  rename_cell=rename_cell),
            aspect=aspect,
            evidence_group=evidence_group,
            terms_merged=terms_merged,
            additional_prefix=additional_prefix,
            qualifier=qualifier,
            ancestors_covering_multiple_terms=ancestors_with_multiple_children,
            trimmed=trimmed)
    else:
        return None