Exemplo n.º 1
0
    def retrieve(self, is_match_pattern, target_sequence, data_spread_length):
        empty_iter = iter([]), 0
        if not target_sequence:
            logging.warning("[parser] no target sequence specified")
            return empty_iter
        analyzer = self._get_analyzer()
        if not analyzer:
            return empty_iter

        from htm_parse.parse_engine import HTMSpec, PosSpec
        start_pattern = target_sequence[0]
        subsequent_patterns = target_sequence[1:]
        pos_spec = PosSpec(IsValidSegment([start_pattern]), data_spread_length)
        for pattern in subsequent_patterns:
            pos_spec.add_spec(pattern, IsValidSegment([pattern]))
        if not analyzer.read_pos(pos_spec):
            logging.debug("[parser] cannot find matched sequence")
            return empty_iter

        logging.debug("[parser] find sequence no: " + "%i " * (len(subsequent_patterns)) %
                      tuple(analyzer.get_values(subsequent_patterns)))
        value_spec = [[start_pattern, 0, str]]  # start_pattern has position '0;
        for pattern in subsequent_patterns:
            value_spec.append([pattern, analyzer.get_value(pattern), str])
        htm_spec = HTMSpec()
        htm_spec.add_spec("spec_name", is_match_pattern, value_spec)  # we only support one spec. now
        return HtmDataRetrieverBase._get_value_iters(analyzer, htm_spec, target_sequence)
Exemplo n.º 2
0
    def retrieve(self, is_match_pattern, entries):
        empty_iter = iter([]), 0
        if not entries:
            logging.warning("[parser] no target entry specified")
            return empty_iter
        analyzer = self._get_analyzer()
        if not analyzer:
            return empty_iter

        value_spec = []
        for entry in entries:
            pos, name = entry[0], entry[1]
            value_spec.append([name, pos, str])
        from htm_parse.parse_engine import HTMSpec
        htm_spec = HTMSpec()
        htm_spec.add_spec("spec_name", is_match_pattern, value_spec)  # we only support one spec. now
        return HtmDataRetrieverBase._get_value_iters(analyzer, htm_spec, [entry[1] for entry in entries])