Ejemplo n.º 1
0
    def __str__(self):
        """
        Prints Expectation of feature for conditions.
        E(feature | c_1 Λ… Λc_n) (norm by multipliers).
        """

        formula = " * E("
        # features
        for i, (table, multiplier) in enumerate(self.features):
            formula += table + "." + multiplier
            if i < len(self.features) - 1:
                formula += "*"

        # /(multipliers)
        if len(self.normalizing_multipliers) > 0:
            formula += " /("
            # 1/multiplier
            for i, (table,
                    normalizer) in enumerate(self.normalizing_multipliers):
                formula += table + "." + normalizer
                if i < len(self.normalizing_multipliers) - 1:
                    formula += "*"
            formula += ")"

        # |c_1 Λ… Λc_n
        if len(self.conditions) > 0:
            formula += "| "
            formula += print_conditions(self.conditions)

        formula += ")"

        return formula
    def true_cardinality(self, query):
        full_join_query = gen_full_join_query(self.schema_graph, query.relationship_set, query.table_set, "JOIN")

        where_cond = print_conditions(query.conditions, seperator='AND')
        if where_cond != "":
            where_cond = "WHERE " + where_cond
        sql_query = full_join_query.format("COUNT(*)", where_cond)
        cardinality = self.db_connection.get_result(sql_query)
        return sql_query, cardinality
Ejemplo n.º 3
0
    def __str__(self):
        """
        Prints Probability of conditions
        """

        formula = ""
        if len(self.conditions) > 0:
            formula += " * P("
            formula += print_conditions(self.conditions)
            formula += ")"

        return formula
Ejemplo n.º 4
0
    def __str__(self):
        """
        Prints Expectation of multipliers for conditions.
        E(multipliers * 1_{c_1 Λ… Λc_n})
        """

        if self.inverse:
            formula = " / E("
        else:
            formula = " * E("

        for i, (table, normalizer) in enumerate(self.nominator_multipliers):
            formula += table + "." + normalizer
            if i < len(self.nominator_multipliers) - 1:
                formula += "*"
        if len(self.nominator_multipliers) == 0:
            formula += "1"

        if len(self.denominator_multipliers) > 0:
            formula += "/("

            # 1/multiplier
            for i, (table,
                    normalizer) in enumerate(self.denominator_multipliers):
                formula += table + "." + normalizer
                if i < len(self.denominator_multipliers) - 1:
                    formula += "*"
            formula += ")"

        # |c_1 Λ… Λc_n
        if len(self.conditions) > 0:
            formula += "* 1_{"
            formula += print_conditions(self.conditions)
            formula += "}"
        formula += ")"

        return formula
Ejemplo n.º 5
0
 def print_conditions(self, seperator='Λ'):
     return print_conditions(self.conditions, seperator=seperator)