Syntax

Description Logics (DLs) are knowledge representation formalisms that are at the basis of the Semantic Web [3,4] and are used for modeling ontologies. They are represented using a syntax based on concepts, basically sets of individuals of the domain, and roles, sets of pairs of individuals of the domain. In this section, we recall the expressive description logic \(\mathcal{ALC}\)[17]. We refer to [10] for a detailed description of \(\mathcal{SHOIN}(\mathbf{D})\) DL, that is at the basis of OWL DL.

Let \(\mathbf{A}\), \(\mathbf{R}\) and \(\mathbf{I}\) be sets of atomic concepts, roles and individuals. A role is an atomic role \(R \in \mathbf{R}\). Concepts are defined by induction as follows. Each \(C \in \mathbf{A}\), \(\bot\) and \(\top\) are concepts. If \(C\), \(C_1\) and \(C_2\) are concepts and \(R \in \mathbf{R}\), then \((C_1\sqcap C_2)\), \((C_1\sqcup C_2 )\), \(\neg C\), \(\exists R.C\), and \(\forall R.C\) are concepts. Let \(C\), \(D\) be concepts, \(R \in \mathbf{R}\) and \(a, b \in \mathbf{I}\). An ABox\({{\cal A}}\) is a finite set of concept membership axioms\(a : C\) and role membership axioms\((a, b) : R\), while a TBox\({{\cal T}}\) is a finite set of concept inclusion axioms\(C\sqsubseteq D\). \(C \equiv D\) abbreviates \(C \sqsubseteq D\) and \(D\sqsubseteq C\).

A knowledge base\({{\cal K}}= ({{\cal T}}, {{\cal A}})\) consists of a TBox \({{\cal T}}\) and an ABox \({{\cal A}}\). A KB \({{\cal K}}\) is assigned a semantics in terms of set-theoretic interpretations \({{\cal I}}= (\Delta^{{\cal I}}, \cdot^{{\cal I}})\), where \(\Delta^{{\cal I}}\) is a non-empty domain and \(\cdot^{{\cal I}}\) is the interpretation function that assigns an element in \(\Delta ^{{\cal I}}\) to each \(a \in \mathbf{I}\), a subset of \(\Delta^{{\cal I}}\) to each \(C \in \mathbf{A}\) and a subset of \(\Delta^{{\cal I}}\times \Delta^{{\cal I}}\) to each \(R \in \mathbf{R}\).

TRILL allows the use of two different syntaxes used together or individually:

RDF/XML

Prolog syntax

RDF/XML syntax can be used by exploiting the predicate owl_rdf/1. For example:

For a brief introduction on RDF/XML syntax see RDF/XML syntax and tools section below (Sec. [rdfxml-syn]).

Note that each single owl_rdf/1 must be self contained and well formatted, it must start and end with rdf:RDF tag and contain all necessary declarations (namespaces, entities, ...).

An example of the combination of both syntaxes is shown the example johnEmployee.pl. It models that john is an employee and that employees are workers, which are in turn people (modeled by the concept person).

The first axiom states that fluffy is a Cat. The second states that every Cat is also a Pet. The third states that the role hasAnimal links together kevin and fluffy.

RDF (Resource Descritpion Framework) is a standard W3C. See the syntax specification for more details. RDF is a standard XML-based used for representing knowledge by means of triples. A representations of the three axioms seen above is shown below.

Semantics

In the field of Probabilistic Logic Programming (PLP for short) many proposals have been presented. An effective and popular approach is the Distribution Semantics [14], which underlies many PLP languages such as PRISM [14,15], Independent Choice Logic [12], Logic Programs with Annotated Disjunctions [19] and ProbLog [5]. Along this line, many reserchers proposed to combine probability theory with Description Logics (DLs for short) [10,18]. DLs are at the basis of the Web Ontology Language (OWL for short), a family of knowledge representation formalisms used for modeling information of the Semantic Web

TRILL follows the DISPONTE [13,21] semantics to compute the probability of queries. DISPONTE applies the distribution semantics [14] of probabilistic logic programming to DLs. A program following this semantics defines a probability distribution over normal logic programs called worlds. Then the distribution is extended to queries and the probability of a query is obtained by marginalizing the joint distribution of the query and the programs.

In DISPONTE, a probabilistic knowledge base\({{\cal K}}\) is a set of certain axioms or probabilistic axioms in which each axiom is independent evidence. Certain axioms take the form of regular DL axioms while probabilistic axioms are \(p::E\) where \(p\) is a real number in \([0,1]\) and \(E\) is a DL axiom.

