Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/DaphneOdekerken/PyArg
Browse files Browse the repository at this point in the history
…into development
  • Loading branch information
jklein94 committed Nov 2, 2023
2 parents 7054708 + 9f80000 commit cad6a7e
Show file tree
Hide file tree
Showing 28 changed files with 502 additions and 191 deletions.
2 changes: 1 addition & 1 deletion docs/aba_examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ Toni, Francesca. A tutorial on assumption-based argumentation. *Argument & Compu
aba_framework = ABAF(assumptions, rules, language, contraries)
# Get preferred extensions
extensions = get_preferred_extensions.apply(aba_framework)
extensions = get_preferred_extensions.get_preferred_extensions(aba_framework)
print(extensions)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "python-argumentation"
version = "0.0.1"
version = "2.0.0"
authors = [
{ name="Daphne Odekerken", email="[email protected]" },
{ name="AnneMarie Borg", email="[email protected]" },
Expand Down
3 changes: 2 additions & 1 deletion src/py_arg/aba_classes/aba_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from py_arg.aba_classes.instantiated_argument import InstantiatedArgument
from py_arg.aba_classes.rule import Rule
from py_arg.abstract_argumentation_classes.abstract_argumentation_framework import AbstractArgumentationFramework
from py_arg.abstract_argumentation_classes.abstract_argumentation_framework import \
AbstractArgumentationFramework
from py_arg.abstract_argumentation_classes.defeat import Defeat


Expand Down
1 change: 0 additions & 1 deletion src/py_arg/aba_classes/instantiated_argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ def __hash__(self):

def __lt__(self, other):
return self.arg_hash < other.arg_hash

12 changes: 6 additions & 6 deletions src/py_arg/aba_classes/semantics/get_admissible_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
import py_arg.algorithms.canonical_constructions.aux_operators as aux


def apply(abaf: ABAF) -> Set[FrozenSet[str]]:
af = abaf.generate_af()
def get_admissible_extensions(aba_framework: ABAF) -> Set[FrozenSet[str]]:
af = aba_framework.generate_af()

abaf_extensions = set()
for ext in aux.powerset(abaf.assumptions):
aba_framework_extensions = set()
for ext in aux.powerset(aba_framework.assumptions):
af_ext = set()
for arg in af.arguments:
if arg.premise.issubset(ext):
af_ext.add(arg)
if is_admissible_af.is_admissible(af_ext, af):
abaf_extensions.add(ext)
aba_framework_extensions.add(ext)

return abaf_extensions
return aba_framework_extensions
12 changes: 6 additions & 6 deletions src/py_arg/aba_classes/semantics/get_complete_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import py_arg.algorithms.semantics.get_complete_extensions as get_complete_extensions_af


def apply(abaf: ABAF) -> Set[FrozenSet[str]]:
af = abaf.generate_af()
def get_complete_extensions(aba_framework: ABAF) -> Set[FrozenSet[str]]:
af = aba_framework.generate_af()
af_extensions = get_complete_extensions_af.get_complete_extensions(af)
abaf_extensions = set()
aba_framework_extensions = set()
for af_ext in af_extensions:
aba_ext = set()
for arg in af_ext:
if arg.conclusion in abaf.assumptions:
if arg.conclusion in aba_framework.assumptions:
aba_ext.add(arg.conclusion)
abaf_extensions.add(frozenset(aba_ext))
aba_framework_extensions.add(frozenset(aba_ext))

return abaf_extensions
return aba_framework_extensions
14 changes: 7 additions & 7 deletions src/py_arg/aba_classes/semantics/get_conflict_free_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
import py_arg.algorithms.canonical_constructions.aux_operators as aux


def apply(abaf: ABAF) -> Set[FrozenSet[str]]:
abaf_extensions = set()
af = abaf.generate_af()
for ext in aux.powerset(abaf.assumptions):
def get_conflict_free_extensions(aba_framework: ABAF) -> Set[FrozenSet[str]]:
aba_framework_extensions = set()
af = aba_framework.generate_af()
for ext in aux.powerset(aba_framework.assumptions):
cf = True
for arg in af.arguments:
if arg.premise.issubset(ext):
for asm in ext:
if abaf.contraries[asm] == arg.conclusion:
if aba_framework.contraries[asm] == arg.conclusion:
cf = False
if cf:
abaf_extensions.add(ext)
aba_framework_extensions.add(ext)

return abaf_extensions
return aba_framework_extensions
15 changes: 0 additions & 15 deletions src/py_arg/aba_classes/semantics/get_ground_extensions.py

This file was deleted.

15 changes: 15 additions & 0 deletions src/py_arg/aba_classes/semantics/get_grounded_extensions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import Set, FrozenSet

from py_arg.aba_classes.aba_framework import ABAF
import py_arg.algorithms.semantics.get_grounded_extension as get_grounded_extensions_af


def get_preferred_extensions(aba_framework: ABAF) -> Set[FrozenSet[str]]:
af = aba_framework.generate_af()
af_extension = get_grounded_extensions_af.get_grounded_extension(af)
aba_framework_extensions = set()
for arg in af_extension:
if arg.conclusion in aba_framework.assumptions:
aba_framework_extensions.add(arg.conclusion)

return {frozenset(aba_framework_extensions)}
4 changes: 2 additions & 2 deletions src/py_arg/aba_classes/semantics/get_naive_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import py_arg.aba_classes.semantics.get_conflict_free_extensions as get_conflict_free_extensions


def apply(abaf: ABAF) -> Set[FrozenSet[str]]:
cf_ext = get_conflict_free_extensions.apply(abaf)
def get_naive_extensions(aba_framework: ABAF) -> Set[FrozenSet[str]]:
cf_ext = get_conflict_free_extensions.get_conflict_free_extensions(aba_framework)
rm = set()
for ext1 in cf_ext:
for ext2 in cf_ext:
Expand Down
6 changes: 3 additions & 3 deletions src/py_arg/aba_classes/semantics/get_preferred_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import py_arg.algorithms.semantics.get_preferred_extensions as get_preferred_extensions_af


def apply(abaf: ABAF) -> Set[FrozenSet[str]]:
af = abaf.generate_af()
def get_preferred_extensions(aba_framework: ABAF) -> Set[FrozenSet[str]]:
af = aba_framework.generate_af()
af_extensions = get_preferred_extensions_af.get_preferred_extensions(af)
abaf_extensions = set()
for af_ext in af_extensions:
aba_ext = set()
for arg in af_ext:
if arg.conclusion in abaf.assumptions:
if arg.conclusion in aba_framework.assumptions:
aba_ext.add(arg.conclusion)
abaf_extensions.add(frozenset(aba_ext))

Expand Down
19 changes: 9 additions & 10 deletions src/py_arg/aba_classes/semantics/get_semi_stable_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,24 @@
# We thank Anh Kiet Nguyen for pointing out that semi-stable assumption extensions
# cannot in general be attained from the instantiated af.
# cf. 'ON THE DIFFERENCE BETWEEN ASSUMPTION-BASED ARGUMENTATION AND ABSTRACT ARGUMENTATION'
def apply(abaf: ABAF) -> Set[FrozenSet[str]]:
af = abaf.generate_af()
com_ext = get_complete_extensions.apply(abaf)
def get_semi_stable_extensions(aba_framework: ABAF) -> Set[FrozenSet[str]]:
af = aba_framework.generate_af()
com_ext = get_complete_extensions.get_complete_extensions(aba_framework)
extension_reach = {}
for ext in com_ext:
extension_reach[ext] = set(ext.copy())
for arg in af.arguments:
if arg.premise.issubset(ext):
if arg.conclusion not in abaf.assumptions:
extension_reach[ext].add(
list(abaf.contraries.keys())[list(abaf.contraries.values()).index(arg.conclusion)])
if arg.premise.issubset(ext) and arg.conclusion not in aba_framework.assumptions:
conclusion_index = list(aba_framework.contraries.values()).index(arg.conclusion)
extension_reach[ext].add(list(aba_framework.contraries.keys())[conclusion_index])
ss_ext = set()
for ext1 in com_ext:
is_semistable = True
is_semi_stable = True
for ext2 in com_ext:
if extension_reach[ext1].issubset(extension_reach[ext2]) and \
not extension_reach[ext2].issubset(extension_reach[ext1]):
is_semistable = False
if is_semistable:
is_semi_stable = False
if is_semi_stable:
ss_ext.add(ext1)

return ss_ext
12 changes: 6 additions & 6 deletions src/py_arg/aba_classes/semantics/get_stable_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import py_arg.algorithms.semantics.get_stable_extensions as get_stable_extensions_af


def apply(abaf: ABAF) -> Set[FrozenSet[str]]:
af = abaf.generate_af()
def get_stable_extensions(aba_framework: ABAF) -> Set[FrozenSet[str]]:
af = aba_framework.generate_af()
af_extensions = get_stable_extensions_af.get_stable_extensions(af)
abaf_extensions = set()
aba_framework_extensions = set()
for af_ext in af_extensions:
aba_ext = set()
for arg in af_ext:
if arg.conclusion in abaf.assumptions:
if arg.conclusion in aba_framework.assumptions:
aba_ext.add(arg.conclusion)
abaf_extensions.add(frozenset(aba_ext))
aba_framework_extensions.add(frozenset(aba_ext))

return abaf_extensions
return aba_framework_extensions
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ def __init__(self, name: str = '',
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) + \
'], [' + ', '.join(defeat.__repr__() for defeat in self.defeats) + '] )'

def __eq__(self, other):
return isinstance(other, AbstractArgumentationFramework) and \
self.name == other.name and \
self.arguments == other.arguments and \
self.defeats == other.defeats

def get_incoming_defeat_arguments(self, argument: Argument) -> List[Argument]:
"""
Get a list of arguments that defeat this argument.
Expand Down
7 changes: 7 additions & 0 deletions src/py_arg/abstract_argumentation_classes/defeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ def __init__(self, from_argument: Argument, to_argument: Argument):
def __str__(self):
return str(self.from_argument) + ' defeats ' + str(self.to_argument)

def __lt__(self, other):
return self.from_argument < other.from_argument or self.from_argument == other.from_argument and \
self.to_argument < other.to_argument

def __repr__(self):
return '(' + str(self.from_argument) + ', ' + str(self.to_argument) + ')'

def __eq__(self, other):
return self.from_argument == other.from_argument and self.to_argument == other.to_argument

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ def instantiate_incomplete_argumentation_theory_generator(nr_of_literals, nr_of_
), topics


# literal_sizes = [50, 100, 150, 200, 250, 500, 1000, 2500]
literal_sizes = [60, 70, 80, 90]
literal_sizes = [20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]
rule_literal_ratios = [0.5, 1, 1.5]

for literal_size in literal_sizes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
IncompleteArgumentationTheoryGenerator


def instantiate_incomplete_argumentation_theory_generator():
nr_of_literals = 10000
nr_of_rules = 15000
def instantiate_incomplete_argumentation_theory_generator(nr_of_literals, nr_of_rules):
rule_antecedent_distribution = {1: int(nr_of_rules / 3),
2: int(nr_of_rules / 3),
3: int(nr_of_rules / 9),
Expand Down Expand Up @@ -42,7 +40,9 @@ def instantiate_incomplete_argumentation_theory_generator():
)


generator = instantiate_incomplete_argumentation_theory_generator()
iaf = generator.generate()
i = 0

if __name__ == "__main__":
for nr_of_literals in [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]:
for nr_of_rules in [nr_of_literals / 2, nr_of_literals, 3 * nr_of_literals / 2]:
generator = instantiate_incomplete_argumentation_theory_generator(nr_of_literals, nr_of_rules)
for instance in range(50):
iaf = generator.generate()
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from py_arg.aspic_classes.argumentation_system import ArgumentationSystem
from py_arg.aspic_classes.defeasible_rule import DefeasibleRule
from py_arg.aspic_classes.literal import Literal
from py_arg.aspic_classes.orderings.preference_preorder import PreferencePreorder
from py_arg.incomplete_aspic_classes.incomplete_argumentation_theory import IncompleteArgumentationTheory


Expand All @@ -20,6 +21,7 @@ def read_from_lp_file(file_path: str) -> IncompleteArgumentationTheory:
defeasible_rule_bodies = [(r[0], r[1]) for r in parse.findall('body({}, {})', lines)]
defeasible_rule_heads = [(r[0], r[1]) for r in parse.findall('head({}, {})', lines)]
contradiction_pairs = [(r[0], r[1]) for r in parse.findall('neg({}, {})', lines)]
preferred_pairs = [(r[0], r[1]) for r in parse.findall('preferred({}, {})', lines)]

all_positive_literals = set(positive_queryable_strs)
for axiom in axiom_strs:
Expand Down Expand Up @@ -48,11 +50,22 @@ def read_from_lp_file(file_path: str) -> IncompleteArgumentationTheory:
language[rule_head])
defeasible_rules.append(defeasible_rule)

argumentation_system = ArgumentationSystem(language, contraries_and_contradictories, [], defeasible_rules,
add_defeasible_rule_literals=False)
def_rules_lookup = {defeasible_rule.id: defeasible_rule for defeasible_rule in defeasible_rules}
preference_preorder = PreferencePreorder(
[(def_rules_lookup[rule_a], def_rules_lookup[rule_b])
for rule_a, rule_b in preferred_pairs])

argumentation_system = ArgumentationSystem(
language=language, contraries_and_contradictories=contraries_and_contradictories,
strict_rules=[], defeasible_rules=defeasible_rules,
defeasible_rule_preferences=preference_preorder, add_defeasible_rule_literals=False)

negative_queryable_strs = ['-' + queryable for queryable in positive_queryable_strs]
queryables = [language[queryable] for queryable in positive_queryable_strs + negative_queryable_strs]
knowledge_base_axioms = [language[axiom_str] for axiom_str in axiom_strs]

return IncompleteArgumentationTheory(argumentation_system, queryables, knowledge_base_axioms, [])
return IncompleteArgumentationTheory(
argumentation_system=argumentation_system, queryables=queryables,
knowledge_base_axioms=knowledge_base_axioms, knowledge_base_ordinary_premises=[],
ordinary_premise_preferences=None
)
Loading

0 comments on commit cad6a7e

Please sign in to comment.