def PatternResolution(
                      quad, cursor, BRPs, orderByTriple=True, fetchall=True,
                      fetchContexts=False, select_modifier=''):
    subject,predicate,object_,context = quad
    targetBRPs = BinaryRelationPartitionCoverage(
                            (subject,predicate,object_,context),BRPs)
    unionQueries = []
    unionQueriesParams = []
    for brp in targetBRPs:
        first = targetBRPs.index(brp) == 0
        if fetchContexts:
            query = "SELECT DISTINCT %s FROM %s %s WHERE " % \
                (','.join(brp.selectContextFields(first)),
                 brp,
                 brp._intersectionSQL)
        else:
            query = CROSS_BRP_QUERY_SQL % \
                (select_modifier,
                 ','.join(brp.selectFields(first)),
                 brp,
                 brp._intersectionSQL)
        whereClause,whereParameters = brp.generateWhereClause(
                                (subject,predicate,object_,context))
        unionQueries.append(query+whereClause)
        unionQueriesParams.extend(whereParameters)
    
    if fetchContexts:
        orderBySuffix = ''
    else:
        orderBySuffix = orderByTriple and ' ORDER BY %s,%s,%s' % \
                (SlotPrefixes[SUBJECT], 
                 SlotPrefixes[PREDICATE],
                 SlotPrefixes[OBJECT]) or ''
    if len(unionQueries) == 1:
        query = unionQueries[0] + orderBySuffix
    else:
        query = ' union all '.join(['('+q+')' 
                        for q in unionQueries]) + orderBySuffix
    try:
        if EXPLAIN_INFO:
            cursor.execute("EXPLAIN "+query,tuple(unionQueriesParams))
            print query
            from pprint import pprint
            pprint(cursor.fetchall())
        cursor.execute(query,tuple(unionQueriesParams))
    except ValueError,e:
        print "## Query ##\n",query
        print "## Parameters ##\n",unionQueriesParams
        raise e
    if fetchall:
        qRT = cursor.fetchall()
    else:
        qRT = cursor.fetchone()
    return qRT
This function implements query pattern resolution against a list of
dataset/ETHPy150Open RDFLib/rdfextras/rdfextras/store/FOPLRelationalModel/BinaryRelationPartition.py/PatternResolution