users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Counting the solutions....


From: gowtham
Subject: Counting the solutions....
Date: Wed, 27 Oct 2010 14:03:35 -0700


Hi All,
Bear with this newbie. I come from procedural programming and started to learn prolog a week ago. Though, I really appreciate its amazing capacity, i am still struggling to learn the basics.

My quaries are getting the solutions but, i have problem in counting the solutions. 

My knowledgebase has fact like following....

node('LmjF01.0010').
node('LmjF01.0020').
node('LmjF01.0030').
 prop('LmjF01.0010', is_coding, 'YES').
 prop('LmjF01.0010', is_coding, 'YES').
 prop('LmjF01.0010', is_coding, 'NO').
prop('LmjF01.0010', located_on, 'Lmjchr1').
prop('LmjF01.0010', located_on, 'Lmjchr1').
prop('LmjF01.0010', located_on, 'Lmjchr2').

function:
%count protein coding genes from GFF
count_pcg0(X) :-
Goal= prop(X, is_coding, 'YES'),
counter(Goal, N),
fail. 

It counts and gives me the actual count in numbers.

But, when I add more conditions to it, It returns 1 or 0 depending on if it fails or passes. 
For example,
count_pcg(X) :-
node(X),
prop(X, is_coding, 'YES'),
G2 = prop(X, located_on, 'Lmjchr1'),
counter(G2, N),
fail. 


%---------------------------------------
% Basic Functions
%---------------------------------------
counter(Goal, N) :-
   flag(counter, Outer, 0),
 (
    call(Goal),
    flag(counter, Inner, Inner+1),
    fail;
    flag(counter, Count, Outer),
    N = Count,
    write(N)
).






_______________________________________________
Users-prolog mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/users-prolog


Thanks a lot , 
I'll really appreciate your help

--
Gowthaman

Bioinformatics Systems Programmer.
SBRI, 307 West lake Ave N Suite 500
Seattle, WA. 98109-5219
Phone : LAB 206-256-7188 (direct).

reply via email to

[Prev in Thread] Current Thread [Next in Thread]