本文整理汇总了Python中kqml.KQMLList类的典型用法代码示例。如果您正苦于以下问题:Python KQMLList类的具体用法?Python KQMLList怎么用?Python KQMLList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KQMLList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: respond_find_disease_targets
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
示例2: send_display_figure
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)
示例3: receive_request
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)
示例4: create_message
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
示例5: respond_has_qca_path
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
示例6: response_error
def response_error(self, error):
reply_content = KQMLList()
for e in error:
error_msg = '"%s"' %\
str(e).encode('string-escape').replace('"', '\\"')
reply_content.add(error_msg)
return self.format_error(reply_content.to_string())
示例7: make_failure
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: test_respond_choose_nonsense
def test_respond_choose_nonsense():
bs = BioSense_Module(testing=True)
msg_content = KQMLList('CHOOSE-SENSE')
msg_content.sets('ekb-term', ekb_from_text('bagel'))
res = bs.respond_choose_sense(msg_content)
print(res)
assert res.head() == 'SUCCESS'
assert res.get('agents')[0].gets('ont-type') is None
示例9: send_null_provenance
def send_null_provenance(self, stmt, for_what, reason=''):
"""Send out that no provenance could be found for a given Statement."""
content_fmt = ('<h4>No supporting evidence found for {statement} from '
'{cause}{reason}.</h4>')
content = KQMLList('add-provenance')
stmt_txt = EnglishAssembler([stmt]).make_model()
content.sets('html', content_fmt.format(statement=stmt_txt,
cause=for_what, reason=reason))
return self.tell(content)
示例10: _get_perf
def _get_perf(text, msg_id):
"""Return a request message for a given text."""
msg = KQMLPerformative('REQUEST')
msg.set('receiver', 'READER')
content = KQMLList('run-text')
content.sets('text', text)
msg.set('content', content)
msg.set('reply-with', msg_id)
return msg
示例11: respond_indra_to_nl
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
示例12: reply
def reply(self,):
reply_msg = KQMLPerformative('reply')
reply_content = KQMLList()
for t in self.tests:
print 'reply {0}'.format(t)
t_content = t.get_content()
if t_content:
reply_content.add(t_content.to_string())
reply_msg.setParameter(':content', reply_content)
return reply_msg
示例13: respond_test
def respond_test(self):
'''
Response content to version message
'''
reply_content = KQMLList()
version_response = KQMLList.from_string( '' +\
'(ONT::TELL :content ' +\
')')
reply_content.add(KQMLList(version_response))
return reply_content
示例14: test_respond_get_synonyms
def test_respond_get_synonyms():
bs = BioSense_Module(testing=True)
msg_content = KQMLList('GET-SYNONYMS')
msg_content.sets('entity', mek1_ekb)
res = bs.respond_get_synonyms(msg_content)
assert res.head() == 'SUCCESS'
syns = res.get('synonyms')
syn_strs = [s.gets(':name') for s in syns]
assert 'MAP2K1' in syn_strs
assert 'MEK1' in syn_strs
assert 'MKK1' in syn_strs
示例15: test_respond_choose_sense_is_member
def test_respond_choose_sense_is_member():
bs = BioSense_Module(testing=True)
msg_content = KQMLList('CHOOSE-SENSE-IS-MEMBER')
msg_content.sets('ekb-term', mek1_ekb)
msg_content.sets('collection', mek_ekb)
print(msg_content)
res = bs.respond_choose_sense_is_member(msg_content)
print(res)
print(res.head())
assert(res.head() == 'SUCCESS')
assert(res.get('is-member') == 'TRUE')