Пример #1
0
    def select_sources(triple_patterns, source_selector, **kwargs):

        verbose = kwargs.get("verbose", True)
        threshold = kwargs.get("threshold", -1)
        tp_groups = []
        for triple_pattern in triple_patterns:
            sources_per_tp = []
            if not triple_pattern.count:
                tp_cnt = source_selector.select_sources(triple_pattern)
            else:
                tp_cnt = triple_pattern.count
            if tp_cnt > 0:
                if not verbose:
                    sources_per_tp.append(triple_pattern)
                elif threshold > 0 and len(
                        triple_pattern.sources.keys()) > threshold:
                    sources_per_tp.append(triple_pattern)
                else:
                    for source, cnt in triple_pattern.sources.items():
                        tp = TriplePattern(triple_pattern[0],
                                           triple_pattern[1],
                                           triple_pattern[2])
                        tp.sources[source] = cnt
                        tp.cardinality = cnt
                        sources_per_tp.append(tp)
            tp_groups.append(sources_per_tp)
        return tp_groups
Пример #2
0
def dict_to_logical(plan_dict, sources):
    left = None
    right = None
    join = None

    for key, value in plan_dict.items():
        if key == 'right':
            right = dict_to_logical(plan_dict['right'], sources)
        if key == 'left':
            left = dict_to_logical(plan_dict['left'], sources)
        if key == 'type':
            if value == 'NLJ':
                join = Xnjoin
            else:
                join = Fjoin

        if key == 'tpf':
            pattern_var = re.compile(r'\?\w+')
            pattern_uri = re.compile(r'\<[^<^>]+\>')
            pattern_literal = re.compile(r'[\'"].*[\'"]@?\w*')

            matches_var = pattern_var.finditer(value)
            matches_uri = pattern_uri.finditer(value)
            matches_literal = pattern_literal.finditer(value)

            matches_var = [(m.start(), m.group(0)) for m in matches_var]
            matches_uri = [(m.start(), m.group(0)) for m in matches_uri]
            matches_literal = [(m.start(), m.group(0))
                               for m in matches_literal]

            arguments = [matches_var, matches_uri, matches_literal]

            arguments = proc_arguments(arguments)

            triple_pattern = TriplePattern(Argument(arguments[0]),
                                           Argument(arguments[1]),
                                           Argument(arguments[2]))
            cardinality = int(plan_dict.get("cardinality", 0))
            triple_pattern.cardinality = cardinality
            triple_pattern.sources = {sources[0]: cardinality}
            print('--- Now printing Triple Pattern: ---')
            print(triple_pattern)
            print('------')
            return LogicalPlan(triple_pattern)

    print plan_dict
    logical_plan = LogicalPlan(left, right, join)
    logical_plan.cardinality = int(plan_dict.get("estimated_cardinality", 0))
    return logical_plan