def list_of_cems(self): """List of cems e.g. cem, cem, cem and cem""" return Group(self.single_cem + Optional(lbrct + R('^\d+$') + rbrct).hide() + ZeroOrMore(delim.hide() | self.single_cem | R('^\d+$')) + (I('and') | I('or') | I('to')).hide() + self.single_cem + Optional(lbrct + R('^\d+$') + rbrct).hide() + Optional(I('compounds') | I('samples')))('cem_list')
def prefix(self): """Specifier and prefix""" return (self.specifier_phrase + Optional(I('values')).hide() + Optional(delim).hide() + Optional((I('varies') + I('from')) | R('^increase(s|d)?') | I('falls') | I('reaches')).hide() + Optional(I('steeply')).hide() + Optional(I('recorded') | I('reported')).hide() + Optional(I('of') | I('was') | I('is') | I('at') | I('near') | I('above') | I('below') | I('with') | I('to') | I('were') | I('a')).hide() + Optional(I('reported') | I('determined') | I('estimated') | I('found') | I('occurs')).hide() + Optional(I('temperatures')).hide() + Optional(I('as') | (I('to') + I('be'))).hide() + Optional(I('in') + I('the') + I('range')).hide() + Optional(I('as') + I('high') + I('as')) + Optional(I('ranging') + I('from')).hide() + Optional(I('of')).hide() + Optional(I('rather') | I('quite')).hide() + Optional(I('high') | I('low') | I('maximum') | I('minimum')).hide() + Optional(I('the')).hide() + Optional(delim | lbrct | rbrct) + Optional( I('of') | I('about') | I('approximately') | I('typically') | I('ca.') | I('around') | I('at') | I( 'above') | I('below') | I('high') | I('low') | ((I('higher') | I('lower') | I('more') | I('less')) + I('than')) | I('order') | ( I('for') + I('instance')) | (I('up') + I('to')) | I('reaching') | I('value')).hide() + Optional(I('a') | I('an') | I('as')).hide() + Optional(I('maximum')).hide() + Optional(I('of')).hide() + ZeroOrMore(lbrct | delim | rbrct) + Optional(self.specifier_phrase) + Optional(I('of')).hide() + Optional(I('the')).hide() + Optional(I('order')).hide() + Optional((I('up') | I('equal')) + I('to')).hide() + Optional(I('of')).hide() + ZeroOrMore(lbrct | delim | rbrct) + Optional(W('=') | W('~') | W('≈') | W('≃') | W('>') | W('<')).hide() + ZeroOrMore(lbrct | delim | rbrct).hide()).add_action(join)
units = (W(u'%') | I(u'percent'))(u'units') value = R(u'\d+(\.\d+)?')(u'value') abbrv_prefix = (I(u'FF') | I(u'ff')).hide() words_pref = (I(u'fill') + I(u'factor')).hide() hyphanated_pref = (I(u'fill') + I(u'-') + I('factor')).hide() joined_range = R('^[\+\-–−]?\d+(\.\d+)?[\-–−~∼˜]\d+(\.\d+)?$')('value').add_action(merge) spaced_range = (R('^[\+\-–−]?\d+(\.\d+)?$') + Optional(units).hide() + (R('^[\-–−~∼˜]$') + R('^[\+\-–−]?\d+(\.\d+)?$') | R('^[\+\-–−]\d+(\.\d+)?$')))('value').add_action(merge) to_range = (R('^[\+\-–−]?\d+(\.\d+)?$') + Optional(units).hide() + (I('to') + R('^[\+\-–−]?\d+(\.\d+)?$') | R('^[\+\-–−]\d+(\.\d+)?$')))('value').add_action(join) prefix = Optional(I('a')).hide() + (Optional(lbrct) + W('FF') + Optional(rbrct) | I('fill') + Optional(I('factor')) ).hide() + Optional(lbrct + W('FF') + rbrct) + Optional(W('=') | I('of') | I('was') | I('is') | I('at')).hide() + Optional(I('in') + I('the') + I('range') + Optional(I('of')) | I('about') | ('around') | I('%')).hide() ff_first = (words_pref + (Optional(lbrct) + abbrv_prefix + Optional(rbrct)) + ZeroOrMore(common_text) + value + units)(u'ff') ff_second = (prefix + value + units)(u'ff') ff_pattern = ff_first | ff_second class FfParser(BaseParser): root = ff_pattern def interpret(self, result, start, end): compound = Compound( ff_pattern=[ Ff( value=first(result.xpath('./value/text()')), units=first(result.xpath('./units/text()')) ) ] )
units = StringType() Compound.pce_pattern = ListType(ModelType(Pce)) abbrv_prefix = (I(u'PCE') | I(u'PCEs') | I(u'pce')).hide() words_pref = (I(u'power') + I(u'conversion') + I(u'efficiency')).hide() hyphanated_pref = (I(u'power-conversion') + I(u'efficiency')).hide() prefix = abbrv_prefix | words_pref | hyphanated_pref common_text = R('(\w+)?\D(\D+)+(\w+)?').hide() units = (W(u'%') | I(u'percent'))(u'units') # value = R(u'^\d+(\.\d+)?$')(u'value') value = R(u'\d+(\.\d+)?')(u'value') pce_first = (prefix + ZeroOrMore(common_text) + value + units)(u'pce') pce_second = (value + units + prefix)(u'pce') pce_pattern = pce_first | pce_second class PceParser(BaseParser): root = pce_pattern def interpret(self, result, start, end): compound = Compound(pce_pattern=[ Pce(value=first(result.xpath('./value/text()')), units=first(result.xpath('./units/text()'))) ]) yield compound