Skip to content

Commit

Permalink
Refactoring AF's: removed the functionality to get incoming and outgo…
Browse files Browse the repository at this point in the history
…ing defeat arguments from the argument (this can be obtained via the AF).
  • Loading branch information
Daphne Odekerken committed Dec 29, 2023
1 parent 1882ea6 commit fc181c0
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ def __init__(self, name: str = '',
else:
self._defeats = defeats

for defeat in self._defeats:
defeat.from_argument.add_outgoing_defeat(defeat.to_argument)
defeat.to_argument.add_ingoing_defeat(defeat.from_argument)

def __repr__(self):
return '( [' + ', '.join(argument.name
for argument in self.arguments) + \
Expand Down
66 changes: 0 additions & 66 deletions src/py_arg/abstract_argumentation/classes/argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
class Argument:
def __init__(self, name: str):
self.name = name
self._ingoing_defeat_arguments = []
self._outgoing_defeat_arguments = []

def __repr__(self):
return self.name
Expand All @@ -21,67 +19,3 @@ def __lt__(self, other):

def __hash__(self):
return hash(str(self))

def add_ingoing_defeat(self, other: 'Argument'):
"""
Add ingoing defeat from the other argument. NOTE: does not add an
outgoing defeat from other to this argument!
:param other: The argument defeating this argument.
"""
self._ingoing_defeat_arguments.append(other)

def add_outgoing_defeat(self, other: 'Argument'):
"""
Add outgoing defeat to the other argument. NOTE: does not add an
ingoing defeat to the other argument!
:param other: The argument defeated by this argument.
"""
self._outgoing_defeat_arguments.append(other)

@property
def get_ingoing_defeat_arguments(self) -> List['Argument']:
"""
Get all arguments that defeat this argument.
:return: Arguments defeating this argument.
>>> a = Argument('a')
>>> b = Argument('b')
>>> c = Argument('c')
>>> a.add_ingoing_defeat(b)
>>> a.add_ingoing_defeat(c)
>>> a.get_ingoing_defeat_arguments
[b, c]
>>> b.add_outgoing_defeat(c)
>>> c.get_ingoing_defeat_arguments
[]
"""
return self._ingoing_defeat_arguments

@property
def get_outgoing_defeat_arguments(self) -> List['Argument']:
"""
Get all arguments that are defeated by this argument.
:return: Arguments defeated by this argument.
>>> a = Argument('a')
>>> b = Argument('b')
>>> c = Argument('c')
>>> a.add_outgoing_defeat(b)
>>> a.add_outgoing_defeat(c)
>>> a.get_outgoing_defeat_arguments
[b, c]
>>> b.add_ingoing_defeat(c)
>>> c.get_outgoing_defeat_arguments
[]
"""
return self._outgoing_defeat_arguments


if __name__ == "__main__":
import doctest

doctest.testmod()
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ def compute_all_literal_grounded_justification_status_naive(
for grounded_argument in grounded_extension:
result[grounded_argument.conclusion] = EnumJustificationLabel.DEFENDED
for attacked_argument in \
grounded_argument.get_outgoing_defeat_arguments:
arg_framework.get_outgoing_defeat_arguments(grounded_argument):
result[attacked_argument.conclusion] = EnumJustificationLabel.OUT
return LiteralLabels(result)
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ def generate_af(self) -> AbstractArgumentationFramework:
for premise in arg1.premise:
for arg2 in arguments:
if self.contraries[premise] == arg2.conclusion:
arg1.add_ingoing_defeat(arg2)
arg2.add_outgoing_defeat(arg1)
defeats.add(Defeat(arg2, arg1))

return AbstractArgumentationFramework('', arguments=list(arguments),
Expand Down Expand Up @@ -114,8 +112,6 @@ def generate_af_full(self) -> AbstractArgumentationFramework:
for premise in arg1.premise:
for arg2 in arguments:
if self.contraries[premise] == arg2.conclusion:
arg1.add_ingoing_defeat(arg2)
arg2.add_outgoing_defeat(arg1)
defeats.add(Defeat(arg2, arg1))

return AbstractArgumentationFramework('', arguments=list(arguments),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,6 @@ def __init__(self, name: str = '',
else:
self._uncertain_defeats = uncertain_defeats

for defeat in self._defeats + self._uncertain_defeats:
if defeat.from_argument.name in self._arguments.keys():
defeat_from_argument = self._arguments[
defeat.from_argument.name]
else:
defeat_from_argument = self._uncertain_arguments[
defeat.from_argument.name]
if defeat.to_argument.name in self._arguments.keys():
defeat_to_argument = self._arguments[defeat.to_argument.name]
else:
defeat_to_argument = self._uncertain_arguments[
defeat.to_argument.name]
defeat_from_argument.add_outgoing_defeat(defeat.to_argument)
defeat_to_argument.add_ingoing_defeat(defeat.from_argument)

def __eq__(self, other):
return isinstance(other, IncompleteArgumentationFramework) and \
self.arguments == other.arguments and \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ def test_get_argumentation_framework(self):
af = arg_theory.create_abstract_argumentation_framework('af')
arg_for_r = af.get_argument('r (ordinary premise)')
self.assertEqual(arg_for_r.name, 'r (ordinary premise)')
defeaters_of_r = arg_for_r.get_ingoing_defeat_arguments
defeaters_of_r = af.get_incoming_defeat_arguments(arg_for_r)
self.assertEqual(len(defeaters_of_r), 1)
self.assertEqual(defeaters_of_r[0].name, '-r (ordinary premise)')
defeated_by_r = arg_for_r.get_ingoing_defeat_arguments
defeated_by_r = af.get_incoming_defeat_arguments(arg_for_r)
self.assertEqual(len(defeated_by_r), 1)
self.assertEqual(defeated_by_r[0].name, '-r (ordinary premise)')
arg_for_not_r = af.get_argument('-r (ordinary premise)')
defeated_by_not_r = arg_for_not_r.get_outgoing_defeat_arguments
defeated_by_not_r = af.get_outgoing_defeat_arguments(arg_for_not_r)
self.assertEqual(len(defeated_by_not_r), 3)

0 comments on commit fc181c0

Please sign in to comment.