0

I got a little problem. I got a Prolog query which "return" the value I want but then as the second value i want it to return true or false. My other queries all work fine but this one doesn't.

Thats what i get:

queryA(T).
T = [..].

thats what I need:

queryA(T).
T = [..];
false/true.

I hope you can help me. Thanks!

Edit:

the Prolog code: finds all feature structure records (represented as lists in prolog [attribute:value,attribute:value,...]) in the knowledge base, and "returns" the smallest record which is bigger than the OldEvent or the OldEvent if there is no smaller value.

turnEventNotAlreadyUsed(Event, OldEvent) :-
    findall(R,
          (  fsr(R),
             type(R, turnEvent)
           ),
            List),
    list_min(List,OldEvent, Event).

if there is no OldEvent (OldEvent has the value : "unknown") then just take the latest feature structure record.

list_min([X], _, X).       % X is min for single list, [X]
list_min(X,OldEvent,MinFSR):-           
   OldEvent = "unknown",
   latest(MinFSR, X),
   !.

%   [...]

latest(R, [R]) :- !.
latest(R, [H|T]) :-
   latest(L, T),
   (  after(L, H), !, R = L
   ;  after(H, L), !, R = H
   ).

I'm not happy withOldEvent = "unknown" either, how can I check whether OldEvent is a normal String or a List?

false
  • 10,264
  • 13
  • 101
  • 209
Tim
  • 193
  • 4
  • 15
  • 1
    Do you want to reify the query success? – Paulo Moura Mar 09 '15 at 11:50
  • 2
    `true` it's implicit when you get an answer – CapelliC Mar 09 '15 at 11:50
  • I need the true or false answer, because the java program which is using this query tries to get more answers until it gets true or false. I can't change anything at this java method. – Tim Mar 09 '15 at 11:54
  • The Java lib call to the predicate should return true or false, shouldn't it? Can you indicate which lib call you are using? Are you just having an issue with queries that result in more than one solution? – lurker Mar 09 '15 at 12:02
  • I edited the question and added the Prolog code, I hope it is not to complicated and you can understand it. – Tim Mar 09 '15 at 12:13
  • 2
    FYI, in Prolog a string (delimited with double quotes, `"abc"`) *is* a list (of character codes). So if you queried `is_list("unknown")`, it would be true. And you didn't answer my question about what the Java lib and API call are. – lurker Mar 09 '15 at 12:29
  • yeah, I know that I can't use is_list as it is true for the string as well. that's why I use the OldEvent = "unknown". The program uses the jpl package. – Tim Mar 09 '15 at 12:48
  • Back to your original problem, *all* queries in prolog are true or false. So the issue is somewhere in how the API call is being handled and understanding what/how it returns results. You have no information in your question about the API call. – lurker Mar 09 '15 at 13:37
  • Even if I call this in the SWI-Prolog-Editor it doesn't return true or false. – Tim Mar 09 '15 at 13:55
  • As @CapelliC says, it's implicitly true when you get an answer. Try at the Prolog prompt: `queryA(T), write('it is true'), nl.`. If you see "it is true" then it's true. It has to be true for the `write` to occur. – lurker Mar 09 '15 at 14:02

0 Answers0