예제 #1
0
def p_join_block_0(p):
    """
    join_block : LKEY union_block RKEY rest_join_block
    """
    if (p[4] != [] and isinstance(p[4][0], Filter)):
        p[0] = [UnionBlock(p[2])] + p[4]
    elif (p[4] != []):
        p[0] = [UnionBlock(p[2])] + [JoinBlock(p[4])]
    else:
        p[0] = [UnionBlock(p[2])]
예제 #2
0
    def getSplan(self, s, stars, soln, fl, dependent=False):
        splan = None
        if len(soln['dataset']) == 1:
            endp = soln['dataset'][0]

            splan = Service('<' + endp + '>', stars[s])
            splanfl = self.includeFilter([splan], fl)
            if len(splanfl) > 0:
                splan.filters.extend(splanfl)
                splan.filters = set(splan.filters)
                fl = list(set(fl) - set(splanfl))
        else:
            # make unions
            slist = []
            endps = [e for e in soln['dataset']]
            endps = list(set(endps))
            for url in endps:
                su = Service('<' + url + '>', stars[s])
                fls = self.includeFilter([su], fl)
                if len(fls) > 0:
                    su.filters = list(su.filters)
                    su.filters.extend(fls)
                    su.filters = set(su.filters)
                    fl = list(set(fl) - set(fls))

                suplan = self.makePlanAux([su], [], dependent)
                slist.append(suplan)

            splan = UnionBlock([JoinBlock([plan]) for plan in slist])

        return splan
예제 #3
0
def p_union_block_0(p):
    """
    union_block : pjoin_block rest_union_block POINT pjoin_block
    """
    punion = [JoinBlock(p[1])] + p[2]
    pjoin = [UnionBlock(punion)] + p[4]
    p[0] = [JoinBlock(pjoin)]
예제 #4
0
def p_union_block_1(p):
    """
    union_block : pjoin_block rest_union_block pjoin_block
    """
    punion = [JoinBlock(p[1])] + p[2]
    if (p[3] != []):
        pjoin = [UnionBlock(punion)] + p[3]
        p[0] = [JoinBlock(pjoin)]
    else:
        p[0] = [JoinBlock(p[1])] + p[2]
예제 #5
0
 def decomposeUnionBlock(self, ub):
     r = []
     filters = []
     for jb in ub.triples:
         pjb = self.decomposeJoinBlock(jb)
         if pjb:
             r.append(pjb)
             filters.extend(pjb.filters)
     if r:
         return UnionBlock(r)
     else:
         return None
예제 #6
0
def p_bgp_01(p):
    """
    bgp : bgp UNION bgp rest_union_block
    """
    ggp = [JoinBlock([p[1]])] + [JoinBlock([p[3]])] + p[4]
    p[0] = UnionBlock(ggp)
예제 #7
0
def p_bgp_0(p):
    """
    bgp :  LKEY bgp UNION bgp rest_union_block RKEY
    """
    ggp = [JoinBlock([p[2]])] + [JoinBlock([p[4]])] + p[5]
    p[0] = UnionBlock(ggp)
예제 #8
0
def p_ggp_0(p):
    """
    group_graph_pattern : union_block
    """
    p[0] = UnionBlock(p[1])
예제 #9
0
 def makePlanUnionBlock(self, ub):
     r = []
     for jb in ub.triples:
         r.append(self.makePlanJoinBlock(jb))
     return UnionBlock(r, ub.filters)
예제 #10
0
 def updateFilters(self, node, filters):
     return UnionBlock(node.triples, filters)
예제 #11
0
    def decomposeForMETIS(self, tl):
        results = []
        stars = self.getQueryStar(tl)

        for s in stars:
            ltr = stars[s]
            mols = {}
            unions = {}
            for tp in ltr:
                if tp.predicate.constant:
                    p = utils.getUri(tp.predicate, self.prefixes)[1:-1]
                    t = self.config.findbypred(p)

                    if len(t) > 0:
                        if len(t) == 1:
                            for c in t:
                                if c in mols:
                                    mols[c].append(tp)
                                else:
                                    mols[c] = [tp]
                                break
                        else:
                            unions[tp] = t

                    else:
                        print("cannot find any matching cluster for:", tl)
                        return []
                else:
                    mm = [m for m in self.config.metadata]
                    unions[tp] = mm
            for m in mols:
                results.append(Service("<" + m + ">", mols[m]))

            for tp in unions.copy():
                cs = unions[tp]

                tps = [t for t in unions if t != tp and unions[t] == cs]
                if len(tps) > 0:
                    for u in tps:
                        del unions[u]
                tps.append(tp)
                samesource = None
                url = None
                differents = None
                for s in cs:
                    wr = self.config.findMolecule(s)
                    wrs = [w for w in wr['wrappers']]
                    wrr = wrs[0]['url']
                    if url is None or wrr == url:
                        url = wrr
                        samesource = s
                    else:
                        differents = s
                        break
                if differents is None:
                    results.append(Service("<" + samesource + ">", tps))
                else:
                    results.append(
                        UnionBlock([
                            UnionBlock([Service("<" + c + ">", tps)])
                            for c in cs
                        ]))

        return results