本文整理汇总了Python中indra.preassembler.Preassembler.add_statements方法的典型用法代码示例。如果您正苦于以下问题:Python Preassembler.add_statements方法的具体用法?Python Preassembler.add_statements怎么用?Python Preassembler.add_statements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类indra.preassembler.Preassembler
的用法示例。
在下文中一共展示了Preassembler.add_statements方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_assembly
# 需要导入模块: from indra.preassembler import Preassembler [as 别名]
# 或者: from indra.preassembler.Preassembler import add_statements [as 别名]
def run_assembly(stmts, folder, pmcid, background_assertions=None):
'''Run assembly on a list of statements, for a given PMCID.'''
# Folder for index card output (scored submission)
indexcard_prefix = folder + '/index_cards/' + pmcid
# Folder for other outputs (for analysis, debugging)
otherout_prefix = folder + '/other_outputs/' + pmcid
# Do grounding mapping here
# Load the TRIPS-specific grounding map and add to the default
# (REACH-oriented) grounding map:
trips_gm = load_grounding_map('trips_grounding_map.csv')
default_grounding_map.update(trips_gm)
gm = GroundingMapper(default_grounding_map)
mapped_agent_stmts = gm.map_agents(stmts)
renamed_agent_stmts = gm.rename_agents(mapped_agent_stmts)
# Filter for grounding
grounded_stmts = []
for st in renamed_agent_stmts:
if all([is_protein_or_chemical(a) for a in st.agent_list()]):
grounded_stmts.append(st)
# Instantiate the Preassembler
pa = Preassembler(hierarchies)
pa.add_statements(grounded_stmts)
print('== %s ====================' % pmcid)
print('%d statements collected in total.' % len(pa.stmts))
# Combine duplicates
unique_stmts = pa.combine_duplicates()
print('%d statements after combining duplicates.' % len(unique_stmts))
# Run BeliefEngine on unique statements
epe = BeliefEngine()
epe.set_prior_probs(pa.unique_stmts)
# Build statement hierarchy
related_stmts = pa.combine_related()
# Run BeliefEngine on hierarchy
epe.set_hierarchy_probs(related_stmts)
print('%d statements after combining related.' % len(related_stmts))
# Instantiate the mechanism linker
# Link statements
linked_stmts = MechLinker.infer_active_forms(related_stmts)
linked_stmts += MechLinker.infer_modifications(related_stmts)
linked_stmts += MechLinker.infer_activations(related_stmts)
# Run BeliefEngine on linked statements
epe.set_linked_probs(linked_stmts)
# Print linked statements for debugging purposes
print('Linked\n=====')
for ls in linked_stmts:
print(ls.inferred_stmt.belief, ls.inferred_stmt)
print('=============')
# Combine all statements including linked ones
all_statements = related_stmts + [ls.inferred_stmt for ls in linked_stmts]
# Instantiate a new preassembler
pa = Preassembler(hierarchies, all_statements)
# Build hierarchy again
pa.combine_duplicates()
# Choose the top-level statements
related_stmts = pa.combine_related()
# Remove top-level statements that came only from the prior
if background_assertions is not None:
nonbg_stmts = [stmt for stmt in related_stmts
if stmt not in background_assertions]
else:
nonbg_stmts = related_stmts
# Dump top-level statements in a pickle
with open(otherout_prefix + '.pkl', 'wb') as fh:
pickle.dump(nonbg_stmts, fh)
# Flatten evidence for statements
flattened_evidence_stmts = flatten_evidence(nonbg_stmts)
# Start a card counter
card_counter = 1
# We don't limit the number of cards reported in this round
card_lim = float('inf')
top_stmts = []
###############################################
# The belief cutoff for statements
belief_cutoff = 0.3
###############################################
# Sort by amount of evidence
for st in sorted(flattened_evidence_stmts,
key=lambda x: x.belief, reverse=True):
if st.belief >= belief_cutoff:
print(st.belief, st)
if st.belief < belief_cutoff:
print('SKIP', st.belief, st)
# If it's background knowledge, we skip the statement
if is_background_knowledge(st):
print('This statement is background knowledge - skipping.')
#.........这里部分代码省略.........