Reasoning on Multi-Relational Contextual Hierarchies via Answer Set Programming with Algebraic Measures

Dealing with context dependent knowledge has led to different formalizations of the notion of context. Among them is the Contextualized Knowledge Repository (CKR) framework, which is rooted in description logics but links on the reasoning side strongly to logic programs and Answer Set Programming (ASP) in particular. The CKR framework caters for reasoning with defeasible axioms and exceptions in contexts, which was extended to knowledge inheritance across contexts in a coverage (specificity) hierarchy. However, the approach supports only this single type of contextual relation and the reasoning procedures work only for restricted hierarchies, due to non-trivial issues with model preference under exceptions. In this paper, we overcome these limitations and present a generalization of CKR hierarchies to multiple contextual relations, along with their interpretation of defeasible axioms and preference. To support reasoning, we use ASP with algebraic measures, which is a recent extension of ASP with weighted formulas over semirings that allows one to associate quantities with interpretations depending on the truth values of propositional atoms. Notably, we show that for a relevant fragment of CKR hierarchies with multiple contextual relations, query answering can be realized with the popular asprin framework. The algebraic measures approach is more powerful and enables e.g. reasoning with epistemic queries over CKRs, which opens interesting perspectives for the use of quantitative ASP extensions in other applications.


Introduction
Representing and reasoning with context dependent knowledge is a fundamental theme in AI, with proposals dating back to the works of McCarthy (1993) and Giunchiglia and Serafini (1994). It has gained increasing attention for the Semantic Web as knowledge resources must be interpreted with contextual information from their metadata. Several approaches for contextual reasoning, most based on description logics, were developed (Straccia et al. 2010;Klarman 2013;Serafini and Homola 2012).
A rich framework among them are Contextualized Knowledge Repositories (CKR) (Serafini and Homola 2012): CKR knowledge bases (KBs) are 2-layered structures with a global context, which contains context-independent global knowledge and meta-knowledge about the structure of the KB, and local contexts containing knowledge about specific situations (e.g., a region in space, a site of an organization). Notably, the global knowledge is propagated to local contexts, where inherited axioms may be defeasible, meaning that instances can be "overridden" on an exceptional basis (Bozzato et al. 2018a). Reasoning from CKRs strongly links to logic programming, as the KBs are over a Horn-description logic and the working of defeasible axioms was inspired by conflict handling in inheritance logic programs (Buccafurri et al. 1999). Furthermore, answering instance and conjunctive queries over a CKR is possible via a uniform ASP program that employs a materialization calculus akin to the one by Krötzsch (2010).
For modeling and analyzing complex scenarios where global regulations (e.g. laws, environmental regulations, access control rules) can be refined by more specific situations (e.g. timebounded events, geographical areas, groups of users), the CKR model was extended (Bozzato et al. 2018b) to cater for defeasible axioms in local contexts and knowledge inheritance across hierarchies, based on a coverage contextual relation (Serafini and Homola 2012).
This approach, however, is limited to reason only on hierarchies based on this single type of contextual relation. In practice, defeasible inheritance may be necessary under different contextual relations. For example, along a location hierarchy, we may prefer axioms encoding regional laws overriding state-level regulations, while preferring newer rules over older laws along a temporal dimension. A further limitation is that even for a single coverage relation, it is challenging to encode the induced preference relation over CKR interpretation using ASP because the relation may not be transitive and thus not a strict partial order, as assumed e.g. in the popular asprin framework for preferences in ASP (Brewka et al. 2015). Instead, a specialized implementation for preferential reasoning was introduced (Bozzato et al. 2019), which however needs to consider all answer sets of a program to single out a preferred CKR model.
In this paper, we overcome these limitations and make the following contributions: (1) We generalize single-relational CKRs to multi-relational CKRs, where axioms are not defeasible in general but merely with regard to individual relations of hierarchies. By a combination of preferences over the distinct individual relations, we obtain an overall preference over the models of a CKR. While intuitive, the technical condition has pitfalls and needs care.
(2) We show how to model multi-relation CKRs in ASP. Specifically, we use to this end ASP with algebraic measures (Eiter and Kiesel 2020), which is a foundation to express many quantitative reasoning problems. Here, weighted logic formulas (Droste and Gastin 2005) measure values associated with an interpretation I by performing a computation over a semiring, whose outcome depends on the truth of the propositional variables in I. Such measures can be used for e.g. weighted model counting, probabilistic reasoning and, as in our case, preferential reasoning.
(3) While asprin is a powerful tool for modeling preferences in ASP, it appears to be illsuited for expressing multi-relational CKR. The reason are eval -expressions in CKRs, which propagate predicate extensions from one local context to another. We show, however, that under a well-behaved use of such expressions according to a syntactic disconnectedness condition, multi-relational CKRs can be expressed in asprin. This enables us to use the asprin solver to evaluate preferences for CKRs, which is showcased in a prototype implementation.
(4) Furthermore, ASP with algebraic measures opens the possibility of reasoning tasks for CKRs beyond asprin's capability, even in absence of eval -expression. As examples we consider obtaining preferred CKR models by overall weight queries and epistemic reasoning, which for description logics is specifically needed in aggregate queries (Calvanese et al. 2008).
In conclusion, ASP extended with preferences or algebraic computations is a valuable tool to express CKR extensions and reasoning on them, with a promising perspective for further research.