The idea of DISPONTE is to associate independent Boolean random variables to the probabilistic axioms. To obtain a world, we include every formula obtained from a certain axiom. For each probabilistic axiom, we decide whether to include it or not in \(w\). A world therefore is a non probabilistic KB that can be assigned a semantics in the usual way. A query is entailed by a world if it is true in every model of the world.

The probability \(p\) can be interpreted as an epistemic probability, i.e., as the degree of our belief in axiom \(E\). For example, a probabilistic concept membership axiom \(
p::a:C
\) means that we have degree of belief \(p\) in \(C(a)\). A probabilistic concept inclusion axiom of the form \(
p::C\sqsubseteq D
\) represents our belief in the truth of \(C \sqsubseteq D\) with probability \(p\).

Formally, an atomic choice is a couple \((E_i,k)\) where \(E_i\) is the \(i\)th probabilistic axiom and \(k\in \{0,1\}\). \(k\) indicates whether \(E_i\) is chosen to be included in a world (\(k\) = 1) or not (\(k\) = 0). A composite choice\(\kappa\) is a consistent set of atomic choices, i.e., \((E_i,k)\in\kappa, (E_i,m)\in \kappa\) implies \(k=m\) (only one decision is taken for each formula). The probability of a composite choice \(\kappa\) is \(P(\kappa)=\prod_{(E_i,1)\in \kappa}p_i\prod_{(E_i, 0)\in \kappa} (1-p_i)\), where \(p_i\) is the probability associated with axiom \(E_i\). A selection\(\sigma\) is a total composite choice, i.e., it contains an atomic choice \((E_i,k)\) for every probabilistic axiom of the probabilistic KB. A selection \(\sigma\) identifies a theory \(w_\sigma\) called a world in this way: \(w_\sigma={{\cal C}}\cup\{E_i|(E_i,1)\in \sigma\}\) where \({{\cal C}}\) is the set of certain axioms. Let us indicate with \(\mathcal{S}_{{\cal K}}\) the set of all selections and with \(\mathcal{W}_{{\cal K}}\) the set of all worlds. The probability of a world \(w_\sigma\) is \(P(w_\sigma)=P(\sigma)=\prod_{(E_i,1)\in \sigma}p_i\prod_{(E_i, 0)\in \sigma} (1-p_i)\). \(P(w_\sigma)\) is a probability distribution over worlds, i.e., \(\sum_{w\in \mathcal{W}_{{\cal K}}}P(w)=1\).

We can now assign probabilities to queries. Given a world \(w\), the probability of a query \(Q\) is defined as \(P(Q|w)=1\) if \(w\models Q\) and 0 otherwise. The probability of a query can be defined by marginalizing the joint probability of the query and the worlds, i.e. \(P(Q)=\sum_{w\in \mathcal{W}_{{\cal K}}}P(Q,w)=\sum_{w\in \mathcal{W}_{{\cal K}}} P(Q|w)p(w)=\sum_{w\in \mathcal{W}_{{\cal K}}: w\models Q}P(w)\).

The KB has four worlds and the query axiom \(Q=kevin:NatureLover\) is true in one of them, the one corresponding to the selection \(
\{(F_1,1),(F_2,1)\}
\). The probability of the query is \(P(Q)=0.5\cdot 0.6=0.3\).

[people+pets_comb]

Sometimes we have to combine knowledge from multiple, untrusted sources, each one with a different reliability. Consider a KB similar to the one of Example [people+petsxy] but where we have a single cat, \({{\mathit{fluffy}}}\). \(\exists hasAnimal.Pet \sqsubseteq NatureLover\ \ \ \ \ (kevin,{{\mathit{fluffy}}}):hasAnimal\ \ \ \ \ Cat\sqsubseteq Pet\)

and there are two sources of information with different reliability that provide the information that \({{\mathit{fluffy}}}\) is a cat. On one source the user has a degree of belief of 0.4, i.e., he thinks it is correct with a 40% probability, while on the other source he has a degree of belief 0.3. The user can reason on this knowledge by adding the following statements to his KB: \(0.4\ \ ::\ \ {{\mathit{fluffy}}}: Cat\ \ \ \ \ 0.3\ \ ::\ \ {{\mathit{fluffy}}}: Cat\) The two statements represent independent evidence on \({{\mathit{fluffy}}}\) being a cat. We associate \(F_1\) (\(F_2\)) to the first (second) probabilistic axiom.

