本文整理汇总了Python中kqml.KQMLList.set方法的典型用法代码示例。如果您正苦于以下问题:Python KQMLList.set方法的具体用法?Python KQMLList.set怎么用?Python KQMLList.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kqml.KQMLList
的用法示例。
在下文中一共展示了KQMLList.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: receive_request
# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import set [as 别名]
def receive_request(self, msg, content):
"""Handle request messages and respond.
If a "request" message is received, decode the task and the content
and call the appropriate function to prepare the response. A
reply_content message is then sent back.
"""
try:
content = msg.get('content')
task_str = content.head().upper()
logger.info(task_str)
except Exception as e:
logger.error('Could not get task string from request.')
logger.error(e)
return self.error_reply(msg, 'Invalid task')
try:
if task_str == 'INDRA-TO-NL':
reply_content = self.respond_indra_to_nl(content)
else:
return self.error_reply(msg, 'Unknown task ' + task_str)
except Exception as e:
logger.error('Failed to perform task.')
logger.error(e)
reply_content = KQMLList('FAILURE')
reply_content.set('reason', 'NL_GENERATION_ERROR')
return self.reply_with_content(msg, reply_content)
示例2: create_message
# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import set [as 别名]
def create_message(self):
target = ekb_kstring_from_text(self.target)
drug = ekb_kstring_from_text(self.drug)
content = KQMLList('IS-DRUG-TARGET')
content.set('target', target)
content.set('drug', drug)
return get_request(content), content
示例3: send_display_figure
# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import set [as 别名]
def send_display_figure(self, path):
msg = KQMLPerformative('tell')
content = KQMLList('display-image')
content.set('type', 'simulation')
content.sets('path', path)
msg.set('content', content)
self.send(msg)
示例4: subscribe_tell
# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import set [as 别名]
def subscribe_tell(self, tell_type):
msg = KQMLPerformative('subscribe')
content = KQMLList('tell')
content.append('&key')
content.set('content', KQMLList.from_string('(%s . *)' % tell_type))
msg.set('content', content)
self.send(msg)
示例5: subscribe_request
# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import set [as 别名]
def subscribe_request(self, req_type):
msg = KQMLPerformative('subscribe')
content = KQMLList('request')
content.append('&key')
content.set('content', KQMLList.from_string('(%s . *)' % req_type))
msg.set('content', content)
self.send(msg)
示例6: respond_has_qca_path
# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import set [as 别名]
def respond_has_qca_path(self, content):
"""Response content to find-qca-path request."""
target_arg = content.gets('TARGET')
source_arg = content.gets('SOURCE')
reltype_arg = content.get('RELTYPE')
if not source_arg:
raise ValueError("Source list is empty")
if not target_arg:
raise ValueError("Target list is empty")
target = self._get_term_name(target_arg)
source = self._get_term_name(source_arg)
if reltype_arg is None or len(reltype_arg) == 0:
relation_types = None
else:
relation_types = [str(k.data) for k in reltype_arg.data]
has_path = self.qca.has_path([source], [target])
reply = KQMLList('SUCCESS')
reply.set('haspath', 'TRUE' if has_path else 'FALSE')
return reply
示例7: make_failure
# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import set [as 别名]
def make_failure(self, reason=None, description=None):
msg = KQMLList('FAILURE')
if reason:
msg.set('reason', reason)
if description:
msg.sets('description', description)
return msg
示例8: respond_indra_to_nl
# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import set [as 别名]
def respond_indra_to_nl(self, content):
"""Return response content to build-model request."""
stmts_json_str = content.gets('statements')
stmts = decode_indra_stmts(stmts_json_str)
txts = assemble_english(stmts)
txts_kqml = [KQMLString(txt) for txt in txts]
txts_list = KQMLList(txts_kqml)
reply = KQMLList('OK')
reply.set('NL', txts_list)
return reply
示例9: respond_find_target_drug
# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import set [as 别名]
def respond_find_target_drug(self, content):
"""Response content to find-target-drug request."""
try:
target_arg = content.gets('target')
target = self._get_agent(target_arg)
except Exception:
return self.make_failure('INVALID_TARGET')
drug_results = self.dtda.find_target_drugs(target)
drugs = self._get_drug_kqml(drug_results)
reply = KQMLList('SUCCESS')
reply.set('drugs', drugs)
return reply
示例10: send_display_model
# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import set [as 别名]
def send_display_model(self, diagrams):
for diagram_type, resource in diagrams.items():
if not resource:
continue
if diagram_type == 'sbgn':
content = KQMLList('display-sbgn')
content.set('type', diagram_type)
content.sets('graph', resource)
else:
content = KQMLList('display-image')
content.set('type', diagram_type)
content.sets('path', resource)
self.tell(content)
示例11: report_paths_graph
# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import set [as 别名]
def report_paths_graph(self, paths_list):
from indra.assemblers.graph import GraphAssembler
from indra.util import flatten
path_stmts = [stmts_from_json(l) for l in paths_list]
all_stmts = flatten(path_stmts)
ga = GraphAssembler(all_stmts)
ga.make_model()
resource = get_img_path('qca_paths.png')
ga.save_pdf(resource)
content = KQMLList('display-image')
content.set('type', 'simulation')
content.sets('path', resource)
self.tell(content)
示例12: respond_find_disease_targets
# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import set [as 别名]
def respond_find_disease_targets(self, content):
"""Response content to find-disease-targets request."""
try:
disease_arg = content.gets('disease')
disease = get_disease(ET.fromstring(disease_arg))
except Exception as e:
logger.error(e)
reply = self.make_failure('INVALID_DISEASE')
return reply
if not trips_isa(disease.disease_type, 'ont::cancer'):
reply = self.make_failure('DISEASE_NOT_FOUND')
return reply
logger.debug('Disease: %s' % disease.name)
try:
mut_protein, mut_percent, agents = \
self.dtda.get_top_mutation(disease.name)
except DiseaseNotFoundException:
reply = self.make_failure('DISEASE_NOT_FOUND')
return reply
# TODO: get functional effect from actual mutations
# TODO: add list of actual mutations to response (get from agents)
# TODO: get fraction not percentage from DTDA (edit get_top_mutation)
reply = KQMLList('SUCCESS')
protein = KQMLList()
protein.set('name', mut_protein)
protein.set('hgnc', mut_protein)
reply.set('protein', protein)
reply.set('prevalence', '%.2f' % (mut_percent/100.0))
reply.set('functional-effect', 'ACTIVE')
return reply
示例13: get_ambiguities_msg
# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import set [as 别名]
def get_ambiguities_msg(ambiguities):
sa = []
for term_id, ambiguity in ambiguities.items():
msg = KQMLList(term_id)
pr = ambiguity[0]['preferred']
pr_dbids = '|'.join([':'.join((k, v)) for
k, v in pr['refs'].items()])
term = KQMLList('term')
term.set('ont-type', pr['type'])
term.sets('ids', pr_dbids)
term.sets('name', pr['name'])
msg.set('preferred', term)
alt = ambiguity[0]['alternative']
alt_dbids = '|'.join([':'.join((k, v)) for
k, v in alt['refs'].items()])
term = KQMLList('term')
term.set('ont-type', alt['type'])
term.sets('ids', alt_dbids)
term.sets('name', alt['name'])
msg.set('alternative', term)
sa.append(msg)
ambiguities_msg = KQMLList(sa)
return ambiguities_msg
示例14: respond_choose_sense_category
# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import set [as 别名]
def respond_choose_sense_category(self, content):
"""Return response content to choose-sense-category request."""
ekb = content.gets('ekb-term')
category = content.gets('category')
try:
in_category = self.bs.choose_sense_category(ekb, category)
except InvalidAgentError:
msg = make_failure('INVALID_AGENT')
except UnknownCategoryError:
msg = make_failure('UNKNOWN_CATEGORY')
else:
msg = KQMLList('SUCCESS')
msg.set('in-category',
'TRUE' if in_category else 'FALSE')
return msg
示例15: respond_choose_sense_what_member
# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import set [as 别名]
def respond_choose_sense_what_member(self, content):
"""Return response content to choose-sense-what-member request."""
# Get the collection agent
ekb = content.gets('collection')
try:
members = self.bs.choose_sense_what_member(ekb)
except InvalidCollectionError:
msg = make_failure('INVALID_COLLECTION')
except CollectionNotFamilyOrComplexError:
msg = make_failure('COLLECTION_NOT_FAMILY_OR_COMPLEX')
else:
kagents = [get_kagent((m, 'ONT::PROTEIN', _get_urls(m)))
for m in members]
msg = KQMLList('SUCCESS')
msg.set('members', KQMLList(kagents))
return msg