def interpret(self, result, start, end): context = {} # print("footnote temp") # print(etree.tostring(result)) # print() c = Compound() context = {} tempvalue = first(result.xpath('//value/text()')) tempunit = first(result.xpath('//units/text()')) if tempunit and '℃' in tempunit: tempunit = '°C' if not tempvalue and not tempunit: tempvalue = first(result.xpath('//tempphrase/text()')) # print(tempvalue) if not tempunit: if "K" in tempvalue: tempunit = 'K' tempvalue = tempvalue.strip('K') elif '°C' in tempvalue: tempunit = '°C' tempvalue = tempvalue.strip("°C") else: tempvalue = None context["tempvalue"] = tempvalue context["tempunits"] = tempunit if context: c.conv.append(Conv(**context)) yield c
def interpret_multi_entity_3c(self, result, start, end): """interpret multiple compounds, single specifier, multiple transitions""" if result is None: return specifier = first( result.xpath('//multi_entity_phrase_3c/specifier/text()')) if specifier is None: yield None values = [ first( result.xpath( '//multi_entity_phrase_3c/value1/raw_value/text()')), first( result.xpath( '//multi_entity_phrase_3c/value2/raw_value/text()')) ] compounds = [ first( result.xpath( '//multi_entity_phrase_3c/cem1/compound/names/text()')), first( result.xpath( '//multi_entity_phrase_3c/cem2/compound/names/text()')) ] if values is None: yield None if compounds is None: yield None requirements = True last_unit = None for i in range(2): raw_value = values[i] raw_units = None c = self.model.compound.model_class(names=[compounds[i]]) value = self.extract_value(raw_value) error = self.extract_error(raw_value) units = None try: units = self.extract_units(raw_units, strict=True) except TypeError as e: #requirements = False log.debug(e) #print (specifier,raw_value,raw_units,error,value,units,c) property_entities = { 'specifier': specifier, 'raw_value': raw_value, 'raw_units': raw_units, 'error': error, 'value': value, 'units': units, 'compound': c } model_instance = self.model(**property_entities) if requirements: yield model_instance
def interpret(self, result, start, end): compound = Compound( melting_points=[ MeltingPoint( value=first(result.xpath('./value/text()')), units=first(result.xpath('./units/text()')) ) ] ) yield compound
def interpret(self, result, start, end): compound = Compound( ff_pattern=[ Ff( value=first(result.xpath('./value/text()')), units=first(result.xpath('./units/text()')) ) ] ) yield compound
def interpret(self, result, start, end): pressure = first(result.xpath('//value/text()')) presunit = first(result.xpath('//units/text()')) if not pressure: pressure = first(result.xpath('//phrase/text()')) # print("inside cell of pres") # print(pressure) # print(presunit) c = Compound(conv=[Conv(pressure=pressure, pressureunit=presunit)]) yield c
def interpret(self, result, start, end): # print("inside cell") # print(etree.tostring(result)) # print() tofvalue = first(result.xpath('./tofvalue/text()')) tempvalue = first(result.xpath('./tempvalue/text()')) tempunits = first(result.xpath('./tempunits/text()')) c = Compound(conv=[ Conv(tofvalue=tofvalue, tempvalue=tempvalue, tempunits=tempunits) ]) yield c
def interpret(self, result, start, end): # print("inside flow cell") # print(etree.tostring(result)) # print() c = Compound(flow=[ Flow( value=first(result.xpath('./value/text()')), unit=first(result.xpath('./units/text()')), ) ]) yield c
def interpret_multi_entity_1(self, result, start, end): """Interpret phrases that have a single CEM and multiple values with multiple specifiers """ if result is None: return cem_el = first(result.xpath('./compound')) if cem_el is None: yield None property_list = first(result.xpath('./property_list')) if property_list is None: yield None c = self.model.compound.model_class() # add names and labels c.names = cem_el.xpath('./names/text()') c.labels = cem_el.xpath('./labels/text()') properties = property_list.xpath('./property') last_unit = None for pt in properties[::-1]: # Reverse order to make sure we get a unit requirements = True specifier = first(pt.xpath('./specifier/text()')) raw_value = first(pt.xpath('./raw_value/text()')) raw_units = first(pt.xpath('./raw_units/text()')) if not raw_units: raw_units = last_unit else: last_unit = raw_units value = self.extract_value(raw_value) error = self.extract_error(raw_value) units = None try: units = self.extract_units(raw_units, strict=True) except TypeError as e: requirements = False log.debug(e) property_entities = { 'specifier': specifier, 'raw_value': raw_value, 'raw_units': raw_units, 'error': error, 'value': value, 'units': units, 'compound': c} model_instance = self.model(**property_entities) if requirements: yield model_instance
def interpret(self, result, start, end): for cem_el, mc in zip(result.xpath('/cem'), result.xpath('./mc')): compound = Compound(measured_concentrations=[ MeasuredConcentration( value=first(mc.xpath('./value/text()')), units=first(mc.xpath('./units/text()')), location=first(result.xpath('./medium/text()')), normal_concentration=first( result.xpath('./normal_range/value/text()'))) ]) if cem_el is not None: compound.names = cem_el.xpath('./name/text()') compound.labels = cem_el.xpath('./label/text()') yield compound
def interpret(self, result, start, end): """""" compunits = [""] # print("inside comp header") # print(etree.tostring(result)) # print() if len(result) == 1: compunits = first(result.xpath('//unit/text()')) elif len(result) > 1: for item in result: compunit = first(item.xpath('//unit/text()')) if compunit: compunits[0] += compunit if compunits[0] == "": compunits = [] # print(flowunits) else: compunits = [] # print("comp header") if "/CO" in first( result.xpath('//compphrase/text()')) or ":CO" in first( result.xpath('//compphrase/text()')): compunits = first(result.xpath('//compphrase/text()')) if "CO/H2" in first( result.xpath('//compphrase/text()')) or "CO:H2" in first( result.xpath('//compphrase/text()')): compunits = first(result.xpath('//compphrase/text()')) # print(compunits) # print(compunits) c = Compound() if compunits: c.comp.append(Comp(unit=compunits)) yield c
def interpret_multi_entity_4(self, result, start, end): """interpret multiple compounds, single specifier, single transition""" if result is None: return requirements = True cem_list = first(result.xpath('./cem_list')) if cem_list is None: yield None raw_units = None specifier = first(result.xpath('./property/specifier/text()')) raw_value = first(result.xpath('./property/raw_value/text()')) raw_units = first(result.xpath('./property/raw_units/text()')) if specifier is None: yield None value = self.extract_value(raw_value) error = self.extract_error(raw_value) units = None try: units = self.extract_units(raw_units, strict=True) except TypeError as e: requirements = False log.debug(e) for cem in cem_list: # Reverse order to make sure we get a unit c = None try: c = self.model.compound.model_class( names=cem.xpath('./names/text()', labels=cem.xpath('./labels/text()'))) except Exception: requirements = False property_entities = { 'specifier': specifier, 'raw_value': raw_value, 'raw_units': raw_units, 'error': error, 'value': value, 'units': units, 'compound': c} model_instance = self.model(**property_entities) if requirements: yield model_instance
def interpret(self, result, start, end): # print("inside cat cell") # print(etree.tostring(result)) # print() # print("test") c = Compound(catalyst_name=[CAT(name=first(result.xpath('text()')), )]) yield c
def interpret(self, result, start, end): # for item in result: # print("inside cell") # print(etree.tostring(item)) # print() convvalue = first(result.xpath('//convvalue/text()')) convunits = first(result.xpath('//convunits/text()')) tempvalue = first(result.xpath('//tempvalue/text()')) tempunits = first(result.xpath('//tempunits/text()')) c = Compound(conv=[ Conv(convvalue=convvalue, convunits=convunits, tempvalue=tempvalue, tempunits=tempunits) ]) yield c
def interpret(self, result, start, end): # print("inside heading of tof") # print(etree.tostring(result)) context = {} no = first(result.xpath('./no/text()')) context['tempunits'] = first(result.xpath('./tempunits/text()')) context['tempvalue'] = first(result.xpath('./tempvalue/text()')) if no == None: context['convunits'] = first(result.xpath('./convunits/text()')) else: context['convunits'] = first(result.xpath('./no/text()')) c = Compound() if tempunits: c.conv.append(Conv(**context)) yield c
def interpret(self, result, start, end): """""" # print("inside flow header") # print(etree.tostring(result)) # print() if type(result) == type([]): for i in result: flowunits = first(i.xpath('//unit/text()')) if flowunits != None: break else: flowunits = first(result.xpath('//unit/text()')) c = Compound() if flowunits: c.flow.append(Flow(unit=flowunits)) yield c
def interpret(self, result, start, end): c = Compound() s = Anneal() tempunits = first(result.xpath('./tempunits/text()')) timeunits = first(result.xpath('./timeunits/text()')) for temp in result.xpath('./temps/temp'): anneal_temp = AnnealTemp(tempvalue=first( temp.xpath('./tempvalue/text()')), tempunits=tempunits) s.temps.append(anneal_temp) for time in result.xpath('./times/time'): anneal_time = AnnealTime(timevalue=first( time.xpath('./timevalue/text()')), timeunits=timeunits) s.times.append(anneal_time) c.anneal.append(s) yield c
def interpret(self, result, start, end): c = Compound() s = SpinCoat( # solvent=first(result.xpath('./solvent/text()')) ) spdunits = first(result.xpath('./spdunits/text()')) timeunits = first(result.xpath('./timeunits/text()')) for spd in result.xpath('./spds/spd'): spin_spd = SpinSpd(spdvalue=first(spd.xpath('./spdvalue/text()')), spdunits=spdunits) s.spds.append(spin_spd) for time in result.xpath('./times/time'): spin_time = SpinTime(timevalue=first( time.xpath('./timevalue/text()')), timeunits=timeunits) s.times.append(spin_time) c.spin_coat.append(s) yield c
def interpret(self, result, start, end): # """""" # print("inside bet header") # print(etree.tostring(result)) # print() units = first(result.xpath('//units/text()')) # print(units) c = Compound(bet=[BET(unit=units)]) yield c
def interpret(self, result, start, end): context = {} # print("foot pressure") # print(etree.tostring(result)) # print() c = Compound() context = {} presvalue = first(result.xpath('//value/text()')) presunit = first(result.xpath('//units/text()')) # print(presvalue) # print(presunit) context["pressure"] = presvalue context["presunits"] = presunit if context: c.conv.append(Conv(**context)) yield c
def interpret(self, result, start, end): """""" # print("inside heading of pres") # print(etree.tostring(result)) presunits = first(result.xpath('//units/text()')) c = Compound() if presunits: c.conv.append(Conv(presunits=presunits)) yield c
def interpret(self, result, start, end): context = {} # print("footnote") # print(etree.tostring(result)) # print() c = Compound() catname = first(result.xpath('./cat_phrase/name/text()')) # print(catname) context["captioncatname"] = catname if context: c.conv.append(Conv(**context)) yield c
def interpret(self, result, start, end): """""" # print("inside temp") # print(etree.tostring(result)) # print() # print(lollol) tempunits = first(result.xpath('./units/text()')) c = Compound() if tempunits: c.temp.append(Temp(unit=tempunits)) yield c
def interpret(self, result, start, end): """""" context = {} c = Compound() no = first(result.xpath('./no/text()')) tempunits = first(result.xpath('./tempunits/text()')) context['tempunits'] = tempunits tempvalues = first(result.xpath('./tempvalue/text()')) context['tempvalue'] = tempvalues any = first(result.xpath('//any/text()')) context["convtype"] = any # print("inside conv heading") # print(etree.tostring(result)) check = result.xpath('/tempnumber') # print("check: ", check) # print() if check: # print("yes") c.conv.append(Conv(**{'check': "True"})) if no == None: context['convunits'] = first(result.xpath('./convunits/text()')) else: context['convunits'] = first(result.xpath('./no/text()')) if tempunits or any: c.conv.append(Conv(**context)) yield c
def interpret(self, result, start, end): # print("inside betcell") # print(etree.tostring(result)) # print() value = result.xpath('//betvalue/text()') if len(value) < 1: value = result.xpath("//betcell/text()") units = first(result.xpath('//units/text()')) # # print(value) # print(units) c = Compound(bet=[BET(value=value, unit=units)]) yield c
def interpret(self, result, start, end): """""" # print("inside heading selectivity") # print(etree.tostring(result)) # print() selectivityunits = first(result.xpath('//units/text()')) # print(selectivityunits) # print() c = Compound() if selectivityunits: sel = Selectivity(unit=selectivityunits) c.conv.append(Conv(selectivity=[sel])) # print(c.serialize()) yield c
def interpret_multi_entity_3(self, result, start, end): """interpret multiple compounds, single specifier, multiple transitions""" if result is None: return cem_list = first(result.xpath('./cem_list')) if cem_list is None: yield None specifier = first(result.xpath('./specifier/text()')) if specifier is None: yield None value_list = first(result.xpath('./value_list')) if value_list is None: yield None raw_values_list = value_list.xpath('./raw_value') raw_units_list = value_list.xpath('./raw_units') last_unit = None for i, v in enumerate(raw_values_list[::-1]): # Reverse order to make sure we get a unit raw_value = first(v.xpath('./text()')) requirements = True raw_units = None try: raw_units = first(raw_units_list[::-1][i].xpath('./text()')) last_unit = raw_units except IndexError: if last_unit: raw_units = last_unit else: requirements = False c = None try: compound = cem_list[::-1][i] c = self.model.compound.model_class( names=compound.xpath('./names/text()', labels=compound.xpath('./labels/text()'))) except Exception: requirements = False value = self.extract_value(raw_value) error = self.extract_error(raw_value) units = None try: units = self.extract_units(raw_units, strict=True) except TypeError as e: requirements = False log.debug(e) property_entities = { 'specifier': specifier, 'raw_value': raw_value, 'raw_units': raw_units, 'error': error, 'value': value, 'units': units, 'compound': c} model_instance = self.model(**property_entities) if requirements: yield model_instance
def interpret_multi_entity_2(self, result, start, end): """single compound, single specifier, multiple transitions e.g. BiFeO3 shows magnetic transitions at 1093 and 640 K """ if result is None: return cem_el = first(result.xpath('./compound')) if cem_el is None: yield None specifier = first(result.xpath('./specifier/text()')) if specifier is None: yield None value_list = first(result.xpath('./value_list')) if value_list is None: yield None c = self.model.compound.model_class() # add names and labels c.names = cem_el.xpath('./names/text()') c.labels = cem_el.xpath('./labels/text()') raw_values_list = value_list.xpath('./raw_value') raw_units_list = value_list.xpath('./raw_units') last_unit = None for i, v in enumerate(raw_values_list[::-1] ): # Reverse order to make sure we get a unit raw_value = first(v.xpath('./text()')) requirements = True raw_units = None try: raw_units = first(raw_units_list[::-1][i].xpath('./text()')) last_unit = raw_units except IndexError: if last_unit: raw_units = last_unit #else: #requirements = False value = self.extract_value(raw_value) error = self.extract_error(raw_value) units = None try: units = self.extract_units(raw_units, strict=True) except Exception as e: #requirements = False log.debug(e) pass property_entities = { 'specifier': specifier, 'raw_value': raw_value, 'raw_units': raw_units, 'error': error, 'value': value, 'units': units, 'compound': c } model_instance = self.model(**property_entities) if requirements: yield model_instance
def interpret(self, result, start, end): compound = Compound(solubility=[ Solubility(value=first(result.xpath('./value/text()')), units=first(result.xpath('./units/text()'))) ]) yield compound
def interpret(self, result, start, end): value = first(result.xpath('//value/text()')) c = Compound(temp=[Temp(value=value)]) yield c
def interpret(self, result, start, end): raw_value = first(result.xpath('//frequencyvalue/text()')) #print (type(raw_value)) frequency = self.model(frequency=raw_value) #print (frequency) yield frequency