Answer Set Programming - How to count number of facts appears to be my query result?

1.3k views Asked by At

So I have a set of facts and a query written in ASP to be run on DLV,

%Q1 : Find the implicit "is_a" relationship between terms
%ex: if term A is is_a term B, term B is_a term C, then term A is_a term C  
%is_a One level
    triple1(TermA, "go:is_a", TermB):- triple(TermA, "go:is_a", TermB), TermA != TermB.
%is_a MultiLevel
triple1(TermA, "go:is_a", TermC) :-
    triple(TermA, "go:is_a", TermB),
    triple(TermB, "go:is_a", TermC),
    TermA != TermC.
triple1(TermA, "go:is_a", TermC) :-
    triple1(TermA, "go:is_a", TermB),
    triple1(TermB, "go:is_a", TermC),
    TermA != TermC.

then I want to count how many of triple1 triples are in my answer set not included the facts. then I made this kind of aggregate #count query:

triple1nr(X) :- #count{TermA : triple1(TermA,"go:is_a",TermC)} = X. 

but what I obtained was only the number of variable TermA appear as my result. And when I changed my query as this:

triple1nr(X) :- #count{triple1(TermA,"go:is_a",TermC)} = X. 

it gives me error. How should I do this query?

1

There are 1 answers

0
vukk On BEST ANSWER

Based on knowledge of other solvers, I'm guessing your code is not counting the combinations of TermA and TermC, it is ignoring TermC variations. You need to tell it it count the combinations.

triple1nr(X) :- #count{TermA,TermC : triple1(TermA,"go:is_a",TermC)} = X.

But I do not use dlv, and I do not have it installed, so this answer might be wrong. Please test it yourself.