Skip to content

Commit

Permalink
Update on skeptical acceptance.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daphne Odekerken committed Apr 24, 2024
1 parent e051edf commit 7fb1d1b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 13 deletions.
5 changes: 5 additions & 0 deletions src/py_arg/aspic/semantics/get_accepted_formulas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
AcceptanceStrategy
from py_arg.abstract_argumentation.semantics.get_accepted_arguments import \
get_accepted_arguments
from py_arg.aspic.classes.argumentation_theory import ArgumentationTheory
from py_arg.aspic.classes.instantiated_argument import InstantiatedArgument
from py_arg.aspic.classes.literal import Literal


def get_accepted_formulas(
arg_theory: ArgumentationTheory,
extensions: Set[FrozenSet[InstantiatedArgument]],
acceptance_strategy: AcceptanceStrategy) -> \
Set[Literal]:
"""
Calculate the set of accepted formulas from a set of extensions
(sets of arguments) and evaluation strategy
:param arg_theory: The argumentation theory..
:param extensions: The extensions (sets of collectively accepted arguments)
:param acceptance_strategy: The acceptance strategy (e.g., skeptical or
credulous).
Expand All @@ -31,6 +34,8 @@ def get_accepted_formulas(
return set(arg.conclusion for arg in accepted_arguments
if not arg.conclusion.defeasible_rule_based)
elif acceptance_strategy == AcceptanceStrategy.WEAKLY_SKEPTICAL:
if not extensions:
return set(arg_theory.argumentation_system.language.values())
extension_formulas = [{arg.conclusion for arg in extension}
for extension in extensions]
return set.intersection(*extension_formulas)
12 changes: 10 additions & 2 deletions src/py_arg/experiments/experiment_get_accepted_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_accepted_formulas_for_file(
argumentation_theory_file_path: str,
ordering_specification: str,
semantics_specification: str,
acceptance_strategy: AcceptanceStrategy
acceptance_strategy: str
) -> List[str]:
# Step 1: read the argumentation theory from the LP file.
reader = ArgumentationTheoryFromLPFileReader()
Expand Down Expand Up @@ -46,7 +46,15 @@ def get_accepted_formulas_for_file(
arg_framework, semantics_specification)

# Step 4: get the conclusions of accepted arguments.
if acceptance_strategy == 'credulous':
acc_strategy = AcceptanceStrategy.CREDULOUS
elif acceptance_strategy == 'skeptical':
acc_strategy = AcceptanceStrategy.WEAKLY_SKEPTICAL
else:
raise NotImplementedError('Choose "credulous" or "skeptical" for the '
'acceptance strategy.')
accepted_formulas = \
get_accepted_formulas(frozen_extensions, acceptance_strategy)
get_accepted_formulas(arg_theory, frozen_extensions,
acc_strategy)
result = sorted([literal.s1 for literal in accepted_formulas])
return result
9 changes: 9 additions & 0 deletions src/py_arg_tests/resources/no_stable_extensions.lp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
premise(a).
premise(b).
premise(c).

contradictory(a,na).
contradictory(b,c).

strict_head(1,na).
strict_body(1,a).
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import pathlib
import unittest

from py_arg.abstract_argumentation.semantics.acceptance_strategy import \
AcceptanceStrategy
from py_arg.experiments.experiment_get_accepted_arguments import \
get_accepted_formulas_for_file

Expand All @@ -13,18 +11,31 @@ class TestASPICAcceptedArguments(unittest.TestCase):
def test_example_file(self):
file_path = str(RESOURCE_DIR / 'aspic_lp_example.lp')
py_arg_result = get_accepted_formulas_for_file(
file_path, 'democratic_last_link', 'Complete',
AcceptanceStrategy.SKEPTICAL)
file_path, 'democratic_last_link', 'Complete', 'skeptical')
self.assertEqual(py_arg_result, ['a', 'b', 'c', 'x', 'y', 'z'])

py_arg_result = get_accepted_formulas_for_file(
file_path, 'elitist_last_link', 'Complete',
AcceptanceStrategy.SKEPTICAL)
file_path, 'elitist_last_link', 'Complete', 'skeptical')
self.assertEqual(py_arg_result, ['a', 'b', 'c', 'nx', 'x', 'y', 'z'])

def test_with_support_cycle(self):
file_path = str(RESOURCE_DIR / 'aspic_support_cycle.lp')
py_arg_result = get_accepted_formulas_for_file(
file_path, 'democratic_last_link', 'Complete',
AcceptanceStrategy.SKEPTICAL)
file_path, 'democratic_last_link', 'Complete', 'skeptical')
self.assertEqual(py_arg_result, ['a', 'b', 'c'])

def test_no_stable_extensions(self):
# If there are no (stable) extensions, all arguments are skeptically
# accepted.
file_path = str(RESOURCE_DIR / 'no_stable_extensions.lp')
py_arg_result = get_accepted_formulas_for_file(
file_path, 'democratic_last_link', 'Stable', 'skeptical')
self.assertEqual(py_arg_result, ['a', 'b', 'c', 'na'])

# For complete semantics, this is no issue.
py_arg_result = get_accepted_formulas_for_file(
file_path, 'democratic_last_link', 'Complete', 'skeptical')
self.assertEqual(py_arg_result, [])
py_arg_result = get_accepted_formulas_for_file(
file_path, 'democratic_last_link', 'Complete', 'credulous')
self.assertEqual(py_arg_result, ['b', 'c'])
2 changes: 1 addition & 1 deletion src/py_arg_tests/test_af_explanations.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def test_accepted_formulas(self):
arg_framework = arg_theory.create_abstract_argumentation_framework(
'af')
extensions = get_preferred_extensions(arg_framework)
accepted_formulas = get_accepted_formulas(extensions,
accepted_formulas = get_accepted_formulas(arg_theory, extensions,
AcceptanceStrategy.CREDULOUS)

gt_accepted_formulas = [p, neg_p, q, neg_q, r, s, t, u, v]
Expand Down
6 changes: 4 additions & 2 deletions src/py_arg_visualisation/pages/22_visualise_aspic.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@ def evaluate_structured_argumentation_framework(
for frozen_extension in frozen_extensions]
acceptance_strategy = get_acceptance_strategy(
acceptance_strategy_specification)
accepted_formulas = get_accepted_formulas(extensions, acceptance_strategy)
accepted_formulas = get_accepted_formulas(arg_theory, extensions,
acceptance_strategy)

extension_buttons = []
formula_arguments = {
Expand Down Expand Up @@ -608,7 +609,8 @@ def derive_explanation_structured(
extension = [set(frozen_extension)
for frozen_extension in frozen_extensions]
acceptance_strategy = get_acceptance_strategy(strategy)
accepted = get_accepted_formulas(extension, acceptance_strategy)
accepted = get_accepted_formulas(arg_theory, extension,
acceptance_strategy)
explanations = get_str_explanations(arg_theory, semantics, ordering,
extension, accepted, function,
explanation_type, strategy, form)
Expand Down

0 comments on commit 7fb1d1b

Please sign in to comment.