Preliminaries
Description Logics and SROIQ-RL. We follow the common presentation of description logics (DLs) (Baader et al. 2003) and the definition of the logic SROIQ (Horrocks et al. 2006).
A DL vocabulary Σ consists of the mutually disjoint countably infinite sets NC of atomic concepts, NR of atomic roles, and NI of individual constants. Complex concepts are recursively defined as the smallest sets containing all concepts that can be inductively constructed using the operators of the considered DL language L Σ . A DL knowledge base K = T , R, A consists of: a TBox T which can contain general concept inclusion axioms C D, where C and D are concepts; an RBox R which contains role inclusion axioms S R, where S and R are roles, and role properties axioms; and an ABox A which contains assertions of the forms D(a), R(a, b), where a and b are any individual constants.
A DL interpretation is a pair I = ∆ I , · I where ∆ I is a non-empty set called domain and · I is the interpretation function which provides the interpretation for language elements: a I ∈ ∆ I , for a ∈ NI; A I ⊆ ∆ I , for A ∈ NC; R I ⊆ ∆ I × ∆ I , for R ∈ NR. The interpretation of complex concepts and roles is defined by the evaluation of their DL operators (see the paper by Horrocks et al. (2006) for SROIQ). An interpretation I satisfies an axiom φ , denoted I |= φ , if it verifies the respective semantic condition, in particular: for φ = D(a), a I ∈ D I ; for φ = R(a, b), a I , b I ∈ R I ; for φ = C D, C I ⊆ D I (resp. for role inclusions). I is a model of K, denoted I |= K, if it satisfies all axioms of K. We adopt w.l.o.g. the standard name assumption (SNA) in the DL setting, i.e., every element in I is reachable via a distinct constant.We denote by NI S ⊆ NI the set of all such constants, called standard names, which are uniform for all interpretations; see the papers by Eiter et al. (2008) andde Bruijn et al. (2008) for more details.
Most of the following definitions for simple CKR are independent from the DL used as representation language inside contexts: however, as in the paper by Bozzato et al. (2018a), we take as reference language a restriction of the SROIQ syntax called SROIQ-RL which corresponds to OWL-RL. We restrict as follows left-side concepts C and right-side concepts D: where A ∈ NC, R ∈ NR and n ∈ {0, 1}. SROIQ-RL TBox axioms can only take the form C D, where C is a left-side and D is a right-side or E ≡ F, where E and F are both left-and right-side concepts. A SROIQ-RL RBox can contain role inclusions R S (with possibly left role composition), role disjointness, irreflexivity, symmetry, asymmetry and transitivity. SROIQ-RL ABox concept assertions can only be of form D(a), where D is a right-side concept. We remark that SROIQ-RL basically defines a restriction of SROIQ to axioms that are expressible as Horn rules (cf. FO translation provided by Bozzato et al. (2018a)).
Normal Programs and Answer Sets. We use function-free normal (datalog) rules with (default) negation under answer sets semantics (Gelfond and Lifschitz 1991) and gather them in ASP programs. A normal (datalog) rule r is an expression of the form: also written H(r) ← B(r) where a, b 1 , . . . , b m are function-free FO-atoms and not is negation as failure (NAF). We allow that a is missing (constraint), viewing a as logical constant for falsity. A (datalog) program P is a finite set of rules. An atom (rule etc.) is ground, if no variables occur in it. A fact H is a ground rule r with m = 0. The grounding of a rule r, grnd(r), is the set of all ground instances of r, and the grounding of a program P is grnd(P) = r∈P grnd(r).
For any program P, we denote by U P its Herbrand universe and by B P its Herbrand base; an (Herbrand) interpretation is any subset I ⊆ B P of B P . An atom a is true in I, denoted I |= a, if a ∈ I. Given a rule r ∈ grnd(P), we say that B(r) is true in An interpretation I is a model of P, denoted I |= P, if I |= r for each r ∈ grnd(P); moreover, I is minimal, if I |= P for each subset I ⊂ I. Furthermore, I is an answer set of P, if I is a minimal model of the (Gelfond-Lifschitz) reduct G I (P) of P w.r.t. I, which results from grnd(P) by removing (i) every rule r such that I |= l for some not l ∈ B(r), and (ii) all formulas not b from the remaining rules. The set of answer sets of P is denoted AS(P).
Weighted formulas over a semiring R and an Herbrand base B allow us to assign an interpretation I a semiring value, depending on the truth of propositional variables w.r.t. I. Their syntax is: where k ∈ R and v ∈ B. The semantics α R (I) of α over R w.r.t. I is: for ∈ {v, ¬v} We generalize the definition of simple CKR (sCKR) introduced by Bozzato et al. (2018b;2019) from single-to multi-relational contextual hierarchies. As in the original formulation of CKR by Bozzato et al. (2018a;2013) a simple CKR is still a two layered structure, but the upper layer is simply a poset with multiple orderings, corresponding to different contextual relations. Simple CKRs define a core fragment of CKR allowing us to provide lean definitions on contextual hierarchies: the presented results, however, can be easily generalized to the full CKR. We provide definitions for multi-relational simple CKRs with a general set of context relations and consider the case for 2-relational sCKR based on temporal and coverage relations.
Syntax. Consider a nonempty set N ⊆ NI of context names. A contextual relation is any strict order ≺ i ⊆ N × N over contexts. We may use the non-strict relation c 1 i c 2 to indicate that either c 1 ≺ i c 2 or c 1 and c 2 are the same context. We consider two contextual relations, namely coverage ≺ c and temporal precedence ≺ t . Here, c 1 ≺ c c 2 (resp. c 1 ≺ t c 2 ) means that c 1 is more specific (resp. newer) than c 2 . More specific means that c 1 represents a portion of the world covered by the one referred to by c 2 , as in the paper by Serafini and Homola (2012). We generalize the definition of defeasible axiom w.r.t. contextual relations: Definition 1 (r-defeasible axiom) Given a set R of contextual relations over N and a description language L Σ , an r-defeasible axiom is any expression of the form D r (α), where α is an axiom of L Σ and ≺ r ∈ R.
Thus, we identify coverage-defeasible axioms as D c (α) and temporal-defeasible axioms as D t (α). We allow for the use of r-defeasible axioms in the local language of contexts: Definition 2 (contextual language) Given a set of context names N, for every description language L Σ we define L Σ,N as the extension of L Σ where: (i) L Σ,N contains the set of r-defeasible axioms in L Σ ; (ii) eval(X, c) is a concept (resp. role) of L Σ,N if X is a concept (resp. role) of L Σ and c ∈ N.
Using these definitions, multi-relational simple CKRs are defined as follows: Definition 3 (multi-relational simple CKR) A multi-relational simple CKR (sCKR) over Σ and N is a structure K = C, K N where: -C is a structure (N, ≺ 1 , . . . , ≺ m ) where each ≺ i is a contextual relation over N, and -K N = {K c } c∈N for each context name c ∈ N, K c is a DL knowledge base over L Σ,N .
A sCKR that combines temporal and coverage orderings can be defined by C = (N, ≺ t , ≺ c ). For simplicity, we assume that the priority for the combination of orderings is defined by the linear order in which they appear in C: in the case above, we prioritize ≺ t over ≺ c .

Example 1
We consider the following example to explain the expected behavior of defeasible axioms in the case of the combination of coverage and temporal relations. Let us consider K org = C, K N with C = (N, ≺ t , ≺ c ) describing the organization of a corporation. The corporation has different policies with respect to its local branches, represented by coverage, and updates them along the time precedence. The structure of C, together with the axioms at each context, is shown in Figure 1. We have a chain of three contexts (representing world, branch and local rules) in the direction of the coverage and three "time-slices" (2019, 2020 and 2021) along the time relation: thus, for example, we have c local 2021 ≺ c c branch 2021 and c branch 2020 ≺ t c branch 2019 . The corporation is active in the fields of Electronics (E) and Robotics (R) and employs supervisors (S). In c world 2019 , we state that, with respect to coverage, every Supervisor has to be applied by default to Electronics and that Electronics and Robotics are disjoint. In the lower context c branch 2019 , we further specify that, with respect to time, Supervisors have to work by default OnSite (OS) (where working OnSite and Remote (RE) are disjoint). In 2019's local context c local 2019 we assert that i is a Supervisor. The previous defeasible statements are, however, contradicted by the ones in c branch 2020 , where Supervisors are applied to Robotics and work on Remote.
The interpretation of defeasible propagation and preferences, then, should define the interpretation of what is derivable in the local context in the three time-slices. In c local 2019 no overriding takes place; then we should derive E(i), OS(i). In c local 2020 the more coverage-specific axiom in c branch 2020 is preferred, thus we derive R(i); the time-related defeasible axiom D t (S RE) is applied locally to the 2020 time-slice, thus we derive RE(i). In the 2021 time-slice no new information is provided, thus the overriding preferences should enforce that the more specific and recent information is used: in c local 2021 we expect to derive R(i), RE(i). ♦

