def test_get_text_content_from_text_refs(): fulltext0 = ('We investigate properties of the estrogen receptor (ER).' ' Our investigation made no new findings about ER, leading to' ' damage in our groups abilty to secure funding.') fulltext1 = ('We describe an experiment about nanoparticles (NPs).' ' The experiment was a complete failure. Our inability to' ' produce sufficient quantities of NPs has made a troubling' ' impact on the future of our lab. The following figure' ' contains a schematic diagram of the apparatus of our' ' experiment.') db = _get_prepped_db() text = get_text_content_from_text_refs({'PMID': '000000'}, db=db) assert text == fulltext0 text = get_text_content_from_text_refs({'PMID': '777777'}, db=db) assert text == fulltext1
def _get_text_for_grounding(stmt, agent_text): """Get text context for Adeft disambiguation If the INDRA database is available, attempts to get the fulltext from which the statement was extracted. If the fulltext is not available, the abstract is returned. If the indra database is not available, uses the pubmed client to get the abstract. If no abstract can be found, falls back on returning the evidence text for the statement. Parameters ---------- stmt : py:class:`indra.statements.Statement` Statement with agent we seek to disambiguate. agent_text : str Agent text that needs to be disambiguated Returns ------- text : str Text for Adeft disambiguation """ text = None # First we will try to get content from the DB try: from indra_db.util.content_scripts \ import get_text_content_from_text_refs from indra.literature.adeft_tools import universal_extract_text refs = stmt.evidence[0].text_refs # Prioritize the pmid attribute if given if stmt.evidence[0].pmid: refs['PMID'] = stmt.evidence[0].pmid logger.debug('Obtaining text for disambiguation with refs: %s' % refs) content = get_text_content_from_text_refs(refs) if not content: raise ValueError('Text obtained from DB is empty') text = universal_extract_text(content, contains=agent_text) if text: return text except Exception as e: logger.info('Could not get text for disambiguation from DB: %s' % e) # If that doesn't work, we try PubMed next if text is None: from indra.literature import pubmed_client pmid = stmt.evidence[0].pmid if pmid: logger.debug('Obtaining abstract for disambiguation for PMID%s' % pmid) text = pubmed_client.get_abstract(pmid) if text: return text # Finally, falling back on the evidence sentence if text is None: logger.info('Falling back on sentence-based disambiguation') text = stmt.evidence[0].text return text return None
def _get_text_for_grounding(stmt, agent_text): """Get text context for Adeft disambiguation If the INDRA database is available, attempts to get the fulltext from which the statement was extracted. If the fulltext is not available, the abstract is returned. If the indra database is not available, uses the pubmed client to get the abstract. If no abstract can be found, falls back on returning the evidence text for the statement. Parameters ---------- stmt : py:class:`indra.statements.Statement` Statement with agent we seek to disambiguate. agent_text : str Agent text that needs to be disambiguated Returns ------- text : str Text for Adeft disambiguation """ text = None # First we will try to get content from the DB try: from indra_db.util.content_scripts \ import get_text_content_from_text_refs from indra.literature.adeft_tools import universal_extract_text refs = stmt.evidence[0].text_refs # Prioritize the pmid attribute if given if stmt.evidence[0].pmid: refs['PMID'] = stmt.evidence[0].pmid logger.info('Obtaining text for disambiguation with refs: %s' % refs) content = get_text_content_from_text_refs(refs) text = universal_extract_text(content, contains=agent_text) if text: return text except Exception as e: logger.info('Could not get text for disambiguation from DB.') # If that doesn't work, we try PubMed next if text is None: from indra.literature import pubmed_client pmid = stmt.evidence[0].pmid if pmid: logger.info('Obtaining abstract for disambiguation for PMID%s' % pmid) text = pubmed_client.get_abstract(pmid) if text: return text # Finally, falling back on the evidence sentence if text is None: logger.info('Falling back on sentence-based disambiguation') text = stmt.evidence[0].text return text return None
def get_text_content(pmid): content = get_text_content_from_text_refs(text_refs={'PMID': pmid}, db=db) if content: text = universal_extract_text(content) return text return None