コード例 #1
0
def listify(possible_list):
    if isinstance(possible_list, list):
        new_list = [listify(each) for each in possible_list]
        return KQMLList(new_list)
    elif isinstance(possible_list, tuple):
        if len(possible_list) == 2:
            # assume dotted pair
            car = listify(possible_list[0])
            cdr = listify(possible_list[1])
            return KQMLList([car, KQMLToken('.'), cdr])
        else:
            # otherwise treat same as list
            new_list = [listify(each) for each in possible_list]
            return KQMLList(new_list)
    elif isinstance(possible_list, str):
        if ' ' in possible_list:
            if possible_list[0] == '(' and possible_list[-1] == ')':
                # WARNING: This is very incomplete!
                terms = possible_list[1:-1].split()
                return KQMLList([listify(t) for t in terms])
            else:
                return KQMLString(possible_list)
        else:
            return KQMLToken(possible_list)
    elif isinstance(possible_list, dict):
        return KQMLList([listify(pair) for pair in possible_list.items()])
    else:
        return KQMLToken(str(possible_list))
コード例 #2
0
def listify(possible_list):
    """Takes in an object and returns it in KQMLList form.

    Checks if the input is a list, and if so it recurses through all entities
    in the list to further listify them. If the input is not a list but is
    instead a tuple of length 2 we make the assumption that this is a dotted
    pair and construct the KQMLList as such, otherwise we treat this larger
    tuple the same as a list. If the input is a string, we first check that it
    has a space in it (to differentiate facts, strings, and tokens). We then
    check if it is in lisp form (i.e. '(...)') and if so we split every term
    between the parens by the spaces. Otherwise we return the object as a
    KQMLString. In either case, if the string had no spaces in it we return it
    as a KQMLToken. WARNING: This may be an incomplete breakdown of strings.
    Next we check if the input was a dictionary and if so we listify the key
    value pairs, and then make a KQMLList of that overall list of pairs.
    Lastly, if the input was nothing else we return the input as a string
    turned into a KQMLToken.

    Arguments:
        possible_list {any} -- any input that you want to transform to KQML
                               ready data types

    Returns:
        KQML* -- List, String, or Token
    """
    # pylint: disable=no-else-return
    # Another pylint bug...? Normally this error is for having return
    # statements inside an else but this is showing up for return statements in
    # elif. Not something to worry about.
    if isinstance(possible_list, list):
        new_list = [listify(each) for each in possible_list]
        return KQMLList(new_list)
    elif isinstance(possible_list, tuple):
        if len(possible_list) == 2:
            car = listify(possible_list[0])
            cdr = listify(possible_list[1])
            return KQMLList([car, KQMLToken('.'), cdr])
        new_list = [listify(each) for each in possible_list]
        return KQMLList(new_list)
    elif isinstance(possible_list, str):
        if ' ' in possible_list:
            # WARNING: This may be an incomplete breakdown of strings.
            if possible_list[0] == '(' and possible_list[-1] == ')':
                terms = possible_list[1:-1].split()
                return KQMLList([listify(t) for t in terms])
            return KQMLString(possible_list)
        return KQMLToken(possible_list)
    elif isinstance(possible_list, dict):
        return KQMLList([listify(pair) for pair in possible_list.items()])
    return KQMLToken(str(possible_list))
コード例 #3
0
ファイル: tra_test.py プロジェクト: dianakolusheva/bioagents
    def create_message(self):
        content = KQMLPerformative('SATISFIES-PATTERN')
        content.set('model', self.model)
        patt = KQMLList()
        patt.sets('type', 'eventual_value')
        ents = KQMLList()
        ent = KQMLList()
        ent.sets('description', agent_clj_from_text('phosphorylated MAPK1'))
        ents.append(ent)
        patt.set('entities', ents)
        val = KQMLList()
        val.sets('type', 'qualitative')
        val.sets('value', 'low')
        patt.set('value', val)
        content.set('pattern', patt)

        conds = KQMLList()
        cond = KQMLList()
        cond.sets('type', 'multiple')
        quant = KQMLList()
        quant.sets('type', 'total')
        ent = KQMLList()
        ent.sets('description', agent_clj_from_text('DUSP6'))
        quant.set('entity', ent)
        cond.sets('quantity', quant)
        #val = KQMLList()
        #val.sets('type', 'number')
        cond.set('value', KQMLToken('10'))
        #cond.set('value', val)
        conds.append(cond)
        content.set('conditions', conds)

        msg = get_request(content)
        return msg, content
コード例 #4
0
ファイル: msa_test.py プロジェクト: kolusask/bioagents
    def create_type_and_source(self):

        bap1 = Bioagent.make_cljson(Agent('BAP1', db_refs={'HGNC': '950'}))
        other_genes = ['CHD8', 'SCN2A', 'ARID1B']
        filter_agents = \
            Bioagent.make_cljson([Agent(n, db_refs=None)
                                  for n in other_genes])

        from kqml import KQMLToken
        for fa in filter_agents:
            fa.set('DB--REFS', KQMLToken('NIL'))

        print(filter_agents)

        return self._get_content('FIND-RELATIONS-FROM-LITERATURE',
                                 type='unknown',
                                 source=bap1,
                                 target=NONE,
                                 filter_agents=filter_agents)