Exemple #1
0
def _convert_clan_to_list_of_dicts(sorted_lefts: 'P( A )', absolute_clan: 'PP(A x A)') -> list:
    """Takes an absolute and left-regular clan and its left set and produces a right
    projection list of dictionaries.
    :param sorted_lefts: The left set of absolute_clan.
    :param absolute_clan: An absolute and left-regular clan.
    :return: A dictionary that represents the data in absolute_clan.
    """
    for rel in absolute_clan:
        left_to_right_dict = {}
        for left in sorted_lefts:
            # Get the right component associated with left and add it to our row.
            right = _relations.get_right(rel, left)
            if right is not _ud.Undef():
                left_to_right_dict[left] = right.value
        # Add right component dictionary to result
        yield left_to_right_dict
Exemple #2
0
def _convert_clan_to_list_of_dicts(ordered_lefts: 'P( A )', absolute_clan: 'PP(A x A)') -> list:
    """Convert a regular, absolute clan into a list of dictionaries.

    :param ordered_lefts: The left components of ``absolute_clan`` that are converted.
    :param absolute_clan: A regular, absolute clan that is converted into a list of dictionaries.
    :return: A list of dictionaries. Every dictionary represents a single relation in
        ``absolute_clan``. The lefts of the relation become the keys, the rights become the values
        of the dictionary.
    """
    for rel in absolute_clan:
        left_to_right_dict = {}
        for left in ordered_lefts:
            # Get the right component associated with left and add it to our row.
            right = _relations.get_right(rel, left)
            if right is not _ud.Undef():
                left_to_right_dict[left] = right.value
        # Add right component dictionary to result
        yield left_to_right_dict
Exemple #3
0
def _convert_clan_to_list_of_dicts(ordered_lefts: 'P( A )', absolute_clan: 'PP(A x A)') -> list:
    """Convert a regular, absolute clan into a list of dictionaries.

    :param ordered_lefts: The left components of ``absolute_clan`` that are converted.
    :param absolute_clan: A regular, absolute clan that is converted into a list of dictionaries.
    :return: A list of dictionaries. Every dictionary represents a single relation in
        ``absolute_clan``. The lefts of the relation become the keys, the rights become the values
        of the dictionary.
    """
    for rel in absolute_clan:
        left_to_right_dict = {}
        for left in ordered_lefts:
            # Get the right component associated with left and add it to our row.
            right = _relations.get_right(rel, left)
            if right is not _ud.Undef():
                left_to_right_dict[left] = right.value
        # Add right component dictionary to result
        yield left_to_right_dict
Exemple #4
0
 def _write_item_wrapper(self, relation: 'P(A x A)', left: '( A )',
                         prefix_separator: bool):
     right = _relations.get_right(relation, left)
     self._write_item(left, right, prefix_separator)
Exemple #5
0
 def _write_item_wrapper(self, relation: 'P(A x A)', left: '( A )', prefix_separator: bool):
     right = _relations.get_right(relation, left)
     self._write_item(left, right, prefix_separator)
     pass
Exemple #6
0
# We can use a Couplet to model a single truth, such as 'blue'^'sky' or 'jeff'^'name'. By collecting
# multiple Couplets together in a set, we form a mathematical model of a data record. This data
# structure, called a binary relation (abbreviated from hereon as simply 'relation'), is the
# fundamental data type in a Data Algebra program.
record_relation = Set(Couplet('id', 123), Couplet('name', 'jeff'), Couplet('loves', 'math'),
                      Couplet('loves', 'code'))
print(record_relation)

# Some relations, specify a function from left to right. This is the case when every left
# value maps to exactly one right value. Such a relation is called "left functional".
# Likewise, a relation can be said to be "right functional" when every right value maps
# to exactly one left value.
import algebraixlib.algebras.relations as relations

functional_relation = Set(Couplet('subject', 123), Couplet('name', 'james'), Couplet('level', 10))
print(relations.get_right(functional_relation, 'subject'))
print(relations.get_left(functional_relation, 123))
print(relations.get_right(record_relation,
                                'loves'))  # See non-functional record_relation above.

# Function evaluation syntax makes this more concise.
print("functional_relation('subject') =", functional_relation('subject'))
print("functional_relation(123) =", functional_relation(123))

# The power set of a set S, which we'll denote as P(S), is the set of all subsets of S. Note how in
# the example below, the elements of set_s are numbers, and the elements of powerset_s are sets of
# numbers.
set_s = Set(1, 2, 3)
powerset_s = sets.power_set(set_s)
print("S := ", set_s)
print("P(S) = ", powerset_s)
Exemple #7
0
# collecting multiple Couplets together in a set, we form a mathematical model of a data record.
# This data structure, called a binary relation (abbreviated from hereon as simply 'relation'), is
# the fundamental data type in a Data Algebra program.
record_relation = Set(Couplet('id', 123), Couplet('name', 'jeff'),
                      Couplet('loves', 'math'), Couplet('loves', 'code'))
print(record_relation)

# Some relations, specify a function from left to right. This is the case when every left
# value maps to exactly one right value. Such a relation is called "left functional".
# Likewise, a relation can be said to be "right functional" when every right value maps
# to exactly one left value.
import algebraixlib.algebras.relations as relations

functional_relation = Set(Couplet('subject', 123), Couplet('name', 'james'),
                          Couplet('level', 10))
print(relations.get_right(functional_relation, 'subject'))
print(relations.get_left(functional_relation, 123))
print(relations.get_right(
    record_relation, 'loves'))  # See non-functional record_relation above.

# Function evaluation syntax makes this more concise.
print("functional_relation('subject') =", functional_relation('subject'))
print("functional_relation(123) =", functional_relation(123))

# The power set of a set S, which we'll denote as P(S), is the set of all subsets of S. Note how in
# the example below, the elements of set_s are numbers, and the elements of powerset_s are sets of
# numbers.
set_s = Set(1, 2, 3)
powerset_s = sets.power_set(set_s)
print("S := ", set_s)
print("P(S) = ", powerset_s)