@tuprolog/arg2p-core 0.6.2 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -108,6 +108,7 @@
108
108
  var Random = Kotlin.kotlin.random.Random;
109
109
  var toTerm = $module$_2p_core.it.unibo.tuprolog.core.listToTerm;
110
110
  var UnaryPredicate$WithoutSideEffects = $module$_2p_solve.it.unibo.tuprolog.solve.primitive.UnaryPredicate.WithoutSideEffects;
111
+ var BinaryRelation$WithoutSideEffects = $module$_2p_solve.it.unibo.tuprolog.solve.primitive.BinaryRelation.WithoutSideEffects;
111
112
  var copyToArray = Kotlin.kotlin.collections.copyToArray;
112
113
  var AliasedLibrary = $module$_2p_solve.it.unibo.tuprolog.solve.library.AliasedLibrary;
113
114
  var compareBy = Kotlin.kotlin.comparisons.compareBy_bvgy4j$;
@@ -167,6 +168,8 @@
167
168
  DefeasibleRules.prototype.constructor = DefeasibleRules;
168
169
  Bps.prototype = Object.create(UnaryPredicate$WithoutSideEffects.prototype);
169
170
  Bps.prototype.constructor = Bps;
171
+ ExtractStrictIds.prototype = Object.create(BinaryRelation$WithoutSideEffects.prototype);
172
+ ExtractStrictIds.prototype.constructor = ExtractStrictIds;
170
173
  StructuredModeBase.prototype = Object.create(LazyRawPrologContent.prototype);
171
174
  StructuredModeBase.prototype.constructor = StructuredModeBase;
172
175
  DebugBase.prototype = Object.create(LazyRawPrologContent.prototype);
@@ -3077,7 +3080,9 @@
3077
3080
  return $receiver.descriptionPair;
3078
3081
  }.bind(null, Premises_getInstance())).get(), getPropertyCallableRef('descriptionPair', 0, function ($receiver) {
3079
3082
  return $receiver.descriptionPair;
3080
- }.bind(null, DefeasibleRules_getInstance())).get()]), this.prologTheory, RuleParserBase$Companion_getInstance().operators());
3083
+ }.bind(null, DefeasibleRules_getInstance())).get(), getPropertyCallableRef('descriptionPair', 0, function ($receiver) {
3084
+ return $receiver.descriptionPair;
3085
+ }.bind(null, ExtractStrictIds_getInstance())).get()]), this.prologTheory, RuleParserBase$Companion_getInstance().operators());
3081
3086
  }
3082
3087
  });
3083
3088
  Object.defineProperty(RuleParserBase.prototype, 'baseFlags', {
@@ -3414,6 +3419,35 @@
3414
3419
  new Bps();
3415
3420
  }return Bps_instance;
3416
3421
  }