Semantics. A sCKR interpretation gathers interpretations for the local contexts as follows.
Definition 4 (sCKR interpretation) An interpretation for L Σ,N is a family I = {I(c)} c∈N of L Σ interpretations, such that ∆ I(c) = ∆ I(c ) and a I(c) = a I(c ) , for every a ∈ NI and c, c ∈ N.
The interpretation of concepts and role expressions in L Σ,N is obtained by extending the standard interpretation to eval expressions: for every c ∈ N, eval(X, c ) I(c) = X I(c ) . We consider the definition of axiom instantiation provided by Bozzato et al. (2018a): given an axiom α ∈ L Σ with FO-translation ∀x.φ α (x), the instantiation of α with a tuple e of individuals in NI, written α(e), is the specialization of α to e, i.e., φ α (e), depending on the type of α.
For a structure C = (N, ≺ 1 , . . . , ≺ m ) and 1 ≤ i ≤ m, we denote by −i the order obtained as the reflexive and transitive closure of j =i ≺ j , i.e., the union of all orders ≺ j except for ≺ i . We denote by * the order obtained as the reflexive and transitive closure of the union of all ≺ j .
Definition 5 (clashing assumptions and sets) A clashing assumption for a context c and contextual relation r is a pair α, e such that α(e) is an axiom instantiation of α, and D r (α) ∈ K c is a defeasible axiom of some c −r c r c. A clashing set for α, e is a satisfiable set S of ABox assertions s.t. S ∪ {α(e)} is unsatisfiable.
A clashing assumption α, e represents that α(e) is not satisfiable in context c, and a clashing set S provides a "justification" for the local assumption of overriding of α on e. CAS-interpretations include a set of clashing assumptions for each context and contextual relation: Definition 6 (CAS-interpretation) A CAS-interpretation is a structure I CAS = I, χ where I is an interpretation and χ = {χ 1 , . . . , χ m } such that each χ i , for i ∈ {1, . . . , m}, maps every c ∈ N to a set χ i (c) of clashing assumptions for context c and context relation ≺ i . Satisfaction of a sCKR K needs to consider the effect of the different relations: Definition 7 (CAS-model) Given a multi-relation sCKR K, a CAS-interpretation I CAS = I, χ is a CAS-model for K (denoted I CAS |= K), if the following holds 1 : (i) for every α ∈ K c (strict axiom), and c * c, I(c ) |= α; (ii) for every D i (α) ∈ K c and c −i c, I(c ) |= α; Intuitively: (i) strict axioms are propagated across the hierarchy structures over * from higher to lower contexts; (ii) considering contexts that are related by relations other than ≺ i (including the context in which axioms are declared), defeasible axioms D i (α) are interpreted as strict axioms; (iii) over relation ≺ i , axioms D i (α) are verified in context c only if applied to instances d that are not in the clashing assumptions for c and relation ≺ i . Note that these propagation rules are applied for every contextual relation: however, the definition can be easily extended to assign different conditions for propagation and overriding for each of the orderings. We provide a local preference on clashing assumption sets for each of the relations: exchanges the "more costly" exceptions of χ 2 i (c) at more specialized contexts with "cheaper" ones at more general contexts. As above, multiple options for local preference can be adopted, cf. (Bozzato et al. 2018b) for ranked hierachies.
Two DL interpretations I 1 and I 2 are NI-congruent, if c I 1 = c I 2 holds for every c ∈ NI. This extends to CAS interpretations I CAS = I, χ by considering all context interpretations I(c) ∈ I.

Definition 8 (justification)
We say that α, e ∈ χ i (c) is justified for a CAS model I CAS , if some clashing set S α,e ,c exists such that, for every I CAS = I , χ of K that is NI-congruent with I CAS , it holds that I (c) |= S α,e ,c . A CAS model I CAS of a sCKR K is justified, if every α, e ∈ χ is justified in K.
We define a model preference by combining the preferences of the relations: it is a global lexicographical ordering on models where each ≺ i defines the ordering at the i-th position.
(MP). I 1 CAS = I 1 , χ 1 1 , . . . , χ 1 m is preferred to (i) or its converse do not hold for ≺ j ). Then, CKR models are defined by taking into account justification and model preference.
Example 2 By considering the sCKR of Example 1, we can show how the preference for different relations influences the global model preference. In the case of K org , we have 8 justified interpretations that are based on combinations of the following clashing assumption sets (for both relations) on contexts c local 2020 and c local 2021 . For any CAS model For χ c (c local 2021 ) we have the same choices as for χ c (c local 2020 ).
According to the (LP) definition, χ 0 c (c local 2020 ) > χ 1 c (c local 2020 ) since D c (S E) occurs at a less specific context w.r.t. ≺ c than D c (S R). Similarly, χ 1 t (c local 2021 ) > χ 2 t (c local 2021 ). Since we can choose the clashing assumptions per context independently, the clashing assumption map of CKR models is uniquely determined by (MP) as Indeed, this corresponds to the intuitive model where overridings over temporal relation occur on defeasible axioms in the "older" contexts and in the "higher" contexts with respect to the coverage relation. ♦ Reasoning and Complexity. We consider the following reasoning tasks for sCKR: The complexity of reasoning with contextual hierarchies in sCKR was studied by Bozzato et al. (2018b;2019) in particular, CKR satisfiability is NP-complete while CKR model checking is coNP-complete already for ranked hierarchies. This causes the complexity of c-entailment to increase in presence of hierarchies: for polynomial-time local preferences on overridings, centailment is Π p 2 -complete. In contrast, BCQ answering remains Π p 2 -complete as verifying a guess for a countermodel to the query remains in coNP. These results would carry over to multirelational hierarchies: for combinations of polynomial-time preferences (like the global preference we considered), c-entailment and similarly BCQ answering would still be Π p 2 -complete.

Preferences with Algebraic Measures
The question rises how the reasoning problems above can be expressed and solved. Previously, in the case of sCKRs with a single relation the strategy was to encode the problem in ASP using a program whose stable models correspond to the least justified models of the sCKR. The preferred models, i.e. sCKR models, were then selected using weight constraints in the restricted case of ranked hierarchies (Bozzato et al. 2018a) or by using a dedicated algorithm for general hierarchies (Bozzato et al. 2019). The preference over models for multi-relational sCKRs is more complicated and thus not easily expressed with weight constraints: we can leverage the power of quantitative extensions of ASP to express model preferences induced by multi-relational sCKRs.
The recently introduced algebraic measures for ASP, which connect ASP with weighted formulas, were shown to be a general framework for specifying quantitative reasoning problems (Eiter and Kiesel 2020). Also preferential reasoning falls into this category, thus allowing us to use algebraic measures to specify a preference on the answer sets in such a way that the preferred answer sets correspond to the preferred least justified models. The concept is as follows.
Definition 10 (Algebraic Measure) An algebraic measure µ = Π, α, R consists of an answer set program Π, a weighted formula α, and a semiring R. The weight of an answer set S ∈ AS(Π) is µ(S) = α R (S). And the overall weight of µ is defined as µ(Π) = S∈AS(Π) µ(S).
Intuitively, given µ = Π, α, R the program Π specifies which interpretations are accepted and the weighted formula α measures some value associated with them. Using algebraic measures, we can not only assign answer sets a weight but also obtain some information from all answer sets by considering the overall weight µ(Π).