The query axiom \(Q=kevin:NatureLover\) is true in 3 out of the 4 worlds, those corresponding to the selections \(
\{ \{(F_1,1),(F_2,1)\},
\{(F_1,1),(F_2,0)\},
\{(F_1,0),(F_2,1)\}\}
\). So \(P(Q)=0.4\cdot 0.3+0.4\cdot 0.7+ 0.6\cdot 0.3=0.58.\) This is reasonable if the two sources can be considered as independent. In fact, the probability comes from the disjunction of two independent Boolean random variables with probabilities respectively 0.4 and 0.3: \(
P(Q) = P(X_1\vee X_2) = P(X_1)+P(X_2)-P(X_1\wedge X_2)
= P(X_1)+P(X_2)-P(X_1)P(X_2)
= 0.4+0.3-0.4\cdot 0.3=0.58
\)

Inference

Traditionally, a reasoning algorithm decides whether an axiom is entailed or not by a KB by refutation: the axiom \(E\) is entailed if \(\neg E\) has no model in the KB. Besides deciding whether an axiom is entailed by a KB, we want to find also explanations for the axiom, in order to compute the probability of the axiom.

Computing Queries Probability

The problem of finding explanations for a query has been investigated by various authors [6–9,16,21]. It was called axiom pinpointing in [16] and considered as a non-standard reasoning service useful for tracing derivations and debugging ontologies. In particular, in [16] the authors define minimal axiom sets (MinAs for short).

Let \({{\cal K}}\) be a knowledge base and \(Q\) an axiom that follows from it, i.e., \({{\cal K}}\models Q\). We call a set \(M\subseteq {{\cal K}}\) a minimal axiom set or MinA for \(Q\) in \({{\cal K}}\) if \(M \models Q\) and it is minimal w.r.t. set inclusion.

The problem of enumerating all MinAs is called min-a-enum. All-MinAs(\(Q,{{\cal K}}\)) is the set of all MinAs for query \(Q\) in knowledge base \({{\cal K}}\).

A tableau is a graph where each node represents an individual \(a\) and is labeled with the set of concepts \({{\cal L}}(a)\) it belongs to. Each edge \(\langle a, b\rangle\) in the graph is labeled with the set of roles to which the couple \((a, b)\) belongs. Then, a set of consistency preserving tableau expansion rules are repeatedly applied until a clash (i.e., a contradiction) is detected or a clash-free graph is found to which no more rules are applicable. A clash is for example a couple \((C, a)\) where \(C\) and \(\neg C\) are present in the label of a node, i.e. \({C, \neg C} \subseteq {{\cal L}}(a)\).

Some expansion rules are non-deterministic, i.e., they generate a finite set of tableaux. Thus the algorithm keeps a set of tableaux that is consistent if there is any tableau in it that is consistent, i.e., that is clash-free. Each time a clash is detected in a tableau \(G\), the algorithm stops applying rules to \(G\). Once every tableau in \(T\) contains a clash or no more expansion rules can be applied to it, the algorithm terminates. If all the tableaux in the final set \(T\) contain a clash, the algorithm returns unsatisfiable as no model can be found. Otherwise, any one clash-free completion graph in \(T\) represents a possible model for the concept and the algorithm returns satisfiable.

To compute the probability of a query, the explanations must be made mutually exclusive, so that the probability of each individual explanation is computed and summed with the others. To do that we assign independent Boolean random variables to the axioms contained in the explanations and defining the Disjunctive Normal Form (DNF) Boolean formula \(f_K\) which models the set of explanations. Thus \(
f_K(\mathbf{X})=\bigvee_{\kappa\in K}\bigwedge_{(E_i,1)}X_{i}\bigwedge_{(E_i,0)}\overline{X_{i}}
\) where \(\mathbf{X}=\{X_{i}|(E_i,k)\in\kappa,\kappa\in K\}\) is the set of Boolean random variables. We can now translate \(f_K\) to a Binary Decision Diagram (BDD), from which we can compute the probability of the query with a dynamic programming algorithm that is linear in the size of the BDD.

In [1,2] the authors consider the problem of finding a pinpointing formula instead of All-MinAs(\(Q,{{\cal K}}\)). The pinpointing formula is a monotone Boolean formula in which each Boolean variable corresponds to an axiom of the KB. This formula is built using the variables and the conjunction and disjunction connectives. It compactly encodes the set of all MinAs. Let’s assume that each axiom \(E\) of a KB \({{\cal K}}\) is associated with a propositional variable, indicated with \(var(E)\). The set of all propositional variables is indicated with \(var({{\cal K}})\). A valuation \(\nu\) of a monotone Boolean formula is the set of propositional variables that are true. For a valuation \(\nu \subseteq var({{\cal K}})\), let \({{\cal K}}_{\nu} := \{t \in {{\cal K}}|var(t)\in\nu\}\).

