Beispiel #1
0
        def j2valid_trend(j):
            nonlocal entities_list

            if j < 3:
                return False

            j_tuple = j_param_types2j_latest(j, Param.Type.list())
            if any(map(is_none, j_tuple)):
                return False

            entities_tuple = [
                entities_list[j] if j is not None else None for j in j_tuple
            ]
            if any(map(lambda x: len(x) != 1, entities_tuple)):
                return False

            j_portlike, j_tradegood, j_rate, j_trend = j_tuple
            assert_equal(j_trend, j)
            if j_rate != j - 1:
                return False

            if j - 2 not in {j_portlike, j_tradegood}:
                return False

            entity_portlike, entity_tradegood, entity_rate, entity_trend = map(
                l_singleton2obj, entities_tuple)

            if FoxylibEntity.entity2type(
                    entity_portlike) != PortEntity.entity_type(
                    ):  # not culture
                return False

            entity_latter = max([entity_portlike, entity_tradegood],
                                key=FoxylibEntity.entity2span)

            span_latter, span_rate, span_trend = lmap(
                FoxylibEntity.entity2span,
                [entity_latter, entity_rate, entity_trend])

            span_latter_rate = SpanTool.span_pair2between(
                span_latter, span_rate)
            str_between_latter_rate = StringTool.str_span2substr(
                text, span_latter_rate)

            if not RegexTool.pattern_str2match_full(
                    RegexTool.pattern_blank_or_nullstr(),
                    str_between_latter_rate):
                return False

            span_rate_trend = SpanTool.span_pair2between(span_rate, span_trend)
            str_between_rate_trend = StringTool.str_span2substr(
                text, span_rate_trend)
            if not RegexTool.pattern_str2match_full(
                    RegexTool.pattern_blank_or_nullstr(),
                    str_between_rate_trend):
                return False

            return True
Beispiel #2
0
    def entity_pair2is_appendable(
        cls,
        text,
        entity_pair,
    ):
        Param = PriceSkillParameter

        entity_type_pair = lmap(FoxylibEntity.entity2type, entity_pair)
        param_type_pair = lmap(Param.Type.entity_type2parameter_type,
                               entity_type_pair)

        for param_type in param_type_pair:
            if param_type not in {Param.Type.PORTLIKE, Param.Type.TRADEGOOD}:
                return False

        param_type_1, param_type_2 = param_type_pair
        if param_type_1 != param_type_2:
            return False

        span_pair = lmap(FoxylibEntity.entity2span, entity_pair)
        text_between = StringTool.str_span2substr(
            text, SpanTool.span_pair2between(*span_pair))
        is_fullmatch = RegexTool.pattern_str2match_full(
            Param.pattern_delim(), text_between)
        if not is_fullmatch:
            return False

        return True