Skip to content

Commit

Permalink
docs: remover method and class documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis committed Nov 25, 2023
1 parent dbb40d0 commit 5d771f7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 113 deletions.
10 changes: 6 additions & 4 deletions src/data/encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ def encode_expression(expr: str) -> Base:
j = find_end(expr[i:]) + i + 1
sub_result = Predicate(expr[i - 1], [*expr[i:j]])
i = j

result.append(quantifiers[quantifier](sub_result))
else:
j = find_end(expr[i:]) + i + 1

if j >= 2:
sub_result = Predicate(expr[i], [*expr[i + 1:j]])
else:
Expand Down Expand Up @@ -102,18 +102,20 @@ def find_operator(expr: str) -> str | None:

return None


def find_quantifier(expr: str) -> str | None:
for quantifier in quantifiers:
if expr.startswith(quantifier):
return quantifier

return None


def find_end(expr):
for i in range(len(expr)):
if not expr[i].isalpha() or expr[i] == 'v':
return i - 1
elif i == len(expr) - 1:
return i
return None

return None
3 changes: 2 additions & 1 deletion src/entity/node.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from src.entity.base import Base


class Node(Base):
def __init__(self, data):
self.data = data
self.childrens = []

def add_child(self, children):
self.childrens.append(children)

Expand Down
31 changes: 1 addition & 30 deletions src/entity/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@


class Operator(Base):
"""
Base class for logical operators in a logical expression tree.
Attributes:
left: The left operand of the operator.
right: The right operand of the operator.
"""
symbol = ''

def __init__(self, left, right):
self.left = left
Expand All @@ -23,45 +17,22 @@ def __str__(self):


class Conjunction(Operator):
"""
Represents the logical `AND` operation in a logical expression tree.
"""

symbol = '^'


class Disjunction(Operator):
"""
Represents the logical `OR` operation in a logical expression tree.
"""

symbol = 'v'


class Conditional(Operator):
"""
Represents the logical `NOT` `OR` operation in a logical expression tree.
"""

symbol = '->'


class BiConditional(Operator):
"""
Represents the logical `EQ` operation in a logical expression tree.
"""

symbol = '<->'


class Negation(Base):
"""
Represents the logical `NOT` operation in a logical expression tree.
Attributes:
expr: The expression being negated.
"""

def __init__(self, expr):
self.expr = expr

Expand Down
13 changes: 9 additions & 4 deletions src/entity/quantifiers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from src.entity.base import Base
from src.entity.operators import Operator


class Quantifier(Base):
symbol = ''

Expand All @@ -12,16 +13,14 @@ def __init__(self, expr):
def __str__(self):
return f'{self.symbol}{self._expr}'


class Universal(Quantifier):
symbol = '∀x'


class Existential(Quantifier):
symbol = '∃x'

quantifiers = {
"Ax": Universal,
"Ex": Existential
}

class Predicate(Base):
def __init__(self, predicate, letters=['x']):
Expand All @@ -30,3 +29,9 @@ def __init__(self, predicate, letters=['x']):

def __str__(self):
return f'{self.predicate}{",".join(self.letters)}'


quantifiers = {
"Ax": Universal,
"Ex": Existential
}
74 changes: 0 additions & 74 deletions src/truth_table/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,10 @@


def generate_combinations(prepositions):
"""
Generate all possible combinations of True and False for a list of prepositions.
Args:
prepositions (list of str): A list of prepositions for which combinations are generated.
Returns:
list of tuples: A list of tuples representing all possible combinations of True and False for prepositions.
"""
return list(product([True, False], repeat=len(prepositions)))


def evaluate_expression(expr, result, row):
"""
Recursively evaluate a logical expression.
Args:
expr (Base): The logical expression to be evaluated.
result (dict): A list of evaluation results for each expression.
row (int): Current row in combination
Returns:
bool: The result of the evaluation.
This function recursively evaluates logical expressions, either prepositions or compound expressions, and stores
the results in the 'result' list.
When the expression is a preposition (a string), it retrieves the corresponding value from the combinations.
When the expression is a Negation or an Operator (e.g., Conjunction, Disjunction), it evaluates the subexpressions
and calculates the result, which is then stored in the 'result' list.
The function returns the final result of the evaluation.
"""
value = None

if expr in result and len(result[expr]) > row:
Expand Down Expand Up @@ -67,21 +37,6 @@ def evaluate_expression(expr, result, row):


def evaluate_expressions(prepositions, expressions, combinations):
"""
Evaluate a list of logical expressions for all possible combinations of prepositions.
Args:
prepositions (list of str): A list of prepositions used in the expressions.
expressions (list of Base): A list of logical expressions to evaluate.
combinations (list of tuples): A list of tuples representing combinations of True and False for prepositions.
Returns:
list of lists: A list of evaluation results for each expression and each combination.
This function evaluates a list of logical expressions (expressions) for all possible combinations of True and False
for prepositions. It returns a list of evaluation results for each expression and each combination
**in column orientation**.
"""
prep_combinations = list(zip(*combinations))
result = {Preposition(preposition): prep_combinations[i] for i, preposition in enumerate(prepositions)}

Expand All @@ -105,20 +60,6 @@ def evaluate_expressions(prepositions, expressions, combinations):


def table_type(results):
"""
Determine the type of a logical table based on its final evaluation results.
Args:
results (list of lists): A list of evaluation results for logical expressions and combinations.
Returns:
str: The type of the logical table, which can be "Tautologia," "Contradição," or "Contingência."
This function analyzes the evaluation results of logical expressions and returns the type of the logical table based on
those results. If all results indicate True, the table is a "Tautologia." If all results indicate False, it is a
"Contradição." Otherwise, it is a "Contingência."
"""

if all(result[-1] for result in results):
return "Tautologia"
elif all(not result[-1] for result in results):
Expand All @@ -128,21 +69,6 @@ def table_type(results):


def is_valid(results, premises, conclusion):
"""
Checks the validity of a logical argument based on premise and conclusion truth values.
Args:
results (dict): A dictionary mapping propositional variables to their truth values.
premises (list): A list of strings representing the premises of the argument.
conclusion (str): A string representing the conclusion of the argument.
Returns:
bool: True if the argument is logically valid, False otherwise.
The `is_valid` function verifies whether a logical argument is valid based on the truth values of the premises
and the conclusion. It uses a truth table to assess the argument's validity.
"""

final_premises = [results[premise] for premise in premises]
final_conclusion = results[conclusion]

Expand Down

0 comments on commit 5d771f7

Please sign in to comment.