Given a query \(Q\) and a KB \({{\cal K}}\), a monotone Boolean formula \(\phi\) over \(var({{\cal K}})\) is called a pinpointing formula for \(Q\) if for every valuation \(\nu \subseteq var({{\cal K}})\) it holds that \({{\cal K}}_{\nu} \models Q\) iff \(\nu\) satisfies \(\phi\).

In Lemma 2.4 of [2] the authors proved that the set of all MinAs can be obtained by transforming the pinpointing formula into a Disjunctive Normal Form Boolean formula (DNF) and removing disjuncts implying other disjuncts.

Irrespective of which representation of the explanations we choose, a DNF or a general pinpointing formula, we can apply knowledge compilation and transform it into a Binary Decision Diagram (BDD), from which we can compute the probability of the query with a dynamic programming algorithm that is linear in the size of the BDD.

Possible Queries

TRILL can compute the probability or find an explanation of the following queries:

Concept membership queries.

Property assertion queries.

Subsumption queries.

Unsatifiability of a concept.

Inconsistency of the knowledge base.

All the input arguments have to be atoms or ground terms. Note that it is necessary to specify which algorithm, TRILL, TRILL\(^P\) or TORNADO, has to be loaded for performing inference. This is done by using at the beginning of the input file the directive

:- trill.

for loading TRILL,

:- trillp.

for TRILL\(^P\) or

:- tornado.

for TORNADO.

Probabilistic Queries

TRILL can be queried for computing the probability of queries. A resulting 0 probaility means that the query is false w.r.t. the knowledge base, while a probability value 1 that the query is certainly true.

The probability of an individual to belong to a concept can be asked using TRILL with the predicate

This query for example corresponds with a subsumption query, which is represented as the intersection of the subclass and the complement of the superclass.

Finally, you can ask the probability if the inconsistency of the knowledge base with

prob_inconsistent_theory(+Print:boolean,-Prob:double)

The first argument takes values true or false. This will affect the behavior of the predicate when the KB is consistent. In this case, if Print is true the predicate prints a message and succeeds returning 0.0 as probability, if Print is false it fails.

NOTE: For versions below 5.0.0 this predicates does not work. You have to use predicate

prob_inconsistent_theory(-Prob:double)

Non Probabilistic Queries

In TRILL you can also ask whether a query is true or false w.r.t. the knowledge base and in case of a succesful query an explanation can be returned as well. Query predicates in this case differs in the number of arguments, in the second case, when we want also an explanation, an extra argument is added to unify with the list of axioms build to explain the query.

The query if an individual belongs to a concept can be used the predicates

The argument Print takes values true or false. This will affect the behavior of the predicate when the KB is consistent. In this case, if Print is true the predicate prints a message and succeeds (returning an empty explanation in the second case), if Print is false it fails.

NOTE: For versions below 5.0.0 this predicates does not work. You have to use predicate

inconsistent_theory
inconsistent_theory(-Expl:list)

TRILL Useful Predicates

There are other predicates defined in TRILL which helps manage and load the KB.

They register the alias for prefixes. The firs registers ShortPref for the prefix LongPref, while the second register all the alias prefixes contained in Prefixes. The input list must contain pairs alias=prefix, i.e., [('foo'='http://example.foo#')]. In both cases, the empty string '' can be defined as alias. The predicates

remove from the registered aliases the one given in input. In particular, remove_kb_prefix/1 takes as input a string that can be an alias or a prefix and removes the pair containing the string from the registered aliases.

add_axiom(++Axiom:axiom)
add_axioms(++Axioms:list)

These predicates add (all) the given axiom to the knowledge base. While, to remove axioms can be similarly used the predicates

remove_axiom(++Axiom:axiom)
remove_axioms(++Axioms:list)

All the axioms must be defined following the TRILL syntax.

Finally, we can interrogate TRILL to return the loaded axioms with

axiom(?Axiom:axiom)

This predicate searches in the loaded knowledge base axioms that unify with Axiom.

Download Query Results through an API

The results of queries can also be downloaded programmatically by directly approaching the Pengine API. Example client code is available. For example, the swish-ask.sh client can be used with bash to download the results for a query in CSV. The call below downloads a CSV file for the coin example.

Results can be downloaded in JSON using the option --json-s or --json-html. With the first the output is in a simple string format where Prolog terms are sent using quoted write, the latter serialize responses as HTML strings. E.g.