def test_build_model_from_ekb(): m = MRA() html = trips_client.send_query('MAP2K1 phosphorylates ERK2.') ekb_xml = trips_client.get_xml(html) res = m.build_model_from_ekb(ekb_xml) assert (res.get('model')) assert (res.get('model_id') == 1) assert (res.get('model_exec')) assert (len(m.models[1]) == 1) assert (isinstance(m.models[1][0], Phosphorylation)) assert (m.models[1][0].enz.name == 'MAP2K1') assert (m.models[1][0].sub.name == 'MAPK1')
def get_example_extractions(fname): "Get extractions from one of the examples in `cag_examples`." with open(fname, 'r') as f: sentences = f.read().splitlines() rdf_xml_dict = {} for sentence in sentences: logger.info("Reading \"%s\"..." % sentence) html = tc.send_query(sentence, 'cwms') try: rdf_xml_dict[sentence] = tc.get_xml(html, 'rdf:RDF', fail_if_empty=True) except AssertionError as e: logger.error("Got error for %s." % sentence) logger.exception(e) return rdf_xml_dict
def process_text(text, save_xml_name='trips_output.xml', save_xml_pretty=True, offline=False, service_endpoint='drum'): """Return a TripsProcessor by processing text. Parameters ---------- text : str The text to be processed. save_xml_name : Optional[str] The name of the file to save the returned TRIPS extraction knowledge base XML. Default: trips_output.xml save_xml_pretty : Optional[bool] If True, the saved XML is pretty-printed. Some third-party tools require non-pretty-printed XMLs which can be obtained by setting this to False. Default: True oflline : Optional[bool] If True, offline reading is used with a local instance of DRUM, if availble. Default: False service_endpoint : Optional[str] Selects the TRIPS/DRUM web service endpoint to use. Is a choice between "drum" (default) and "drum-dev", a nightly build. Returns ------- tp : TripsProcessor A TripsProcessor containing the extracted INDRA Statements in tp.statements. """ if not offline: html = trips_client.send_query(text, service_endpoint) xml = trips_client.get_xml(html) else: if offline_reading: try: dr = DrumReader() if dr is None: raise Exception('DrumReader could not be instantiated.') except BaseException as e: logger.error(e) logger.error('Make sure drum/bin/trips-drum is running in' ' a separate process') return None try: dr.read_text(text) dr.start() except SystemExit: pass xml = dr.extractions[0] else: logger.error('Offline reading with TRIPS/DRUM not available.') logger.error('Error message was: %s' % offline_err) msg = """ To install DRUM locally, follow instructions at https://github.com/wdebeaum/drum. Next, install the pykqml package either from pip or from https://github.com/bgyori/pykqml. Once installed, run drum/bin/trips-drum in a separate process. """ logger.error(msg) return None if save_xml_name: trips_client.save_xml(xml, save_xml_name, save_xml_pretty) return process_xml(xml)