3422
+ function ExtractStrictIds() {
3423
+ ExtractStrictIds_instance = this;
3424
+ BinaryRelation$WithoutSideEffects.call(this, 'extract_id');
3425
+ }
3426
+ ExtractStrictIds.prototype.computeAllSubstitutions_2j1e5m$ = function ($receiver, first, second) {
3427
+ var tmp$ = Substitution.Companion;
3428
+ var tmp$_0 = ensureNotNull(second.asVar());
3429
+ var tmp$_1 = List.Companion;
3430
+ var $receiver_0 = ensureNotNull(first.asList()).toList();
3431
+ var destination = ArrayList_init(collectionSizeOrDefault($receiver_0, 10));
3432
+ var tmp$_2;
3433
+ tmp$_2 = $receiver_0.iterator();
3434
+ while (tmp$_2.hasNext()) {
3435
+ var item = tmp$_2.next();
3436
+ destination.add_11rb$(Struct.Companion.of('strict', [ensureNotNull(item.asCons()).head]));
3437
+ }
3438
+ return sequenceOf([tmp$.of(tmp$_0, tmp$_1.ofList(destination))]);
3439
+ };
3440
+ ExtractStrictIds.$metadata$ = {
3441
+ kind: Kind_OBJECT,
3442
+ simpleName: 'ExtractStrictIds',
3443
+ interfaces: [BinaryRelation$WithoutSideEffects]
3444
+ };
3445
+ var ExtractStrictIds_instance = null;
3446
+ function ExtractStrictIds_getInstance() {
3447
+ if (ExtractStrictIds_instance === null) {
3448
+ new ExtractStrictIds();
3449
+ }return ExtractStrictIds_instance;
3450
+ }
3417
3451
  function StructuredModeBase() {
3418
3452
  LazyRawPrologContent.call(this);
3419
3453
  this.alias_k0m5up$_0 = 'prolog.argumentation.structured';
@@ -3631,7 +3665,11 @@
3631
3665
  Object.defineProperty(UtilsBase.prototype, 'baseContent', {
3632
3666
  configurable: true,
3633
3667
  get: function () {
3634
- return Library.Companion.aliased(this.alias, void 0, this.prologTheory);
3668
+ var tmp$, tmp$_0, tmp$_1;
3669
+ tmp$_1 = Library.Companion;
3670
+ tmp$ = this.alias;
3671
+ tmp$_0 = this.prologTheory;
3672
+ return tmp$_1.aliased(tmp$, mapOf_0([to(AppendOptimized_getInstance().signature, AppendOptimized_getInstance()), to(AssertAll_getInstance().signature, AssertAll_getInstance())]), tmp$_0);
3635
3673
  }
3636
3674
  });
3637
3675
  Object.defineProperty(UtilsBase.prototype, 'baseFlags', {
@@ -3654,6 +3692,172 @@
3654
3692
  simpleName: 'UtilsBase',
3655
3693
  interfaces: [Loadable, LazyRawPrologContent, ArgLibrary]
3656
3694
  };
3695
+ function AppendOptimized() {
3696
+ AppendOptimized_instance = this;
3697
+ this.signature = new Signature('append_fast', 3);
3698
+ }
3699
+ function Coroutine$AppendOptimized$solve$lambda(closure$request_0, closure$res_0, closure$list1_0, closure$list2_0, $receiver_0, controller, continuation_0) {
3700
+ CoroutineImpl.call(this, continuation_0);
3701
+ this.$controller = controller;
3702
+ this.exceptionState_0 = 1;
3703
+ this.local$closure$request = closure$request_0;
3704
+ this.local$closure$res = closure$res_0;
3705
+ this.local$closure$list1 = closure$list1_0;
3706
+ this.local$closure$list2 = closure$list2_0;
3707
+ this.local$$receiver = $receiver_0;
3708
+ }
3709
+ Coroutine$AppendOptimized$solve$lambda.$metadata$ = {
3710
+ kind: Kotlin.Kind.CLASS,
3711
+ simpleName: null,
3712
+ interfaces: [CoroutineImpl]
3713
+ };
3714
+ Coroutine$AppendOptimized$solve$lambda.prototype = Object.create(CoroutineImpl.prototype);
3715
+ Coroutine$AppendOptimized$solve$lambda.prototype.constructor = Coroutine$AppendOptimized$solve$lambda;
3716
+ Coroutine$AppendOptimized$solve$lambda.prototype.doResume = function () {
3717
+ do
3718
+ try {
3719
+ switch (this.state_0) {
3720
+ case 0:
3721
+ this.state_0 = 2;
3722
+ this.result_0 = this.local$$receiver.yield_11rb$(this.local$closure$request.replyWith(Substitution.Companion.of(this.local$closure$res, List.Companion.ofList(plus(this.local$closure$list1.toList(), this.local$closure$list2.toList()))), void 0, []), this);
3723
+ if (this.result_0 === COROUTINE_SUSPENDED)
3724
+ return COROUTINE_SUSPENDED;
3725
+ continue;
3726
+ case 1:
3727
+ throw this.exception_0;
3728
+ case 2:
3729
+ return this.result_0;
3730
+ default:this.state_0 = 1;
3731
+ throw new Error('State Machine Unreachable execution');
3732
+ }
3733
+ } catch (e) {
3734
+ if (this.state_0 === 1) {
3735
+ this.exceptionState_0 = this.state_0;
3736
+ throw e;
3737
+ } else {
3738
+ this.state_0 = this.exceptionState_0;
3739
+ this.exception_0 = e;
3740
+ }
3741
+ }
3742
+ while (true);
3743
+ };
3744
+ function AppendOptimized$solve$lambda(closure$request_0, closure$res_0, closure$list1_0, closure$list2_0) {
3745
+ return function ($receiver_0, continuation_0, suspended) {
3746
+ var instance = new Coroutine$AppendOptimized$solve$lambda(closure$request_0, closure$res_0, closure$list1_0, closure$list2_0, $receiver_0, this, continuation_0);
3747
+ if (suspended)
3748
+ return instance;
3749
+ else
3750
+ return instance.doResume(null);
3751
+ };
3752
+ }
3753
+ AppendOptimized.prototype.solve = function (request) {
3754
+ var list1 = request.arguments.get_za3lpa$(0);
3755
+ var list2 = request.arguments.get_za3lpa$(1);
3756
+ var res = request.arguments.get_za3lpa$(2);
3757
+ if (!Kotlin.isType(list1, List)) {
3758
+ throw TypeError.Companion.forGoal(request.context, request.signature, TypeError$Expected.LIST, list1);
3759
+ }if (!Kotlin.isType(list2, List)) {
3760
+ throw TypeError.Companion.forGoal(request.context, request.signature, TypeError$Expected.LIST, list2);
3761
+ }if (!Kotlin.isType(res, Var)) {
3762
+ throw TypeError.Companion.forGoal(request.context, request.signature, TypeError$Expected.VARIABLE, res);
3763
+ }return sequence(AppendOptimized$solve$lambda(request, res, list1, list2));
3764
+ };
3765
+ AppendOptimized.$metadata$ = {
3766
+ kind: Kind_OBJECT,
3767
+ simpleName: 'AppendOptimized',
3768
+ interfaces: [Primitive]
3769
+ };
3770
+ var AppendOptimized_instance = null;
3771
+ function AppendOptimized_getInstance() {
3772
+ if (AppendOptimized_instance === null) {
3773
+ new AppendOptimized();
3774
+ }return AppendOptimized_instance;
3775
+ }
3776
+ function AssertAll() {
3777
+ AssertAll_instance = this;
3778
+ this.signature = new Signature('assert_all', 1);
3779
+ }
3780
+ function AssertAll$solve$lambda(closure$list, closure$request) {
3781
+ return function ($receiver) {
3782
+ var $receiver_0 = closure$list.toSequence();
3783
+ var tmp$;
3784
+ tmp$ = $receiver_0.iterator();
3785
+ while (tmp$.hasNext()) {
3786
+ var element = tmp$.next();
3787
+ first(closure$request.solve($receiver.stringInvoke('context_assert', element, [])));
3788
+ }
3789
+ return Unit;
3790
+ };
3791
+ }
3792
+ function Coroutine$AssertAll$solve$lambda(closure$request_0, $receiver_0, controller, continuation_0) {
3793
+ CoroutineImpl.call(this, continuation_0);
3794
+ this.$controller = controller;
3795
+ this.exceptionState_0 = 1;
3796
+ this.local$closure$request = closure$request_0;
3797
+ this.local$$receiver = $receiver_0;
3798
+ }
3799
+ Coroutine$AssertAll$solve$lambda.$metadata$ = {
3800
+ kind: Kotlin.Kind.CLASS,
3801
+ simpleName: null,
3802
+ interfaces: [CoroutineImpl]
3803
+ };
3804
+ Coroutine$AssertAll$solve$lambda.prototype = Object.create(CoroutineImpl.prototype);
3805
+ Coroutine$AssertAll$solve$lambda.prototype.constructor = Coroutine$AssertAll$solve$lambda;
3806
+ Coroutine$AssertAll$solve$lambda.prototype.doResume = function () {
3807
+ do
3808
+ try {
3809
+ switch (this.state_0) {
3810
+ case 0:
3811
+ this.state_0 = 2;
3812
+ this.result_0 = this.local$$receiver.yield_11rb$(this.local$closure$request.replyWithCondition(true, void 0, []), this);
3813
+ if (this.result_0 === COROUTINE_SUSPENDED)
3814
+ return COROUTINE_SUSPENDED;
3815
+ continue;
3816
+ case 1:
3817
+ throw this.exception_0;
3818
+ case 2:
3819
+ return this.result_0;
3820
+ default:this.state_0 = 1;
3821
+ throw new Error('State Machine Unreachable execution');
3822
+ }
3823
+ } catch (e) {
3824
+ if (this.state_0 === 1) {
3825
+ this.exceptionState_0 = this.state_0;
3826
+ throw e;
3827
+ } else {
3828
+ this.state_0 = this.exceptionState_0;
3829
+ this.exception_0 = e;
3830
+ }
3831
+ }
3832
+ while (true);
3833
+ };
3834
+ function AssertAll$solve$lambda_0(closure$request_0) {
3835
+ return function ($receiver_0, continuation_0, suspended) {
3836
+ var instance = new Coroutine$AssertAll$solve$lambda(closure$request_0, $receiver_0, this, continuation_0);
3837
+ if (suspended)
3838
+ return instance;
3839
+ else
3840
+ return instance.doResume(null);
3841
+ };
3842
+ }
3843
+ AssertAll.prototype.solve = function (request) {
3844
+ var list = request.arguments.get_za3lpa$(0);
3845
+ if (!Kotlin.isType(list, List)) {
3846
+ throw TypeError.Companion.forGoal(request.context, request.signature, TypeError$Expected.LIST, list);
3847
+ }arg2pScope(AssertAll$solve$lambda(list, request));
3848
+ return sequence(AssertAll$solve$lambda_0(request));
3849
+ };
3850
+ AssertAll.$metadata$ = {
3851
+ kind: Kind_OBJECT,
3852
+ simpleName: 'AssertAll',
3853
+ interfaces: [Primitive]
3854
+ };
3855
+ var AssertAll_instance = null;
3856
+ function AssertAll_getInstance() {
3857
+ if (AssertAll_instance === null) {
3858
+ new AssertAll();
3859
+ }return AssertAll_instance;
3860
+ }
3657
3861
  function MetaInterpreterLib() {
3658
3862
  MetaInterpreterLib_instance = this;
3659
3863
  this.$delegate_3wovwi$_0 = Library.Companion.aliased('prolog.argumentation.meta', void 0, parse_2(Theory.Companion, trimIndent('\n % with_facts_and_length/3\n with_facts_and_length(X, Y, L) :-\n solve(X, R),\n recover_facts(R, Y),\n length(Y, L).\n\n % lenght/2\n\n length([], 0).\n length([_|T], X) :- length(T, Y), X is Y + 1.\n\n % recover_facts/2\n\n recover_facts([], []) :- !.\n recover_facts([H|T], C) :-\n is_list(H), !,\n recover_facts(T, TC),\n recover_facts(H, HC),\n append(TC, HC, C).\n recover_facts([H|T], C) :-\n \\+ is_list(H),\n recover_facts(T, TC),\n evaluate(H, HC),\n append(TC, HC, C).\n\n evaluate(user_fact(X), [X]) :- !.\n evaluate(_, []) :- !.\n\n % solve/2\n\n solve((A,B), Result) :- !,\n solve(A, ARes),\n solve(B, BRes),\n append(ARes, BRes, Result).\n\n solve((A;B), Result) :- !,\n solve(A, Result);\n solve(B, Result).\n\n solve(member(A, B), [system_predicate]) :- !,\n call(member(A, B)).\n\n solve(\\+(A), [not(A)]) :- !,\n call(\\+(A)).\n\n solve((A)\\=(B), [doNotUnify(A, B)]) :- !,\n call((A)\\=(B)).\n\n solve(A, [system_predicate]) :-\n catch(clause(A, _), B, true),\n \\+ var(B), !,\n call(A).\n\n solve(A, [A]) :-\n \\+ clause(A, B), !,\n call(A).\n\n solve(A, [A|[Res]]) :-\n clause(A, B),\n solve(B, Res).\n\n % is_list/1\n\n is_list(X) :- var(X), !, fail.\n is_list([]).\n is_list([_|T]) :- is_list(T).\n \n % fetch_argument_facts/2\n \n fetch_argument_facts(Conclusion, Facts) :-\n argument([R, TR, [Conclusion]]),\n findall(user_fact(Fact), \n support([_, _, [user_fact(Fact)]], [R, TR, [Conclusion]]),\n Facts).\n ')));
@@ -4876,7 +5080,7 @@
4876
5080
  }
4877
5081
  function RuleTranslator() {
4878
5082
  RuleTranslator_instance = this;
4879
- this.theoryCode = trimIndent("\n /*\n * Main directive. Find all the rules in the theory in the format (Name : Preconditions => Conclusion)\n * or (Name : Effects) and then if:\n * - It is a standard rule, translate it in the standard format (rule([Name, Preconditions, Conclusions]));\n * - It is a bp rule, translate it to (abstractBp([Effects]))\n * During the process, clean them from the unallowed symbols (-, o, p).\n */\n convertAllRules(ArgRules) :-\n defeasibleRules(DefeasibleRules),\n strictRules(StrictRules, RulesIds),\n ordinaryPremises(Premises),\n axiomPremises(Axioms, AxiomsIds),\n specialRules(SpecialRules),\n utils::appendLists([DefeasibleRules, StrictRules, Premises, Axioms, SpecialRules], L),\n convertAllRules(L, Rules),\n findall(sup(X, Y), sup(X, Y), Sups),\n utils::appendLists([Rules, AxiomsIds, RulesIds, Sups], ArgRules),\n findall(_, (member(X, ArgRules), context_assert(X)), _), !.\n defeasibleRules(DefeasibleRules) :-\n findall([RuleName, Preconditions, Effect], (RuleName : Preconditions => Effect), DefeasibleRulesOld),\n prologDefeasibleRules(DefeasibleRulesNew),\n append(DefeasibleRulesOld, DefeasibleRulesNew, DefeasibleRules).\n strictRules(CtrRules, Ids) :-\n findall([RuleName, Preconditions, Effect], (RuleName : Preconditions -> Effect), StrictRulesOld),\n prologStrictRules(StrictRulesNew),\n append(StrictRulesOld, StrictRulesNew, StrictRules),\n transpose(StrictRules, StrictRules, CtrRules),\n findall(strict(RN), member([RN, _, _], CtrRules), Ids).\n ordinaryPremises(Premises) :-\n findall([RuleName, Effect], ((RuleName :=> Effect), atom(RuleName)), PremisesOld),\n prologPremises(PremisesNew),\n append(PremisesOld, PremisesNew, Premises).\n axiomPremises(Axioms, Ids) :-\n findall([RuleName, Effect], ((RuleName :-> Effect), atom(RuleName)), AxiomsOld),\n prologAxioms(AxiomsNew),\n append(AxiomsOld, AxiomsNew, Axioms),\n findall(strict(RN), member([RN, _], Axioms), Ids).\n specialRules(SpecialRules) :-\n bpsNew(SpecialRules).\n transpose(_, CtrRules, CtrRules) :- \\+ autoTransposition, !.\n transpose([], CtrRules, CtrRules).\n transpose([H|T], TempCtrRules, CtrRules) :-\n transpose(T, TempCtrRules, CR),\n findall(TrH, transposition(H, TrH), Tran),\n mergeCtrRules(CR, Tran, CtrRules).\n mergeCtrRules(All, ToMerge, X) :-\n append(All, ToMerge, XT),\n deduplicate(XT, X).\n deduplicate([], []).\n deduplicate([[RN,A,B]|T], X) :- deduplicate(T, TT), (member([RN,_,_], TT) -> X = TT; X = [[RN,A,B]|TT]). \n transposition([Id, Prec, Effect], [Id, Prec, Effect]).\n transposition([Id, Prec, Effect], [NewId, NewPrec ,XNegated]) :-\n compound(Prec),\n tuple_to_list(Prec, LPrec),!,\n transposition_sequential(LPrec, LPrec, Effect, Id, [], NewPrec, XNegated, NewId).\n transposition([Id, Prec, Effect], [NewId, EffectNegated ,XNegated]) :-\n \\+ compound(Prec),\n Prec \\== [],\n prologEscape(Prec),\n negate(Prec, XNegated),\n negate(Effect, EffectNegated),\n atom_concat(Id, '_i', NewId).\n transposition_sequential(LPrec, [H|T], Effect, Id, Skipped, NewPrec, XNegated, NewId) :-\n transposition_sequential(LPrec, T, Effect, Id, [H|Skipped], NewPrec, XNegated, NewId).\n transposition_sequential(LPrec, [X|T], Effect, Id, Skipped, NewPrec, XNegated, NewId) :-\n prologEscape(X),\n append(Skipped, T, CleanedPrec),\n negate(X, XNegated),\n negate(Effect, EffectNegated),\n list_to_tuple([EffectNegated|CleanedPrec], NewPrec),\n newIdentifier(Skipped, Id, NewId).\n newIdentifier(List, OldId, NewId) :-\n modifier(List, Mod),\n atom_concat(OldId, Mod, NewId).\n modifier([], '_i').\n modifier([_|Tail], Index):-\n modifier(Tail, Index1),\n atom_concat(Index1, 'i', Index).\n negate(X, Arg) :-\n functor(X, '-', _) -> (\n arg(1, X, Arg));\n functor(X, 'p', _) -> (\n arg(1, X, PX),\n (functor(PX, '-', _) -> (\n arg(1, PX, PNX),\n Arg = o(PNX)\n );\n Arg = o(-(PX))));\n Arg = -(X).\n prologEscape(X) :- \\+ functor(X, 'prolog', _), \\+ functor(X, '~', _).\n /*\n * Standard rules (RuleName : Preconditions => Effects)\n * Special rules (RuleName : Effects)\n */\n convertAllRules([], []).\n convertAllRules([[H,P,E]|T], [R|Rules]) :- convertRule(H, P, E, R), convertAllRules(T, Rules).\n convertAllRules([[H,E]|T], [R|Rules]) :- convertRule(H, E, R), convertAllRules(T, Rules).\n /*\n * Convert the given rule to the standard format\n * Example:\n * r2: followedGuidelines(X), doctor(X) => -liable(X)\n * rule([r2,[[followedGuidelines(X_e4149)],[doctor(X_e4149)]],[neg,liable(X_e4149)]]).\n */\n convertRule(RuleName, Preconditions, Effects, rule(List)) :-\n tuple_to_list(Preconditions, Lprecond),\n tuple_to_list(Effects, Leffects),\n check_modifiers_in_list(preconditions, Lprecond, LprecondChecked),\n check_modifiers_in_list(effects, Leffects, LeffectsChecked),\n flatten_first_level(LeffectsChecked, LeffectsCheckedFlattened),\n List = [RuleName, LprecondChecked, LeffectsCheckedFlattened], !.\n /*\n * Convert the given special rule\n * Example:\n * bp(-liable(X)).\n * abastractBp([[neg, liable(X_e4149)]]).\n */\n convertRule(bps, Effects, abstractBp(Checked)) :-\n functor(Effects, 'bp', _),\n Effects =.. L,\n removehead(L, LC),\n check_modifiers_in_list(effects, LC, Checked), !.\n convertRule(Name, Effects, premise([Name, LeffectsCheckedFlattened])) :-\n tuple_to_list(Effects, Leffects),\n check_modifiers_in_list(effects, Leffects, LeffectsChecked),\n flatten_first_level(LeffectsChecked, LeffectsCheckedFlattened).\n /*\n * Find negations(-), obligations(o), permissions(p) on a list of preconditions/effects and\n * raplace them with the assigned literal (neg, obl, perm)\n */\n check_modifiers_in_list(MODE, [], []) :- !.\n check_modifiers_in_list(MODE, [H|T], L) :- H == [], L = [], !.\n check_modifiers_in_list(MODE, [H|T], L) :- H \\== [],\n check_modifiers_once(H, LH),\n check_modifiers_in_list(MODE, T, LT),\n append([LH], LT, L).\n check_modifiers_once(H, List) :- once(check_modifiers(H, List)).\n check_modifiers([], []).\n check_modifiers(H, List) :-\n functor(H, '-', _) -> (\n arg(1, H, Arg),\n check_modifiers_once(Arg, Lobl),\n append([neg], Lobl, Lf),\n List = Lf);\n functor(H, 'o', _) -> (\n arg(1, H, Arg),\n check_modifiers_once(Arg, Lobl),\n List = [obl|[Lobl]]);\n functor(H, 'p', _) -> (\n arg(1, H, Arg),\n check_modifiers_once(Arg, Lper),\n List = [perm|[Lper]]);\n functor(H, '~', _) -> (\n arg(1, H, Arg),\n check_modifiers_once(Arg, Lper),\n List = [unless|[Lper]]);\n functor(H, 'bp', _) -> (\n H =.. [_|Arg],\n check_modifiers_in_list(effects, Arg, Lper),\n List = [bp|[Lper]]);\n List = [H].\n /*\n * Convert the given tuple to list\n */\n tuple_to_list(A,[A]) :- nonvar(A), A \\= (_ , _), !.\n tuple_to_list((A,B),L) :-\n tuple_to_list(A, La),\n tuple_to_list(B, Lb),\n append(La, Lb,L).\n list_to_tuple([H], (H)) :- !.\n list_to_tuple([H|T], (H,TT)) :- list_to_tuple(T,TT).\n /*\n * Replace all the occurences of a given element with the given argument\n */\n replace(_, _, [],[]) :- !.\n replace(O, R, [O|T], [R|T2]) :- replace(O, R, T, T2), !.\n replace(O, R, [H|T], [H|T2]) :- H \\= O, replace(O, R, T, T2).\n flatten_first_level([X], X) :- !.\n flatten_first_level.\n removehead([_|Tail], Tail).\n in(A, A) :- nonvar(A), A \\= (_ , _), !.\n in(A, (A, _)) :- !.\n in(A, (_ , Cs)) :- in(A, Cs).\n check_admissibility(preconditions, H, LH) :-\n \\+ defeasible_admissible(LH),\n throw(['Premise ', H, ' is not a well formed member of the argumentation language.']).\n check_admissibility(effects, H, LH) :-\n \\+ admissible(LH),\n throw(['Conclusion ', H, ' is not a well formed member of the argumentation language.']).\n check_admissibility(_, _, _).\n defeasible_admissible([unless, Term]) :- admissible(Term).\n defeasible_admissible(Term) :- admissible(Term).\n admissible([neg, bp, Term]) :- admissible_terms_complete(Term).\n admissible([bp, Term]) :- admissible_terms_complete(Term).\n admissible([neg, Term]) :- admissible_term(Term).\n admissible([obl, [Term]]) :- admissible_term(Term).\n admissible([obl, [neg, Term]]) :- admissible_term(Term).\n admissible([neg, obl, [Term]]) :- admissible_term(Term).\n admissible([neg, obl, [neg, Term]]) :- admissible_term(Term).\n admissible([perm, [Term]]) :- admissible_term(Term).\n admissible([perm, [neg, Term]]) :- admissible_term(Term).\n admissible([Term]) :- admissible_term(Term).\n admissible_term(Term) :-\n atomic(Term),\n Term \\== neg,\n Term \\== obl,\n Term \\== perm,\n Term \\== unless,\n Term \\== bp.\n admissible_term(Term) :- var(Term).\n admissible_term(Term) :-\n compound(Term),\n \\+ functor(Term, 'o', _),\n \\+ functor(Term, 'p', _),\n \\+ functor(Term, '-', _),\n \\+ functor(Term, '~', _),\n \\+ functor(Term, 'bp', _),\n Term =.. [_|Args],\n admissible_terms(Args).\n admissible_terms([]).\n admissible_terms([H|T]) :-\n admissible_term(H),\n admissible_terms(T).\n admissible_terms_complete([]).\n admissible_terms_complete([H|T]) :-\n admissible(H),\n admissible_terms_complete(T).\n ");
5083
+ this.theoryCode = trimIndent("\n /*\n * Main directive. Find all the rules in the theory in the format (Name : Preconditions => Conclusion)\n * or (Name : Effects) and then if:\n * - It is a standard rule, translate it in the standard format (rule([Name, Preconditions, Conclusions]));\n * - It is a bp rule, translate it to (abstractBp([Effects]))\n * During the process, clean them from the unallowed symbols (-, o, p).\n */\n convertAllRules(ArgRules) :-\n defeasibleRules(DefeasibleRules),\n strictRules(StrictRules, RulesIds),\n ordinaryPremises(Premises),\n axiomPremises(Axioms, AxiomsIds),\n specialRules(SpecialRules),\n utils::appendLists([DefeasibleRules, StrictRules, Premises, Axioms, SpecialRules], L),\n convertAllRules(L, Rules),\n findall(sup(X, Y), sup(X, Y), Sup),\n utils::appendLists([Rules, AxiomsIds, RulesIds, Sup], ArgRules),\n utils::assert_all(ArgRules), !.\n defeasibleRules(DefeasibleRules) :-\n findall([RuleName, Preconditions, Effect], (RuleName : Preconditions => Effect), DefeasibleRulesOld),\n prologDefeasibleRules(DefeasibleRulesNew),\n utils::append_fast(DefeasibleRulesOld, DefeasibleRulesNew, DefeasibleRules).\n strictRules(CtrRules, Ids) :-\n findall([RuleName, Preconditions, Effect], (RuleName : Preconditions -> Effect), StrictRulesOld),\n prologStrictRules(StrictRulesNew),\n utils::append_fast(StrictRulesOld, StrictRulesNew, StrictRules),\n transpose(StrictRules, StrictRules, CtrRules),\n extract_id(CtrRules, Ids).\n ordinaryPremises(Premises) :-\n findall([RuleName, Effect], ((RuleName :=> Effect), atom(RuleName)), PremisesOld),\n prologPremises(PremisesNew),\n utils::append_fast(PremisesOld, PremisesNew, Premises).\n axiomPremises(Axioms, Ids) :-\n findall([RuleName, Effect], ((RuleName :-> Effect), atom(RuleName)), AxiomsOld),\n prologAxioms(AxiomsNew),\n utils::append_fast(AxiomsOld, AxiomsNew, Axioms),\n extract_id(Axioms, Ids).\n specialRules(SpecialRules) :-\n bpsNew(SpecialRules).\n transpose(_, CtrRules, CtrRules) :- \\+ autoTransposition, !.\n transpose([], CtrRules, CtrRules).\n transpose([H|T], TempCtrRules, CtrRules) :-\n transpose(T, TempCtrRules, CR),\n findall(TrH, transposition(H, TrH), Tran),\n mergeCtrRules(CR, Tran, CtrRules).\n mergeCtrRules(All, ToMerge, X) :-\n utils::append_fast(All, ToMerge, XT),\n deduplicate(XT, X).\n deduplicate([], []).\n deduplicate([[RN,A,B]|T], X) :- deduplicate(T, TT), (member([RN,_,_], TT) -> X = TT; X = [[RN,A,B]|TT]). \n transposition([Id, Prec, Effect], [Id, Prec, Effect]).\n transposition([Id, Prec, Effect], [NewId, NewPrec ,XNegated]) :-\n compound(Prec),\n tuple_to_list(Prec, LPrec),!,\n transposition_sequential(LPrec, LPrec, Effect, Id, [], NewPrec, XNegated, NewId).\n transposition([Id, Prec, Effect], [NewId, EffectNegated ,XNegated]) :-\n \\+ compound(Prec),\n Prec \\== [],\n prologEscape(Prec),\n negate(Prec, XNegated),\n negate(Effect, EffectNegated),\n atom_concat(Id, '_i', NewId).\n transposition_sequential(LPrec, [H|T], Effect, Id, Skipped, NewPrec, XNegated, NewId) :-\n transposition_sequential(LPrec, T, Effect, Id, [H|Skipped], NewPrec, XNegated, NewId).\n transposition_sequential(LPrec, [X|T], Effect, Id, Skipped, NewPrec, XNegated, NewId) :-\n prologEscape(X),\n utils::append_fast(Skipped, T, CleanedPrec),\n negate(X, XNegated),\n negate(Effect, EffectNegated),\n list_to_tuple([EffectNegated|CleanedPrec], NewPrec),\n newIdentifier(Skipped, Id, NewId).\n newIdentifier(List, OldId, NewId) :-\n modifier(List, Mod),\n atom_concat(OldId, Mod, NewId).\n modifier([], '_i').\n modifier([_|Tail], Index):-\n modifier(Tail, Index1),\n atom_concat(Index1, 'i', Index).\n negate(X, Arg) :-\n functor(X, '-', _) -> (\n arg(1, X, Arg));\n functor(X, 'p', _) -> (\n arg(1, X, PX),\n (functor(PX, '-', _) -> (\n arg(1, PX, PNX),\n Arg = o(PNX)\n );\n Arg = o(-(PX))));\n Arg = -(X).\n prologEscape(X) :- \\+ functor(X, 'prolog', _), \\+ functor(X, '~', _).\n /*\n * Standard rules (RuleName : Preconditions => Effects)\n * Special rules (RuleName : Effects)\n */\n convertAllRules([], []).\n convertAllRules([[H,P,E]|T], [R|Rules]) :- convertRule(H, P, E, R), convertAllRules(T, Rules).\n convertAllRules([[H,E]|T], [R|Rules]) :- convertRule(H, E, R), convertAllRules(T, Rules).\n /*\n * Convert the given rule to the standard format\n * Example:\n * r2: followedGuidelines(X), doctor(X) => -liable(X)\n * rule([r2,[[followedGuidelines(X_e4149)],[doctor(X_e4149)]],[neg,liable(X_e4149)]]).\n */\n convertRule(RuleName, Preconditions, Effects, rule(List)) :-\n tuple_to_list(Preconditions, Lprecond),\n tuple_to_list(Effects, Leffects),\n check_modifiers_in_list(preconditions, Lprecond, LprecondChecked),\n check_modifiers_in_list(effects, Leffects, LeffectsChecked),\n flatten_first_level(LeffectsChecked, LeffectsCheckedFlattened),\n List = [RuleName, LprecondChecked, LeffectsCheckedFlattened], !.\n /*\n * Convert the given special rule\n * Example:\n * bp(-liable(X)).\n * abastractBp([[neg, liable(X_e4149)]]).\n */\n convertRule(bps, Effects, abstractBp(Checked)) :-\n functor(Effects, 'bp', _),\n Effects =.. L,\n removehead(L, LC),\n check_modifiers_in_list(effects, LC, Checked), !.\n convertRule(Name, Effects, premise([Name, LeffectsCheckedFlattened])) :-\n tuple_to_list(Effects, Leffects),\n check_modifiers_in_list(effects, Leffects, LeffectsChecked),\n flatten_first_level(LeffectsChecked, LeffectsCheckedFlattened).\n /*\n * Find negations(-), obligations(o), permissions(p) on a list of preconditions/effects and\n * raplace them with the assigned literal (neg, obl, perm)\n */\n check_modifiers_in_list(MODE, [], []) :- !.\n check_modifiers_in_list(MODE, [H|T], L) :- H == [], L = [], !.\n check_modifiers_in_list(MODE, [H|T], R) :- H \\== [],\n check_modifiers_once(H, LH),\n check_modifiers_in_list(MODE, T, LT),\n utils::append_fast([LH], LT, L),\n R = L.\n check_modifiers_once(H, List) :- once(check_modifiers(H, List)).\n check_modifiers([], []).\n check_modifiers(H, List) :-\n functor(H, '-', _) -> (\n arg(1, H, Arg),\n check_modifiers_once(Arg, Lobl),\n utils::append_fast([neg], Lobl, Lf),\n List = Lf);\n functor(H, 'o', _) -> (\n arg(1, H, Arg),\n check_modifiers_once(Arg, Lobl),\n List = [obl|[Lobl]]);\n functor(H, 'p', _) -> (\n arg(1, H, Arg),\n check_modifiers_once(Arg, Lper),\n List = [perm|[Lper]]);\n functor(H, '~', _) -> (\n arg(1, H, Arg),\n check_modifiers_once(Arg, Lper),\n List = [unless|[Lper]]);\n functor(H, 'bp', _) -> (\n H =.. [_|Arg],\n check_modifiers_in_list(effects, Arg, Lper),\n List = [bp|[Lper]]);\n List = [H].\n /*\n * Convert the given tuple to list\n */\n tuple_to_list(A,[A]) :- nonvar(A), A \\= (_ , _), !.\n tuple_to_list((A,B),L) :-\n tuple_to_list(A, La),\n tuple_to_list(B, Lb),\n utils::append_fast(La, Lb,L).\n list_to_tuple([H], (H)) :- !.\n list_to_tuple([H|T], (H,TT)) :- list_to_tuple(T,TT).\n /*\n * Replace all the occurences of a given element with the given argument\n */\n replace(_, _, [],[]) :- !.\n replace(O, R, [O|T], [R|T2]) :- replace(O, R, T, T2), !.\n replace(O, R, [H|T], [H|T2]) :- H \\= O, replace(O, R, T, T2).\n flatten_first_level([X], X) :- !.\n flatten_first_level.\n removehead([_|Tail], Tail).\n in(A, A) :- nonvar(A), A \\= (_ , _), !.\n in(A, (A, _)) :- !.\n in(A, (_ , Cs)) :- in(A, Cs).\n check_admissibility(preconditions, H, LH) :-\n \\+ defeasible_admissible(LH),\n throw(['Premise ', H, ' is not a well formed member of the argumentation language.']).\n check_admissibility(effects, H, LH) :-\n \\+ admissible(LH),\n throw(['Conclusion ', H, ' is not a well formed member of the argumentation language.']).\n check_admissibility(_, _, _).\n defeasible_admissible([unless, Term]) :- admissible(Term).\n defeasible_admissible(Term) :- admissible(Term).\n admissible([neg, bp, Term]) :- admissible_terms_complete(Term).\n admissible([bp, Term]) :- admissible_terms_complete(Term).\n admissible([neg, Term]) :- admissible_term(Term).\n admissible([obl, [Term]]) :- admissible_term(Term).\n admissible([obl, [neg, Term]]) :- admissible_term(Term).\n admissible([neg, obl, [Term]]) :- admissible_term(Term).\n admissible([neg, obl, [neg, Term]]) :- admissible_term(Term).\n admissible([perm, [Term]]) :- admissible_term(Term).\n admissible([perm, [neg, Term]]) :- admissible_term(Term).\n admissible([Term]) :- admissible_term(Term).\n admissible_term(Term) :-\n atomic(Term),\n Term \\== neg,\n Term \\== obl,\n Term \\== perm,\n Term \\== unless,\n Term \\== bp.\n admissible_term(Term) :- var(Term).\n admissible_term(Term) :-\n compound(Term),\n \\+ functor(Term, 'o', _),\n \\+ functor(Term, 'p', _),\n \\+ functor(Term, '-', _),\n \\+ functor(Term, '~', _),\n \\+ functor(Term, 'bp', _),\n Term =.. [_|Args],\n admissible_terms(Args).\n admissible_terms([]).\n admissible_terms([H|T]) :-\n admissible_term(H),\n admissible_terms(T).\n admissible_terms_complete([]).\n admissible_terms_complete([H|T]) :-\n admissible(H),\n admissible_terms_complete(T).\n ");
4880
5084
  }
4881
5085
  RuleTranslator.$metadata$ = {
4882
5086
  kind: Kind_OBJECT,
@@ -4921,7 +5125,7 @@
4921
5125
  }
4922
5126
  function Utils() {
4923
5127
  Utils_instance = this;
4924
- this.theoryCode = trimIndent('\n writeList([]) :- nl.\n writeList([X|Others]) :-\n \twrite(X),\n \twriteList(Others).\n writeListNl([]).\n writeListNl([X|Others]) :-\n \twrite(X),nl,\n \twriteListNl(Others).\n sortDistinct(List, Sorted) :-\n deduplicate(List, Deduplicated),\n sort(Deduplicated, Sorted).\n deduplicate([], []).\n deduplicate(List, Output) :-\n List \\== [],\n setof(X, member(X, List), Output).\n sort(List,Sorted) :- q_sort(List, [], Sorted).\n q_sort([], Acc, Acc).\n q_sort([H|T], Acc, Sorted) :-\n \tpivoting(H, T, L1, L2),\n \tq_sort(L1, Acc, Sorted1),\n \tq_sort(L2, [H|Sorted1], Sorted).\n pivoting(H,[],[],[]).\n pivoting(H, [X|T], [X|L], G) :-\n H @>= X,\n pivoting(H, T, L, G).\n pivoting(H, [X|T], L, [X|G]) :-\n X @> H,\n pivoting(H, T, L, G).\n subtract([], _, []).\n subtract([Head|Tail], L2, L3) :-\n member(Head, L2), !,\n subtract(Tail, L2, L3).\n subtract([Head|Tail1], L2, [Head|Tail3]) :-\n subtract(Tail1, L2, Tail3).\n isEmptyList([]).\n appendLists([], []).\n appendLists([H|T], R) :-\n appendLists(T, AT),\n append(H, AT, R).\n search(F, L, S) :-\n between(1, L, N),\n functor(S, F, N),\n call(S).\n between(N, M, K) :- N < M, K = N.\n between(N, M, K) :- N == M, !, K = N.\n between(N, M, K) :- N < M, N1 is N+1, between(N1, M, K).\n recoverGraph(Args, Attacks, Supports) :-\n findall(X, context_check(argument(X)), TempArgs),\n findall((T, A, B, C), context_check(attack(T, A, B, C)), TempAttacks),\n findall((A, B), context_check(support(A, B)), TempSupports),\n utils::sort(TempArgs, Args),\n utils::sort(TempAttacks, Attacks),\n utils::sort(TempSupports, Supports).\n recoverArgumentLabelling(ArgsIn, ArgsOut, ArgsUnd) :-\n findall(X, context_check(in(X)), TempArgsIn),\n findall(X, context_check(out(X)), TempArgsOut),\n findall(X, context_check(und(X)), TempArgsUnd),\n utils::sort(TempArgsIn, ArgsIn),\n utils::sort(TempArgsOut, ArgsOut),\n utils::sort(TempArgsUnd, ArgsUnd).\n recoverStatementLabelling(In, Out, Und) :-\n findall(X, context_check(statIn(X)), TempIn),\n findall(X, context_check(statOut(X)), TempOut),\n findall(X, context_check(statUnd(X)), TempUnd),\n utils::sort(TempIn, In),\n utils::sort(TempOut, Out),\n utils::sort(TempUnd, Und).\n ');
5128
+ this.theoryCode = trimIndent('\n writeList([]) :- nl.\n writeList([X|Others]) :-\n \twrite(X),\n \twriteList(Others).\n writeListNl([]).\n writeListNl([X|Others]) :-\n \twrite(X),nl,\n \twriteListNl(Others).\n sortDistinct(List, Sorted) :-\n deduplicate(List, Deduplicated),\n sort(Deduplicated, Sorted).\n deduplicate([], []).\n deduplicate(List, Output) :-\n List \\== [],\n setof(X, member(X, List), Output).\n sort(List,Sorted) :- q_sort(List, [], Sorted).\n q_sort([], Acc, Acc).\n q_sort([H|T], Acc, Sorted) :-\n \tpivoting(H, T, L1, L2),\n \tq_sort(L1, Acc, Sorted1),\n \tq_sort(L2, [H|Sorted1], Sorted).\n pivoting(H,[],[],[]).\n pivoting(H, [X|T], [X|L], G) :-\n H @>= X,\n pivoting(H, T, L, G).\n pivoting(H, [X|T], L, [X|G]) :-\n X @> H,\n pivoting(H, T, L, G).\n subtract([], _, []).\n subtract([Head|Tail], L2, L3) :-\n member(Head, L2), !,\n subtract(Tail, L2, L3).\n subtract([Head|Tail1], L2, [Head|Tail3]) :-\n subtract(Tail1, L2, Tail3).\n isEmptyList([]).\n appendLists([], []).\n appendLists([H|T], R) :-\n appendLists(T, AT),\n append_fast(H, AT, R).\n search(F, L, S) :-\n between(1, L, N),\n functor(S, F, N),\n call(S).\n between(N, M, K) :- N < M, K = N.\n between(N, M, K) :- N == M, !, K = N.\n between(N, M, K) :- N < M, N1 is N+1, between(N1, M, K).\n recoverGraph(Args, Attacks, Supports) :-\n findall(X, context_check(argument(X)), TempArgs),\n findall((T, A, B, C), context_check(attack(T, A, B, C)), TempAttacks),\n findall((A, B), context_check(support(A, B)), TempSupports),\n utils::sort(TempArgs, Args),\n utils::sort(TempAttacks, Attacks),\n utils::sort(TempSupports, Supports).\n recoverArgumentLabelling(ArgsIn, ArgsOut, ArgsUnd) :-\n findall(X, context_check(in(X)), TempArgsIn),\n findall(X, context_check(out(X)), TempArgsOut),\n findall(X, context_check(und(X)), TempArgsUnd),\n utils::sort(TempArgsIn, ArgsIn),\n utils::sort(TempArgsOut, ArgsOut),\n utils::sort(TempArgsUnd, ArgsUnd).\n recoverStatementLabelling(In, Out, Und) :-\n findall(X, context_check(statIn(X)), TempIn),\n findall(X, context_check(statOut(X)), TempOut),\n findall(X, context_check(statUnd(X)), TempUnd),\n utils::sort(TempIn, In),\n utils::sort(TempOut, Out),\n utils::sort(TempUnd, Und).\n ');
4925
5129
  }
4926
5130
  Utils.$metadata$ = {
4927
5131
  kind: Kind_OBJECT,
@@ -5144,6 +5348,9 @@
5144
5348
  Object.defineProperty(package$language, 'Bps', {
5145
5349
  get: Bps_getInstance
5146
5350
  });
5351
+ Object.defineProperty(package$language, 'ExtractStrictIds', {
5352
+ get: ExtractStrictIds_getInstance
5353
+ });
5147
5354
  var package$structured = package$libs.structured || (package$libs.structured = {});
5148
5355
  package$structured.StructuredModeBase = StructuredModeBase;
5149
5356
  Object.defineProperty(package$structured, 'QueryMode', {
@@ -5162,6 +5369,12 @@
5162
5369
  get: OrderingComparator_getInstance
5163
5370
  });
5164
5371
  package$utils.UtilsBase = UtilsBase;
5372
+ Object.defineProperty(package$utils, 'AppendOptimized', {
5373
+ get: AppendOptimized_getInstance
5374
+ });
5375
+ Object.defineProperty(package$utils, 'AssertAll', {
5376
+ get: AssertAll_getInstance
5377
+ });
5165
5378
  var package$meta = package$core.meta || (package$core.meta = {});
5166
5379
  Object.defineProperty(package$meta, 'MetaInterpreterLib', {
5167
5380
  get: MetaInterpreterLib_getInstance
@@ -5480,9 +5693,9 @@
5480
5693
  PrologWithArgumentationImpl.prototype.anyMguWith = PrologWithArgumentation.prototype.anyMguWith;
5481
5694
  PrologWithArgumentationImpl.prototype.anyUnifyWith = PrologWithArgumentation.prototype.anyUnifyWith;
5482
5695
  PrologWithArgumentationImpl.prototype.list = PrologWithArgumentation.prototype.list;
5483
- PrologWithArgumentationImpl.prototype.listFromIterable = PrologWithArgumentation.prototype.listFromIterable;
5484
- PrologWithArgumentationImpl.prototype.listFrom = PrologWithArgumentation.prototype.listFrom;
5485
5696
  PrologWithArgumentationImpl.prototype.listFromSequence = PrologWithArgumentation.prototype.listFromSequence;
5697
+ PrologWithArgumentationImpl.prototype.listFrom = PrologWithArgumentation.prototype.listFrom;
5698
+ PrologWithArgumentationImpl.prototype.listFromIterable = PrologWithArgumentation.prototype.listFromIterable;
5486
5699
  PrologWithArgumentationImpl.prototype.matchAny = PrologWithArgumentation.prototype.matchAny;
5487
5700
  PrologWithArgumentationImpl.prototype.mguWithOccurCheck = PrologWithArgumentation.prototype.mguWithOccurCheck;
5488
5701
  PrologWithArgumentationImpl.prototype.mguAny = PrologWithArgumentation.prototype.mguAny;