Example 3
Let Π be some answer set program. Then, for example, for µ 1 = Π, 1, N the overall weight µ(Π) is the number of answer sets of Π. For µ 2 = Π, (a 1 * 1 + + + ¬a 1 ) * . . . * (a n * 1 + + + ¬a n ), R max , where R max = R ∪ {−∞}, max, +, −∞, 0 , the weight µ(S) of an answer set S is the number of atoms a 1 , . . . , a n it satisfies. We need the additional term ¬a i , since a i * 1 evaluates to e ⊕ = −∞ when a i is false and not to the desired value e ⊗ = 0. Due to the usage of the semiring R max the overall weight µ(Π) is the maximum number of atoms from a 1 , . . . , a n that are satisfied in any answer set of Π.
A natural use case of algebraic measures is preferential reasoning. In the sequel, a preference relation is any asymmetric relation.
Intuitively, we use µ as an optimization function and take the preferred answer sets as those that achieve an optimal value.

Example 4
Reconsider the measure µ 2 from Example 3. If a 1 , . . . , a n are desired to be true, then we only want to consider those answer sets for which a maximal number of them is true. These are exactly the preferred answer sets with respect to the measure µ 2 and the usual order over the reals.
We assume a program PK(K) (see Section 5), which intuitively guesses a set of atoms ovr(φ , e, c, i), each corresponding to a clashing assumption φ , e in χ i (c), and checks whether there is an CAS model I CAS = I, χ . The answer sets I corresponds to the least CAS models with that property. Then we can introduce a measure µ opt and order > opt to obtain those answer sets of PK(K) as preferred answer sets w.r.t. µ opt and > opt that correspond to the preferred least justified models of K. Here, we do not require any restrictions on the K at all.
We use the powerset semiring P(CA) over the set CA, which contains the tuple φ , e, c, i for each possible clashing assumption φ , e that can occur at context c w.r.t. relation i. The weighted formula of µ opt = PK(K), α, P(CA) is given by α = Σ φ ,e,c,i ∈CA ovr(φ , e, c, i) * { φ , e, c, i }. It is easy to see that for each answer set I of PK(K) it holds that φ , e, c, i ∈ µ opt (I) iff ovr(φ , e, c, i) ∈ I. Thus, we only need to define the order > opt on the semiring values S ⊆ CA that correctly captures the ordering on the justified models. For this we let S ⊆ CA and define (χ , the clashing assumption maps corresponding to S, by setting Theorem 1 Let K be an sCKR and PK(K) as described above. Then the preferred answer sets w.r.t. µ opt and > opt correspond to the least CKR models I, χ of K, i.e. those where I is the ⊆-minimal interpretation such that I, χ is a CKR model.
In the following we outline how such an ASP program PK(K) can be constructed. Furthermore, we show that for suitably restricted K, we can also express algebraic measures and preferential answer sets using asprin.

ASP Encoding of Reasoning Problems
ASP translation process. The ASP translation by Bozzato et al. (2018a) for instance checking (w.r.t. c-entailment, under UNA) in a SROIQ-RL CKR can be extended to multi-relational sCKRs K = C, K N , such that (1) a set of input rules I encode the contextual structure and local contents of contexts in K as facts; (2) uniform deduction rules P encode the interpretation of axioms; and (3) the instance query is encoded by output rules O as ground facts.
Formally, the CKR program PK(K) = PG(C)∪ c∈N PC(c, K) encodes the whole sCKR, where PG(C) = I glob (C) ∪ P glob is the global program for C and PC(c, K) = I loc (K c , c) ∪ P loc is the local program for c ∈ N. Query answering K |= c : α is then achieved by testing whether the instance query, translated to O(α, c), is a consequence of the preferred models of PK(K), i.e., whether PK(K) ∪ P pre f |= O(α, c) holds, where P pre f are the newly added rules for selection of preferred models. Analogously, this can be extended to conjunctive queries as shown by Bozzato et al. (2018a). The details of the translation rules are in the Appendix; in the following, we further discuss P pre f . asprin-based model selection. From the translation PK(K) we obtain the least justified models of K as answer sets of an ASP program. In Section 4, we showed how to use algebraic measures for describing which answer sets correspond to preferred models. By suitably restricting the input CKR K, we show that we can implement the preference already in the asprin framework (Brewka et al. 2015). The latter can not express sCKR preference relations in general as eval -expressions may cause non-transitive and even cyclic preference relations. We thus restrict the use of evalexpressions such that we can define an asprin preference relation > that has the same preferred answer sets as µ opt but is a strict partial order. For this, we consider a dependency graph.

Definition 12 (Dependency Graph)
The dependency graph of an sCKR K is the directed graph DEP(K) = (V, E) is K, where: -V = {X c | X is a concept or role that occurs in K c }, i.e., we have a vertex X c for every combination of a concept or role X that occurs in K and context c ∈ N. -(X c , X c ) ∈ E if either: (i) c = c , X is a complex concept or role and X is a subexpression of X; (ii) c = c and X, X co-occur in some (possibly defeasible) axiom; or (iii) X = eval(X , c ).
Intuitively, a path connects two concepts/roles X c , X c in DEP(K) if the interpretations of X, X at contexts c, c , respectively, may depend on each other. If there are no eval -expressions, then clearly there is no path between X c , X c when c = c . In this case, we can choose the interpretations per context independently, which simplifies the choosing of preferred interpretations significantly. However, as the preference only refers to clashing assumptions caused by defaults, we can also use a weaker condition to a similar effect: Definition 13 (eval-Disconnectedness) Let K be an sCKR and X, X two concepts or roles that occur in default axioms. Then X, X are eval-disconnected if there is no path between X c , X c in DEP(K) for every c = c . Furthermore, K is eval -disconnected if every such X, X are eval -disconnected.
In the following, we confine to eval -disconnected sCKR's and define the preference in asprin as follows. We use so called "poset" preferences, which are specified using statements of the form: Here each F i is a Boolean formula, and a partial order > on such formulas is defined by the transitive closure of >>.
We then define the local preference w.r.t. context c and relation i by This encodes that, whenever possible, we prefer not to override a defeasible axiom D i (α) (line 2); further, if we have to override some defeasible axiom, then we prefer to override the least specific one possible (line 3). Next, we emulate the preference definition (MP), where item (i) combines the local preferences into a preference per defeasibility relation and item (ii) states that the global ordering is the lexicographical combination of the preferences per relation.
Using asprin, we can combine existing preference orders into a new one. This is where evaldisconnectedness comes into play. While for general sCKRs this is not the case, for eval -disconnected sCKRs, the preferred models w.r.t. (i) are the pareto optimal models X, i.e., no model Y exists that is strictly better than X on one of the local preferences LocPref(c, i) and at least as good on all the others. Thus, we use the pareto type to define the preference per relation i: Here, the condition context(C) enforces that we take the pareto order over the orders LocPref (C,i) for every context C. Finally, for (ii), we use asprin's lexicographical preference over orders (p i ) i∈[n] with weights (w i ) i∈ [n] . When w i > w j we may worsen p j to improve p i . # preference ( GlobPref , lexico ) { W ::** RelPref ( I ) : rel_w (I , W ) }.
Similar to above, the condition rel_w(I,W) ensures that we obtain the lexicographical order over all preferences RelPref(I), where I is a relation with weight W; in our case, W is its index.
Correctness. The presented encoding yields a sound and complete reasoning method for multirelational sCKRs in SROIQ-RLD normal form, on time and coverage relations. SROIQ-RLD disallows defeasible SROIQ-RL-axioms that introduce disjunctive information. The normal form of SROIQ-RLD due to Bozzato et al. (2018a) is summarized in the Appendix. Formally,

Theorem 2
Let K be a multi-relational sCKR that is eval -disconnected and in SROIQ-RLD normal form. Then under the unique name assumption (UNA), Similarly to Bozzato et al. (2019;2018b), the result is shown by proving a correspondence between the least CAS models of K and the answer sets of PK(K), and then between preferred CAS models and answer sets, which are here selected by our asprin preference. For space reasons, we confine to a proof outline; more details are given in the Appendix.
Without loss of generality, we can restrict to named models, i.e., models I s.t. the interpretation of atomic concepts and roles belongs to N I for some N ⊆ NI \ NI S . This allows us to concentrate on Herbrand models for K; in particular, w.r.t. a clashing assumption χ = (χ t , χ c ), we have a least Herbrand model which we denote asÎ(χ).
Suppose I CAS = I, χ is a justified named CAS-model. We can build from I CAS a corresponding Herbrand interpretation I(I CAS ) for the program PK(K). Along the lines of Bozzato et al. (2018a, Lemma 6), we can then show that the answer sets of PK(K) coincide with the sets I(Î(χ)) where χ is the clashing assumption of a named CAS model of K. With this in place, we show that in case of a multi-relational hierarchy, the answer sets of PK(K) ∪ P pre f found optimal by the asprin preference GlobPref (implementing P pre f ) coincide with the sets I(Î(χ)) where χ is the clashing assumption of a named preferred CAS model (i.e. CKR model) of K. Prototype Implementation. The ASP translation presented above is implemented as a proofof-concept in the CKRew (CKR datalog rewriter) prototype (Bozzato et al. 2018a). CKRew is a Java-based command line application that builds on dlv. It accepts as input RDF files representing the contextual structure and local knowledge bases and produces as output a single .dlv text file with the ASP rewriting for the input CKR. The latest version of CKRew is available at github.com/dkmfbk/ckrew/releases and includes sample RDF files for K org of Example 1.

Additional Possibilities with Algebraic Measures
We highlight further fruitful usages of algebraic measures for reasoning with sCKRs.
Preferred Model as an Overall Weight. First, we show another alternative way of obtaining a preferred model as the result of an overall weight query. Formally, we have the following:

Theorem 3
Let K be a single-relational, eval -free sCKR. Then there exist a semiring R one (K) and weighted formula α one such that the overall weight of µ one = PK(K), α one , R one (K) is either (I, χ), where I is the minimum lexicographical preferred answer set of PK(K) and χ is the corresponding clashing assumption map, or 0 0 0 if there is no preferred answer set.
Here, the lexicographical order > lex over answer sets is given by I > lex I iff there exists some b ∈ B PK(K) such that b ∈ I \ I and for all b < var b it holds that b ∈ I iff b ∈ I , where < var is an arbitrary but fixed total order on B PK(K) .
Intuitively, we define R one (K) by the following strategy. The domain R is the set of all pairs (I, χ), where I is an interpretation of PK(K) and χ a possible clashing assumption map, and two constants 0, 1, which act as the zero and one of the semiring. The multiplication ⊗ of R one (K) is (pointwise) union and can thus be used to build a representation of the interpretation I and its clashing assumption map χ. The addition ⊕ corresponds to taking the "more preferred" interpretation or the one which is lexicographically smaller, in case of a tie.
Note that the restriction to eval -free sCKRs (or a similar fragment) is necessary: the strategy explained above is only viable if the preference relation over the models is transitive.
Epistemic Reasoning using Overall Weight Queries. Using asprin, we can enumerate preferred models. For obtaining all of them at once, we can use an overall weight query.

Theorem 4
Let K be a single-relational, eval -free sCKR. Then there exists a semiring R all (K) and weighted formula α all such that the overall weight of µ all = PK(K), α all , R all (K) is (A c ) c∈N and the set of CKR models corresponds to {(I(c)) c∈N | for each c ∈ N : (I(c), χ(c)) ∈ A c }.
The definition of R all (K) is similar to that of R one (K). However, instead of pairs (I, χ) the semiring values here are sets of pairs (I, χ). Given such sets A, B, addition and multiplication select the preferred pairs in the result of the union A ∪ B and the "Cartesian" union {(S 1 ∪ S 2 , χ 1 ∪ χ 2 ) | (S 1 , χ 1 ) ∈ A, (S 2 , χ 2 ) ∈ B}, respectively.
We can use the overall weight µ all (PK(K)) not only to single out all preferred models but also for further advanced tasks. E.g., the cautious and brave consequences at context c are obtained by Apart from this, we can also use the result to evaluate epistemic aggregate queries, akin to the ones defined by Calvanese et al. (2008), of the form where φ and ψ are conjunctions of possibly non-ground atoms and x, y, z are sequences of variables that occur in φ , such that z is distinct from x and y. Furthermore, α is an aggregation function. The meaning of this expression given a knowledge base KB is intuitively as follows. For each assignment to x, we aggregate over all values y using α, subject to the constraint that for every model D of KB the assignment to x, y can be completed to an assignment γ to all the variables in φ and ψ such that (i) φ and ψ are satisfied by D w.r.t. γ, and (ii) for every model D of KB it holds that γ restricted to x, y, z is a certain answer for the query ( * ) aux q (x, y, z) ← φ , ψ. Then, q(t, z) is an answer of the above epistemic aggregate query if it is the result of the query in every model D. For formal details, we refer to the paper by Calvanese et al. (2008).
Here z φ are the variables of z that occur in φ and Cert(aux q , K)(x, y, z) refers to the certain answers of the query ( * ). Unfortunately, we cannot use ASP alone to compute the certain answers in the presence of defeasible axioms and preferences in sCKRs. However, the overall weight µ * (PK(K)) contains the information necessary to conclude what the certain answers are. These in turn can then be used to evaluate epistemic aggregates over sCKRs.

Discussion and Conclusions
We considered the application of ASP with algebraic measures for expressing preferences of defeasibility in multi-relational CKRs. The problem of representing notions of defeasibility in DLs has led to many proposals and is still an active area of research (Giordano et al. 2011;Bonatti et al. 2015;Pensel and Turhan 2018;Britz et al. 2021). A detailed comparison of justifiable exceptions with other definitions of non-monotonicity in DLs and contextual systems can be found in the papers by Bozzato et al. (2018a;2019). Our work on CKRs with multiple contextual relations was influenced by approaches dealing with exceptions under different relations or diverse definitions of normality. One of the latest in this direction is the work by Giordano and Dupré (2020), where the notion of typicality in DLs is extended to a "concept-aware multi-preference semantics": the domain elements are organized in multiple preference orderings ≤ C to represent their typicality w.r.t. a concept C; models are then ordered by a global preference combining the concept-related preferences. Similar to our approach, entailment is encoded in ASP using a fragment of Krötzsch's (2010) materialization calculus and representing combination of preferences in asprin. Gil (2014) earlier studied the effects of adding multiple preferences to a typicality extension of ALC.
Concerning semirings for general quantitative specifications, several works used semirings to define quantitative generalisations of well-known qualitative problems. For example, Semiringbased Constraint Satisfaction Problems (SCSP) (Bistarelli et al. 1999) allow for quantitative semantics of CSP's and capture other quantitative extensions of CSP's (weighted CSP) as special cases for some specific semiring. Semiring Provenance (Green et al. 2007), generalizes the bag semantics and other definitions of provenance for relational algebra to semirings: this allows one to capture existing quantitative semantics, but also to introduce additional novel capabilities to obtain the provenance lineage of a query. Moreover, algebraic ProbLog (Kimmig et al. 2011) introduced an algebraic semantics of logic programs by facilitating semirings. Intuitively, their approach can be seen as a fragment of ASP with algebraic measures allowing only a restricted use of negation in programs and no arbitrary recursive sums and products in the weighted formulas.
The parametrization of semantics with a semiring allows for flexible and highly general quantitative frameworks: in particular, algebraic measures allow for an intuitive specification of computations depending on the truth of propositional variables. Building on ASP, they offer an appealing specification language for quantitative reasoning problems like preferential reasoning.
Outlook. In the direction of using the capabilities of algebraic measures for comparing models, we plan to further study the possibilities for epistemic reasoning on DLs as introduced in previous sections. With respect to contextual reasoning, a possible continuation of this work can consider a refinement of the definitions of preference and knowledge propagation across different contextual relations, possibly by considering a motivating real-world application.

Appendix A Single-relational Example
We also give an example of a single-relational sCKR.

Example 5
We consider a single-relation hierarchy on coverage by reviewing the example from (Bozzato et al. 2019;Bozzato et al. 2018b). Let us consider a sCKR K org1 = C, K N with with C = (N, ≺ c ) describing the organization of a corporation. The corporation wants to define different policies with respect to its local branches, represented by the coverage hierarchy in C. The corporation is active in the fields of Musical instruments (M), Electronics (E) and Robotics (R). A supervisor (S) can be assigned to manage only one of these fields. Defeasible axioms in contexts in K N define the assignment of local supervisors to their field: In c world we say that supervisors are assigned to Electronics, while in the sub-context for c br2 we contradict this by assigning all local supervisors to the Robotics area and in c br1 we further specialize this by assigning supervisors to the Musical instruments area. In the context c local1 for a local site we have information about an instance i. Note that different assignments of areas for i are possible by instantiating the defeasible axioms: intuitively, we want to prefer the interpretations that override the higher defeasible axioms in c world and c br2 . Observe that different justified CAS models are possible, depending on the different assignments of the individual i in c local1 to the alternative areas denoted by defeasible axioms. We have three possible clashing assumptions sets for context c local1 : By the ordering on clashing assumption sets, in particular χ 1 c (c local1 ) > χ 2 c (c local1 ), χ 1 c (c local1 ) > χ 3 c (c local1 ) and χ 3 c (c local1 ) > χ 2 c (c local1 ). Thus, K org1 has one preferred model which corresponds to χ 1 c : it corresponds to the intended interpretation in which the defeasible axiom D(S M) associated to c br1 wins over the more general rules asserted in c br2 and c world . ♦

Appendix B ASP Translation and Rule Set Tables
We provide further details on the ASP encoding introduced in Section 5. The ASP translation is defined by adapting the encoding presented in (Bozzato et al. 2019;Bozzato et al. 2018b) (which, in turn, is based on the translation introduced in (Bozzato et al. 2018a)) to the manage the interpretation of multiple relations in simple CKRs. The ASP translation is defined for SROIQ-RLD multi-relational simple CKRs of the form K = C, K N with C = (N, ≺ t , ≺ c ), i.e. over time and coverage contextual relations.
The language of SROIQ-RLD (Bozzato et al. 2018a) restrict the form of SROIQ-RL expressions in defeasible axioms: in defeasible axioms, D D can not appear as a right-side concept and each right-side concept ∀R.D has D ∈ NC. We consider the SROIQ-RLD normal form transformation proposed in (Bozzato et al. 2018a) for the formulation of the rules (considering axioms that can appear in simple CKRs) and we assume again the Unique Name Assumption. For ease of reference, the form of (strict and defeasible) axioms in normal form is presented in Table B 1. SROIQ-RLD normal form for axioms in L Σ Strict axioms: for A, B ∈ NC, R, S, T ∈ NR, a, b ∈ NI, c ∈ N: Defeasible axioms: for A, B ∈ NC, R, S ∈ NR, a ∈ NI, rel ∈ {t, c}: Table B 1. Note that we further simplified the normalization of defeasible class and role assertions and negative assertions as they can be easily represented using defeasible class and role inclusions with auxiliary symbols. As in the original formulation (inspired by the materialization calculus in (Krötzsch 2010)), the translation includes sets of input rules I (which encode DL axioms and signature as facts), deduction rules P (normal rules providing instance level inference) and output rules O (that encode in terms of a fact the ABox assertion to be proved).
The sets of rules for the proposed translation are presented in tables in the following pages. The input rules I rl and deduction rules P rl for SROIQ-RL axioms are shown in Table B 2. Table B 3 shows input rules I glob and deduction rules P glob for the translation of the contextual structure in C local input rules I eval and deduction rules P eval for managing eval expressions, and output rules O for encoding the output instance query. Input rules I D in Table B 4 provide the encoding of defeasible axioms. Deduction rules in P D manage the interpretation of defeasible axioms and knowledge propagation. Table B 5 shows rules defining the overriding of axioms. Rules for the inheritance of strict axioms are shown in Table B 6, while rules in Table B 7 define defeasible inheritance. Table B 8 shows rules for the propagation of defeasible axioms on a relation rel1 over the other relation. Auxiliary test rules in P D are shown in Table B 9. Finally, rules and directives in P pre f define the asprin preference: the definition of asprin local and global preferences is shown in Table B 11, while rules in Table B 10 provide auxiliary rules.
Given a multi-relational sCKR K = C, K N in SROIQ-RLD normal form with C = (N, ≺ t , ≺ c ), a program PK(K) that encodes K is obtained as follows: 1. the global program for C is built as: PG(C) = I glob (C) ∪ P glob 2. for each c ∈ N, we define each local program for context c as: PC(c, K) = I loc (K c , c) ∪ P loc , where I loc (K c , c) = I rl (K c , c) ∪ I eval (K c , c) ∪ I D (K c , c) and P loc = P rl ∪ P eval ∪ P D 3. The CKR program PK(K) is defined as: PK(K) = PG(C) ∪ c∈N PC(c, K) Query answering K |= c : α is then obtained by testing whether the instance query, translated to ASP by O(α, c), is a consequence of the preferred models of PK(K), i.e., whether PK(K) ∪ instd(y, z , c,t) ← supForall(z, r, z , c), instd(x, z, c,t), tripled(x, r, y, c,t). (prl-leqone) unsat(t) ← supLeqOne(z, r, c), instd(x, z, c,t), tripled(x, r, x 1 , c,t), tripled(x, r, x 2 , c,t).
(prl-sat) ← unsat(main). P pre f |= O(α, c) holds. This can be extended to conjunctive queries Q by applying the output rules to its atoms and checking if PK(K) ∪ P pre f |= O(Q) holds.
of PK(K) with respect S. The lemma can then be proved by showing that the answer sets of PK(K) coincide with the sets S = I(Î(χ)) where χ = (χ t , χ c ) is composed by justified clashing assumptions of K.
(i). Assuming that χ = (χ t , χ c ) is justified, we show that S = I(Î(χ)) is an answer set of PK(K). We first prove that S |= G S (PK(K)), that is for every rule instance r ∈ G S (PK(K)) it holds that S |= r. This is proved by examining the possible rule forms that occur in G S (PK(K)). Here we show some representative cases (see also (Bozzato et al. 2018a A, B, c 1 , rel1), prec(c, c 2 , rel1), preceq(c 2 , c 1 , rel2), instd(a, A, c, main)} ⊆ I(Î(χ)). Since r ∈ G S (PK(K)), then test fails(nlit(a, B, c)) / ∈ I(Î(χ)). By construction of I(Î(χ)), this implies that unsat(nlit(a, B, c)) ∈ I(Î(χ)), meaning that I(c) |= ¬B(a). Thus, I(c) satisfies the clashing set {A(a), ¬B(a)} for the clashing assumption A B, a for rel1 in context c. Consequently, A B, a ∈ χ rel1 (c) and by construction ovr(subClass, a, A, B, c) is added to I(Î(χ)). -(props-subc): then {subClass(A, B, c 1 ), instd(a, A, c,t), preceq(c 2 , c 1 , rel2),    Finally, χ S = (χ S t , χ S c ) where χ S rel (c) = { α, e | I rl (α, c ) = p, ovr(p(e), c, rel) ∈ S}. We have to show that I S meets the definition of a least justifed CAS-model for a multi-relational K, that is: (i) for every α ∈ K c (strict axiom), and c * c, I S (c ) |= α; (ii) for every D i (α) ∈ K c and c −i c, I S (c ) |= α; Note that, since we are considering multi-relational CKRs based only on two relations (time and coverage), the relational closure c −i c can be read as c j c with j = i: this corresponds to the conditions preceq(c , c, rel2) with rel1 = rel2 in the formulation of the rules. Item (i) should be proved in the local case where c = c and in the "strict propagation" case where c ≺ * c. The second case can be shown similarly to the local case, considering strict propagation rules in Table B 6. Thus, considering c = c, we verify the condition by showing that, for every K c , we have I S (c) |= K c . This can be shown by cases considering the form of all of the (strict) axioms β ∈ L Σ,N that can occur in K c . For example (the other cases are similar): -Let β = A(a) ∈ K c , then, by rule (prl-instd), S |= instd(a, A, c, main). This directly implies that a I(c) ∈ A I(c) . -Let β = A B ∈ K c , then S |= subClass(A, B, c). If d ∈ A I(c) , then by definition S |= instd(d, A, c, main). By rule (prl-subc) we obtain that S |= instd (d, B, c, main) and thus d ∈ B I(c) . Condition (ii) can be proved similarly, considering rules of Table B 8. In particular, assuming that D i (β ) ∈ K c with c −i c we can proceed by cases on the possible forms of β and consider the (strict) propagation of defeasible axioms to c along the "parallel" relations. For example: -Let β = A(a). Then, by definition of the translation, we have S |= def insta (a, A, c , rel1).
To prove condition (iii), let us assume that D i (β ) ∈ K c with c ≺ i c −i c . We proceed again by cases on the possible forms of β as in the original proof in (Bozzato et al. 2018a), by considering the defeasible propagation to c along the relation i. For example: -Let β = A(a). Then, by definition of the translation, we have that S |= def insta(a, A, c , rel1).
We have shown that I S is a CAS-model of K: using the same reasoning in the original proof in (Bozzato et al. 2018a) we can also prove the I S corresponds to the least model and that χ S is justified, thus proving the result.

Lemma 2
Let K be a multi-relational sCKR in SROIQ-RLD normal form. Then,Î is a CKR model of K iff there exists a (named) justified clashing assumption χ s.t. I(Î(χ)) is a preferred answer set of PK(K) ∪ P pre f .
Proof (sketch) of Theorem 5 P 2,i ( I 1 , χ 1 , I 2 , χ 2 ) implies P 1,i ( I 1 , χ 1 , I 2 , χ 2 ). So we consider the other direction. Let I CAS be preferred with respect to P 2,i . Assume that there exists a justified model I CAS of K such that P 1,i (I CAS , I CAS ) holds.
Let I CAS = {I(c)} c∈N , χ and I CAS = {I (c)} c∈N , χ . We know there exists some c * ∈ N such that χ (c * ) > χ(c * ). This implies that some D(α) ∈ K c and e exist such that α, e ∈ χ(c * ) \ χ (c * ). Let C be the component of DEP(K) that contains X c * , where X is any concept or role appearing in α. Note that C is independent of the choice of X, since any two possible choices X, X satisfy that X c * and X c * are reachable from one another.
We take I CAS = {I (c)} c∈N , χ such that X I (c) = X I(c) for X c ∈ C and X I (c) = X I (c) otherwise, and we let χ (c) = χ(c) for c = c * and χ (c) = χ (c) otherwise. That is, we take the original justified model I CAS and swap the interpretations of all the concepts and roles that were changed in order to satisfy α(e) at context c * by their changed interpretation in I CAS . The result, I CAS , is still a model of K, as we exchanged the interpretation for the whole component and therefore any relevant axioms stay satisfied, since they were satisfied in I CAS . Furthermore, since K is eval -disconnected, χ is justified because the default D(α) does not use any concept/role X such that X c * is connected to X c such that c = c * and X is used in another default D(β ). This implies that only the clashing assumptions for c * were changed. Now, we however know that P 2,i (I CAS , I CAS ). This is a contradiction to our original assumption. Therefore, there cannot exist some I CAS such that P 1,i (I CAS , I CAS ) and I CAS is preferred with respect to P 1,i .

Proof (sketch) of Lemma 2
Our definition of the preferences in P pre f mirrors the definition of preference: both go from local preference on the clashing assumptions per context, i.e. χ i (c), to per relation preference and finally to the global preference. We show that the definitions correspond for each step.
The second item is equivalent to So, we see that the only difference between > LocPref(c,i) and the order on the context c is the first condition, i.e. that the clashing assumptions on c must be different. However, this does not affect us, since the definition of preference for justified interpretations always uses E ="χ 1 i (c) < χ 2 i (c) and not χ 2 i (c) < χ 1 i (c)". This is equivalent to "X > LocPref(c,i) Y and not Y > LocPref(c,i) X", since E can only hold when the clashing assumption sets at c w.r.t. relation i are different.
Next, we consider the preference per relation. As we have shown in Theorem 5 the preferred models with respect to the original preference relation P 1 are the same as the preferred models with respect to the preference relation P 2,i . However, as can be easily seen from the definition, P 2,i is the order that has the models that are pareto optimal with respect to the local preference orders LocPref(c,i) per context as its optimal models. We see that RelPref(i) correctly captures this, as it is the pareto combination of the orders LocPref(c,i) for each context c.
Last but not least, we consider the global preference. In our definition, we say that we prioritize the preference on the clashing assumptions with respect to the relations with a lower index. This corresponds to the lexicographical combination of the orders LocPref(i) for each relation i, when assigning the weight i to relation i, when it is the preference relation with index i.

Appendix D Proofs for Overall Weight Queries
Before we define the semiring, we ensure that the preference relation LocPref(rel) is transitive.

Lemma 3
The preference relation LocPref(rel) defined in Section 5 is transitive.
We use the transitivity of the local preference: Case 1: If α 1 , e ∈ χ 2 i (c) then since Note that this is the same situation as in case 1 except that D i (α 3 ) is at context c 3b i c such that c 1b i c 2b i c 3b . Since i is a strict (partial) order and we only have finitely many contexts this can only occur finitely often. Since in all other cases below case 1 we have that χ 1 i (c) > χ 3 i (c) we are done with case 1. Case 2: If α 1 , e ∈ χ 2 i (c) we are in a similar situation as in case 1.2 the statement follows by analogous reasoning.

Proof
As we have seen, LocPref(c,rel) is transitive for each context c and relation rel. Thus their pareto combination is also transitive.
As the domain of the semiring we choose R = {(S, χ) | S ∈ N B , χ clashing assumption multiset-map}. Here, we need S to be a multiset and χ to map to multisets of clashing assumptions for technical reasons (namely so that our semiring satisfies the distributive law). We generalize the definition of the local preference to multisets by using , if for every η = α 1 , e s.t. the multiplicity of η in χ 1 i (c) is greater than its multiplicity in χ 2 i (c) with D i (α 1 ) at a context c 1 −i c 1b i c, there exists an η = α 2 , f s.t. the multiplicity of η in χ 2 i (c) is greater than its multiplicity in χ 1 i (c) with D i (α 2 ) at context c 2 −i c 2b i c such that c 1b i c 2b .
Theorem 6 R one (K) is a semiring and the overall weight of µ = PK(K), α one , R one (K) is (I, χ), where I is the minimum lexicographical preferred model of K and χ its clashing assumption map or 0 0 0 if there is no preferred model.

Proof
Associativity of ⊕ follows from transitivity of LocPref(c,rel) and the lexicographical order. Commutativity of ⊕ is clear. 0 and 1 are identities and annihilators of ⊗, ⊕ by definition. Associativity of ⊗ is clear. It remains to prove that multiplication distributes over addition. So let A i = (I i , χ i ) for i = 1, 2, 3. Then, in the expression Assume w.l.o.g. that (A 2 ⊕ A 3 ) evaluates to A 2 . If A 2 > LocPref(rel) A 3 then there exists a context c such that χ 2 (c) > LocPref(c,rel) χ 3 (c). Then it also holds that (χ 1 + χ 2 )(c) > LocPref(c,rel) (χ 1 + χ 3 )(c) and thus If A 2 > LocPref(rel) A 3 this implies that A 2 is either equal to A 3 (in this case we are done) or that A 2 is smaller lexicographically. In the latter case the sum A 1 ⊗ A 2 is however also lexicographically smaller than A 1 ⊗ A 3 since we add A 1 both times.

Reasoning on Multi-Relational Contextual Hierarchies via ASP with Algebraic Measures 31
Thus we have established that R one (K) is a semiring. For each answer set I of PK(K), we know that I corresponds to a (least) CAS model. Thus, α one R one (I) = (I, χ), where I ∈ {0, 1} B and χ only maps to multisets that can be interpreted as sets (i.e. each of their elements has at most multiplicity one). The lexicographical minimum CKR model I * , χ * satisfies that (I, χ) ⊕ (I * , χ * ) = (I * , χ * ) for all (I, χ) that are the semantics of α one w.r.t. some answer set of PK(K). Therefore, if there exists a CKR model, the overall weight is (I * , χ * ). Otherwise, it is 0.
We continue with the R all semiring. Again, we need some additional lemma

Lemma 5
Let K be a single relational sCKR without eval expressions. Then a CAS model ({I(c)} c∈N , χ) is a CKR model iff no CAS model ({I c } c∈N , χ ) and c ∈ N exist such that χ (c) > χ(c).
Therefore, we can take the locally optimal models I(c) for each context c and obtain the global optimal models as arbitrary combinations of locally preferred models.
In the following, we let D be the Herbrand base.
Using this notation, we define the semiring R c = (R c , ⊕ c , ⊗ c , e ⊕ , e ⊗ ) that collects all locally optimal models I(c). Here, where pclash(c) is the set of all possible clashing assumptions α, e for c. We obtain Theorem 7 R c is a semiring and the overall weight µ c (PK(K)) is equal to the set containing for each locally optimal interpretation I(c) of K the pair (I(c), χ I(c) ), where χ I(c) is the unique multiset containing each justified clashing assumption of I(c) once.
We take R all to be the crossproduct semiring (R c ) c∈N defined by Using it, we can obtain the locally optimal interpretations for each context as the crossproduct of measures µ * = (µ c ) c∈N which is a measure over the crossproduct semiring (R c ) c∈N . As we have shown in Lemma 5, this gives us all the preferred models. Namely, let µ * (PK(K)) = (A c ) c∈N , then {(I(c)) c∈N | (I(c), χ(c)) ∈ A c } is the set of preferred models.

Example 6
The sCKR K defined in Example 5 has five contexts c world , c branch1 , c branch2 , c local1 , and c local2 . Therefore, the measure µ * is a crossproduct of the five measures µ c world , µ c branch1 , µ c branch2 , µ c local1 and µ c local2 . Their overall weight is given by c world (PK(K)) = µ c branch1 (PK(K)) = µ c branch2 (PK(K)) = µ c local2 (PK(K)) = Let K be a single-relational, eval -free sCKR, then R all is a semiring and the overall weight of µ all = PK(K), α all , R all (K) is (A c ) c∈N and the set of preferred models corresponds to {(I(c)) c∈N | for each c ∈ N : (I(c), χ(c)) ∈ A c }.

Proof
The reasoning that R all is a semiring is along the same lines as that for R one . The fact that the result is as desired can be clearly seen during the construction of the semiring.