\subsection{Possible Queries} \label{queries} TRILL can compute the probability or find an explanation of the following queries: \begin{itemize} \item Concept membership queries. \item Property assertion queries. \item Subsumption queries. \item Unsatifiability of a concept. \item Inconsistency of the knowledge base. \end{itemize} All the input arguments must be atoms or ground terms. \subsubsection{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 \begin{verbatim} prob_instanceOf(+Concept:term,+Individual:atom,-Prob:double) \end{verbatim} as in (\href{http://trill-sw.eu/example/trill/peoplePets.pl}{\texttt{peoplePets.pl}}) \begin{verbatim} ?- prob_instanceOf(cat,'Tom',Prob). \end{verbatim} The probability of two individuals to be related by a role can be computed with \begin{verbatim} prob_property_value(+Prop:atom,+Individual1:atom, +Individual2:atom,-Prob:double) \end{verbatim} as in (\href{http://trill-sw.eu/example/trill/peoplePets.pl}{\texttt{peoplePets.pl}}) \begin{verbatim} ?- prob_property_value(has_animal,'Kevin','Tom',Prob). \end{verbatim} If you want to know the probability with which a class is a subclass of another you have to use \begin{verbatim} prob_sub_class(+Concept:term,+SupConcept:term,-Prob:double) \end{verbatim} as in (\href{http://trill-sw.eu/example/trill/peoplePets.pl}{\texttt{peoplePets.pl}}) \begin{verbatim} ?- prob_sub_class(cat,pet,Prob). \end{verbatim} The probability of the unsatisfiability of a concept can be asked with the predicate \begin{verbatim} prob_unsat(+Concept:term,-Prob:double) \end{verbatim} as in (\href{http://trill-sw.eu/example/trill/peoplePets.pl}{\texttt{peoplePets.pl}}) \begin{verbatim} ?- prob_unsat(intersectionOf([cat,complementOf(pet)]),P). \end{verbatim} 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 of the inconsistency of the knowledge base with \begin{verbatim} prob_inconsistent_theory(-Prob:double) \end{verbatim} \subsubsection{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 \begin{verbatim} instanceOf(+Concept:term,+Individual:atom) instanceOf(+Concept:term,+Individual:atom,-Expl:list) \end{verbatim} as in (\href{http://trill-sw.eu/example/trill/peoplePets.pl}{\texttt{peoplePets.pl}}) \begin{verbatim} ?- instanceOf(pet,'Tom'). ?- instanceOf(pet,'Tom',Expl). \end{verbatim} In the first query the result is \verb|true| because Tom belongs to cat, in the second case TRILL returns the explanation \begin{verbatim} [classAssertion(cat,'Tom'), subClassOf(cat,pet)] \end{verbatim} Similarly, to ask whether two individuals are related by a role you have to use the queries \begin{verbatim} property_value(+Prop:atom,+Individual1:atom,+Individual2:atom) property_value(+Prop:atom,+Individual1:atom, +Individual2:atom,-Expl:list) \end{verbatim} as in (\href{http://trill-sw.eu/example/trill/peoplePets.pl}{\texttt{peoplePets.pl}}) \begin{verbatim} ?- property_value(has_animal,'Kevin','Tom'). ?- property_value(has_animal,'Kevin','Tom',Expl). \end{verbatim} If you want to know if a class is a subclass of another you have to use \begin{verbatim} sub_class(+Concept:term,+SupConcept:term) sub_class(+Concept:term,+SupConcept:term,-Expl:list) \end{verbatim} as in (\href{http://trill-sw.eu/example/trill/peoplePets.pl}{\texttt{peoplePets.pl}}) \begin{verbatim} ?- sub_class(cat,pet). ?- sub_class(cat,pet,Expl). \end{verbatim} The unsatisfiability of a concept can be asked with the predicate \begin{verbatim} unsat(+Concept:term) unsat(+Concept:term,-Expl:list) \end{verbatim} as in (\href{http://trill-sw.eu/example/trill/peoplePets.pl}{\texttt{peoplePets.pl}}) \begin{verbatim} ?- unsat(intersectionOf([cat,complementOf(pet)])). ?- unsat(intersectionOf([cat,complementOf(pet)]),Expl). \end{verbatim} In this case, the returned explanation is the same obtained by querying if cat is subclass of pet with the \verb|sub_class/3| predicate, i.e., \verb|[subClassOf(cat,pet)]| Finally, you can ask about the inconsistency of the knowledge base with \begin{verbatim} inconsistent_theory inconsistent_theory(-Expl:list) \end{verbatim} The predicate above returns explanations one at a time. To collect all the explanations with a single goal you can use the predicates: \begin{verbatim} all_instanceOf(+Concept:term,+Individual:atom,-Expl:list) all_property_value(+Prop:atom,+Individual1:atom, +Individual2:atom,-Expl:list) all_sub_class(+Concept:term,+SupConcept:term,-Expl:list) all_unsat(+Concept:term,-Expl:list) all_inconsistent_theory(-Expl:list) \end{verbatim} \subsection{Query Options} The behaviour of the queries can be fine tuned using the \emph{query options}. To use them you need to use the predicates: \begin{verbatim} instanceOf(+Concept:term,+Individual:atom,-Expl:list,-QueryOptions:list) property_value(+Prop:atom,+Individual1:atom, +Individual2:atom,-Expl:list,-QueryOptions:list) sub_class(+Concept:term,+SupConcept:term,-Expl:list,-QueryOptions:list) unsat(+Concept:term,-Expl:list,-QueryOptions:list) inconsistent_theory(-Expl:list,-QueryOptions:list) \end{verbatim} Options can be: \begin{itemize} \item \verb|assert_abox(Boolean)| if Boolean is set to true the list of ABoxes is asserted with the predicate \verb|final_abox/1|; \item \verb|return_prob(Prob)| if present the probability of the query is computed and unified with \verb|Prob|; % \item \verb|return_single_prob(Boolean)| must be used with \verb|return_prob(Prob)|. It forces TRILL to return the probability of each single explanation; \item \verb|max_expl(Value)| to limit the maximum number of explanations to find. \verb|Value| must be an integer. The predicate will return a list containing at most \verb|Value| different explanations; \item \verb|time_limit(Value)| to limit the time for the inference. The predicate will return the explanations found in the time allowed. \verb|Value| is the number of seconds allowed for the search of explanations . \end{itemize} For example, if you want to find the probability of the query $Q=kevin:PetOwner$ computed on at most 2 explanations allowing at most 1 second for the explanations search you can use the goal \begin{verbatim} instanceOf('natureLover','Kevin',Expl, [time_limit(1),return_prob(Prob),max_expl(2)]). \end{verbatim} \subsection{TRILL Useful Predicates} There are other predicates defined in TRILL which helps manage and load the KB. \begin{verbatim} add_kb_prefix(++ShortPref:string,++LongPref:string) add_kb_prefixes(++Prefixes:list) \end{verbatim} They register the alias for prefixes. The firs registers \verb|ShortPref| for the prefix \verb|LongPref|, while the second register all the alias prefixes contained in Prefixes. The input list must contain pairs alias=prefix, i.e., \verb|[('foo'='http://example.foo#')]|. In both cases, the empty string \verb|''| can be defined as alias. The predicates \begin{verbatim} remove_kb_prefix(++ShortPref:string,++LongPref:string) remove_kb_prefix(++Name:string) \end{verbatim} remove from the registered aliases the one given in input. In particular, \verb|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. \begin{verbatim} add_axiom(++Axiom:axiom) add_axioms(++Axioms:list) \end{verbatim} These predicates add (all) the given axiom to the knowledge base. While, to remove axioms can be similarly used the predicates \begin{verbatim} remove_axiom(++Axiom:axiom) remove_axioms(++Axioms:list) \end{verbatim} All the axioms must be defined following the TRILL syntax. We can interrogate TRILL to return the loaded axioms with \begin{verbatim} axiom(?Axiom:axiom) \end{verbatim} This predicate searches in the loaded knowledge base axioms that unify with Axiom.