neurolang.relational_algebra.relational_algebra module¶
- class neurolang.relational_algebra.relational_algebra.BinaryRelationalAlgebraOperation(relation_left, relation_right)¶
Bases:
RelationalAlgebraOperation
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
columns
get_wrapped_attribute
- columns()¶
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.ColumnInt¶
-
Refer to a relational algebra set’s column by its index.
- Attributes:
denominator
the denominator of a rational number in lowest terms
imag
the imaginary part of a complex number
numerator
the numerator of a rational number in lowest terms
real
the real part of a complex number
Methods
as_integer_ratio
(/)Return integer ratio.
bit_length
(/)Number of bits necessary to represent self in binary.
conjugate
Returns self, the complex conjugate of any int.
from_bytes
(/, bytes, byteorder, *[, signed])Return the integer represented by the given array of bytes.
to_bytes
(/, length, byteorder, *[, signed])Return an array of bytes representing an integer.
- class neurolang.relational_algebra.relational_algebra.ColumnStr¶
-
Refer to a named relational algebra set’s column by its name.
Methods
capitalize
(/)Return a capitalized version of the string.
casefold
(/)Return a version of the string suitable for caseless comparisons.
center
(width[, fillchar])Return a centered string of length width.
count
(sub[, start[, end]])Return the number of non-overlapping occurrences of substring sub in string S[start:end].
encode
(/[, encoding, errors])Encode the string using the codec registered for encoding.
endswith
(suffix[, start[, end]])Return True if S ends with the specified suffix, False otherwise.
expandtabs
(/[, tabsize])Return a copy where all tab characters are expanded using spaces.
find
(sub[, start[, end]])Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
format
(*args, **kwargs)Return a formatted version of S, using substitutions from args and kwargs.
format_map
(mapping)Return a formatted version of S, using substitutions from mapping.
index
(sub[, start[, end]])Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
isalnum
(/)Return True if the string is an alpha-numeric string, False otherwise.
isalpha
(/)Return True if the string is an alphabetic string, False otherwise.
isascii
(/)Return True if all characters in the string are ASCII, False otherwise.
isdecimal
(/)Return True if the string is a decimal string, False otherwise.
isdigit
(/)Return True if the string is a digit string, False otherwise.
isidentifier
(/)Return True if the string is a valid Python identifier, False otherwise.
islower
(/)Return True if the string is a lowercase string, False otherwise.
isnumeric
(/)Return True if the string is a numeric string, False otherwise.
isprintable
(/)Return True if the string is printable, False otherwise.
isspace
(/)Return True if the string is a whitespace string, False otherwise.
istitle
(/)Return True if the string is a title-cased string, False otherwise.
isupper
(/)Return True if the string is an uppercase string, False otherwise.
join
(iterable, /)Concatenate any number of strings.
ljust
(width[, fillchar])Return a left-justified string of length width.
lower
(/)Return a copy of the string converted to lowercase.
lstrip
([chars])Return a copy of the string with leading whitespace removed.
maketrans
(x[, y, z])Return a translation table usable for str.translate().
partition
(sep, /)Partition the string into three parts using the given separator.
replace
(old, new[, count])Return a copy with all occurrences of substring old replaced by new.
rfind
(sub[, start[, end]])Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
rindex
(sub[, start[, end]])Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
rjust
(width[, fillchar])Return a right-justified string of length width.
rpartition
(sep, /)Partition the string into three parts using the given separator.
rsplit
(/[, sep, maxsplit])Return a list of the words in the string, using sep as the delimiter string.
rstrip
([chars])Return a copy of the string with trailing whitespace removed.
split
(/[, sep, maxsplit])Return a list of the words in the string, using sep as the delimiter string.
splitlines
(/[, keepends])Return a list of the lines in the string, breaking at line boundaries.
startswith
(prefix[, start[, end]])Return True if S starts with the specified prefix, False otherwise.
strip
([chars])Return a copy of the string with leading and trailing whitespace removed.
swapcase
(/)Convert uppercase characters to lowercase and lowercase characters to uppercase.
title
(/)Return a version of the string where each word is titlecased.
translate
(table, /)Replace each character in the string using the given translation table.
upper
(/)Return a copy of the string converted to uppercase.
zfill
(width, /)Pad a numeric string with zeros on the left, to fill a field of the given width.
- class neurolang.relational_algebra.relational_algebra.ConcatenateConstantColumn(relation, column_name, column_value)¶
Bases:
UnaryRelationalAlgebraOperation
Add a column with a repeated constant value to a relation.
- Attributes:
- relationConstant[RelationalAlgebraSet]
Relation to which the column will be added.
- column_nameConstant[ColumnStr] or Symbol[ColumnStr]
Name of the newly added column.
- column_valueConstant
Constant value repeated in the new column.
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
columns
get_wrapped_attribute
- columns()¶
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.Destroy(relation, src_column, dst_column)¶
Bases:
UnaryRelationalAlgebraOperation
Operation to map a column of a collection of elements into a new column with all collections concatenated
Notes
The concept of set destruction is formally defined in chapter 20 of [1].
[1]Abiteboul, S., Hull, R. & Vianu, V. “Foundations of databases”. ( Addison Wesley, 1995).
- Attributes:
- relationExpression[AbstractSet]
Relation on which the projections are applied.
- src_columnConstant[ColumnStr]
Column to destroy in the operation.
- dst_columnConstant[ColumnStr]
Column to map onto the new set.
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
columns
get_wrapped_attribute
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.Difference(relation_left, relation_right)¶
Bases:
BinaryRelationalAlgebraOperation
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
columns
get_wrapped_attribute
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.EquiJoin(relation_left, columns_left, relation_right, columns_right)¶
Bases:
BinaryRelationalAlgebraOperation
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
columns
get_wrapped_attribute
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.ExtendedProjection(relation, projection_list)¶
Bases:
RelationalAlgebraOperation
General operation defining string-based relational algebra projections allowing flexible computations on a relation’s columns.
Notes
The concept of extended projection is formally defined in section 5.2.5 of [1].
[1]Garcia-Molina, Hector, Jeffrey D. Ullman, and Jennifer Widom. “Database systems: the complete book.” (2009).
- Attributes:
- relationExpression[AbstractSet]
Relation on which the projections are applied.
- projection_listTuple[FunctionApplicationListMember]
List of projections to apply.
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
columns
get_wrapped_attribute
- columns()¶
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.FullOuterNaturalJoin(relation_left, relation_right)¶
Bases:
BinaryRelationalAlgebraOperation
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
columns
get_wrapped_attribute
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.FunctionApplicationListMember(fun_exp, dst_column)¶
Bases:
Definition
Representation of a function application to a column. Can be used to represent either the application of an extended projection, or the application of an aggregate function, to a column.
Notes
In the case of an extended projection operation, as described in [1], a function application list member can either be
a single attribute (column) name in the relation, resulting in a normal non-extended projection,
an expression x -> y where x and y are both attribute (column) names, x effectively being rename as y,
or an expression E -> z where E is an expression involving attributes of the relation, arithmetic operators, and string operators, and z is a new name for the attribute that results from the calculation implied by E. For example, a + b -> x represents the sum of the attributes a and b, renamed x.
[1]Garcia-Molina, Hector, Jeffrey D. Ullman, and Jennifer Widom. “Database systems: the complete book.” (2009).
- Attributes:
- fun_expUnion[Constant[str], FunctionApplication]
Constant string representation of an extended projection operation, or FunctionApplication representation of an aggregate function.
- dst_columnConstant[ColumnStr] or Symbol[ColumnStr]
Constant column string of the destination column.
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
get_wrapped_attribute
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.GroupByAggregation(relation, groupby, aggregate_functions)¶
Bases:
RelationalAlgebraOperation
General representation of a groupby operation with aggregate functions.
- Attributes:
- relationExpression[AbstractSet]
Relation on which the groupby is applied.
- groupbyTuple[Union[Constant[ColumnStr], Symbol[ColumnStr]]]
The list of columns on which to group.
- aggregate_functionsTuple[FunctionApplicationListMember]
List of aggregate functions to apply.
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
columns
get_wrapped_attribute
- columns()¶
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.Intersection(relation_left, relation_right)¶
Bases:
BinaryRelationalAlgebraOperation
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
columns
get_wrapped_attribute
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.LeftNaturalJoin(relation_left, relation_right)¶
Bases:
BinaryRelationalAlgebraOperation
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
columns
get_wrapped_attribute
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.NAryRelationalAlgebraOperation¶
Bases:
RelationalAlgebraOperation
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
columns
get_wrapped_attribute
- columns()¶
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.NameColumns(relation, column_names)¶
Bases:
UnaryRelationalAlgebraOperation
Give names to the columns of a relational algebra set.
All columns must be named at once. Each column name must either be a Constant[ColumnStr] or a Symbol[ColumnStr] pointing to a symbolic column name resolved when the expression is compiled.
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
columns
get_wrapped_attribute
- columns()¶
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.NaturalJoin(relation_left, relation_right)¶
Bases:
BinaryRelationalAlgebraOperation
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
columns
get_wrapped_attribute
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.NumberColumns(relation, column_names)¶
Bases:
UnaryRelationalAlgebraOperation
Converts a named relational algebra set to an unnamed one
All columns must be numbered at once. Each column name must either be a Constant[ColumnStr] and the numbering will be the ordering in the column_names attribute.
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
columns
get_wrapped_attribute
- columns()¶
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.Product(relations)¶
Bases:
NAryRelationalAlgebraOperation
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
columns
get_wrapped_attribute
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.Projection(relation, attributes)¶
Bases:
UnaryRelationalAlgebraOperation
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
columns
get_wrapped_attribute
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.RelationalAlgebraOperation¶
Bases:
Definition
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
columns
get_wrapped_attribute
- columns()¶
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.RelationalAlgebraSolver(symbol_table=None)¶
Bases:
ExpressionWalker
Mixing that walks through relational algebra expressions and executes the operations.
Relations are expected to be represented as objects with the same interface as
RelationalAlgebraSet
.- Attributes:
patterns
Property holding an iterator of triplets
(pattern, guard, action)
.
Methods
match
(expression)Find the action for a given expression by going through the
patterns
.pattern_match
(pattern, expression)Return
True
ifpattern
matchesexpression
.aggregate
arithmetic_string_expression
concatenate_constant_column
extended_projection
pattern_match_expression
pattern_match_expression_parameters
pattern_match_expression_tuple
pattern_match_tuple
process_expression
process_iterable_argument
prov_arithmetic_operation
ra_constant
ra_difference
ra_equijoin
ra_full_outer_naturaljoin
ra_intersection
ra_left_naturaljoin
ra_name_columns
ra_naturaljoin
ra_number_columns
ra_product
ra_projection
ra_rename_column
ra_rename_columns
ra_symbol
ra_union
replace_null
selection_between_columns
selection_by_constant
selection_general_selection_by_constant
set_destroy
walk
- aggregate(agg_op)¶
- arithmetic_string_expression(expression)¶
- concatenate_constant_column(concat_op)¶
- extended_projection(proj_op)¶
- prov_arithmetic_operation(arithmetic_op)¶
- ra_constant(constant)¶
- ra_difference(difference)¶
- ra_equijoin(equijoin)¶
- ra_full_outer_naturaljoin(naturaljoin)¶
- ra_intersection(intersection)¶
- ra_left_naturaljoin(naturaljoin)¶
- ra_name_columns(name_columns)¶
- ra_naturaljoin(naturaljoin)¶
- ra_number_columns(number_columns)¶
- ra_product(product)¶
- ra_projection(projection)¶
- ra_rename_column(rename_column)¶
- ra_rename_columns(rename_columns)¶
- ra_symbol(symbol)¶
- ra_union(union)¶
- replace_null(expression)¶
- selection_between_columns(selection)¶
- selection_by_constant(selection)¶
- selection_general_selection_by_constant(selection)¶
- set_destroy(destroy)¶
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.RenameColumn(relation, src, dst)¶
Bases:
UnaryRelationalAlgebraOperation
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
columns
get_wrapped_attribute
- columns()¶
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.RenameColumns(relation, renames)¶
Bases:
UnaryRelationalAlgebraOperation
Convenient operation for renaming multiple columns at the same time.
- Attributes:
- relationNamedRelationalAlgebraFrozenSet
The relation whose columns shall be renamed.
- renamestuple of pairs of Constant[ColumnStr] or Symbol[ColumnStr]
The renamings that should happen, represented as tuples (src, dst).
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
columns
get_wrapped_attribute
- columns()¶
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.ReplaceConstantColumnStrBySymbol(*args, **kwargs)¶
Bases:
ExpressionWalker
- Attributes:
patterns
Property holding an iterator of triplets
(pattern, guard, action)
.
Methods
match
(expression)Find the action for a given expression by going through the
patterns
.pattern_match
(pattern, expression)Return
True
ifpattern
matchesexpression
.column_int
column_str
pattern_match_expression
pattern_match_expression_parameters
pattern_match_expression_tuple
pattern_match_tuple
process_expression
process_iterable_argument
walk
- column_int(expression)¶
- column_str(expression)¶
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.ReplaceNull(relation, column, value)¶
Bases:
UnaryRelationalAlgebraOperation
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
columns
get_wrapped_attribute
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.Selection(relation, formula)¶
Bases:
UnaryRelationalAlgebraOperation
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
columns
get_wrapped_attribute
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.StringArithmeticWalker(*args, **kwargs)¶
Bases:
PatternWalker
Walker translating an Expression with basic arithmetic operations on a relation’s columns to its equivalent string representation.
The expression can refer to the names a relation’s columns or to the length of an other constant relation.
- Attributes:
patterns
Property holding an iterator of triplets
(pattern, guard, action)
.
Methods
match
(expression)Find the action for a given expression by going through the
patterns
.pattern_match
(pattern, expression)Return
True
ifpattern
matchesexpression
.arithmetic_operation
negative_value
operation_sum
pattern_match_expression
pattern_match_expression_parameters
pattern_match_expression_tuple
pattern_match_tuple
process_constant_column_int
process_constant_column_str
process_constant_float
process_constant_int
process_constant_str
translatable_numpy_operation
walk
- arithmetic_operation(fa)¶
- negative_value(fa)¶
- operation_sum(fa)¶
- process_constant_column_int(cst_col_int)¶
- process_constant_column_str(cst_col_str)¶
- process_constant_float(cst)¶
- process_constant_int(cst)¶
- process_constant_str(cst)¶
- translatable_numpy_operation(fa)¶
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.UnaryRelationalAlgebraOperation¶
Bases:
RelationalAlgebraOperation
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
columns
get_wrapped_attribute
- columns()¶
- type = typing.Any¶
- class neurolang.relational_algebra.relational_algebra.Union(relation_left, relation_right)¶
Bases:
BinaryRelationalAlgebraOperation
Methods
__call__
(*args, **kwargs)Call self as a function.
apply
(*args)Builds a new expression using a tuple of its parameters
unapply
()Returns a tuple of parameters used to build the expression.
cast
change_type
columns
get_wrapped_attribute
- type = typing.Any¶
- neurolang.relational_algebra.relational_algebra.get_expression_columns(expression)¶
- neurolang.relational_algebra.relational_algebra.int2columnint_constant(col)¶
- neurolang.relational_algebra.relational_algebra.is_arithmetic_operation(exp)¶
Whether the expression is an arithmetic operation function application.
- Parameters:
- expExpression
- Returns:
- bool
- neurolang.relational_algebra.relational_algebra.is_translatable_operation(exp)¶
- neurolang.relational_algebra.relational_algebra.str2columnstr_constant(name)¶