Skip to content

Commit

Permalink
Made LP reader faster.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daphne Odekerken committed Nov 23, 2023
1 parent cad6a7e commit ef56572
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
3 changes: 1 addition & 2 deletions src/py_arg/experiments/experiment_run_stability_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ def get_all_literals_stability(lp_file_name: str):


if __name__ == "__main__":
get_literal_is_stable('generated_iat.lp', 'l0')
with os.scandir(r'C:\Users\Daphne\PycharmProjects\py_arg\py_arg\experiments\generated_data') as entries:
with os.scandir(r'generated_data') as entries:
for entry in entries:
filename = entry.name
st, st2, et = get_all_literals_stability(filename)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import parse

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
Expand All @@ -13,15 +11,29 @@ def __init__(self):

@staticmethod
def read_from_lp_file(file_path: str) -> IncompleteArgumentationTheory:
with open(file_path, 'r') as reader:
lines = reader.read()

positive_queryable_strs = [r[0] for r in parse.findall('queryable({})', lines)]
axiom_strs = [r[0] for r in parse.findall('axiom({})', lines)]
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)]
positive_queryable_strs = []
axiom_strs = []
defeasible_rule_bodies = []
defeasible_rule_heads = []
contradiction_pairs = []
preferred_pairs = []

reader = open(file_path, 'r')
for line in reader:
if line.startswith('queryable'):
positive_queryable_strs.append(line.split('(', 1)[1].split(')', 1)[0])
if line.startswith('axiom'):
axiom_strs.append(line.split('(', 1)[1].split(')', 1)[0])
if line.startswith('body'):
defeasible_rule_bodies.append((line.split('(', 1)[1].split(')', 1)[0]).split(', ', 1))
if line.startswith('head'):
defeasible_rule_heads.append((line.split('(', 1)[1].split(')', 1)[0]).split(', ', 1))
if line.startswith('neg'):
contradiction_pairs.append((line.split('(', 1)[1].split(')', 1)[0]).split(', ', 1))
if line.startswith('preferred'):
preferred_pairs.append((line.split('(', 1)[1].split(')', 1)[0]).split(', ', 1))
reader.close()

all_positive_literals = set(positive_queryable_strs)
for axiom in axiom_strs:
Expand Down

0 comments on commit ef56572

Please sign in to comment.