Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Prolog - Frame Inheritance and Loop Detection
Closed Thread
Old 03-28-2007, 12:47 PM   #1 (permalink)
 
Newb Techie

Join Date: Mar 2006

Posts: 22

SmallGods

Default Prolog - Frame Inheritance and Loop Detection

Hopefully theres got to be at least one person out there that knows a little bit about Prolog. I'll admit straight up that this is a coursework problem, but I'm stuck right at the end, and the error is so stupid, I just can't quite work it out..

Incidently, I'm using SWI-Prolog for this. The shortened version of my code is as follows.


frame(bird, subclass_of(animal), [beak, feathers]).
frame(flying_bird, subclass_of(bird),[]).
frame(canary, subclass_of(flying_bird), [colour(yellow)]).
frame(tweetie, instance_of(canary), [cage(blue),type(cage, colour)]).

This is a sample of a tree structure involving various animals. The above is all thats needed to demonstrate this really..



fask(Name, Value, Accum,[Name|Accum]):-
frame(Name,_,List),
member(Value, List),
write('Accum is: '), write(Accum).

fask(Name, Value, Accum, [Name|History]):-
frame(Name, instance_of(Sometype),_),
fask(Sometype, Value, [instance_of|Accum], History ).

fask(Name, Value, Accum, [Name|History]):-
frame(Name, subclass_of(Superclass),_),
fask(Superclass, Value,[subclass_of|Accum] ,History).



The above should then be able to be used, to find out if tweetie the canary has a beak, as its a bird via inheritance. I can do this no worries, but the problem comes when I try and record the inheritance path and write it out (ulitmatly for the purpose of loop detection).

?- fask(tweetie, beak [], Inheritance_History).

Inheritance_History = [tweetie, canary, flying_bird, bird, subclass_of, subclass_of, instance_of].

Yes


As you can see, it works, except for the fact that the two halfs need merging, if that makes sense..

Bit of an obscure area I know, but if anyone feels like shedding some light on this, I would be very grateful. In the mean time, I'm gonna keep hitting the books in search of an answer..
SmallGods is offline  
Old 04-17-2007, 11:02 PM   #2 (permalink)
office politics's Avatar
 
It's all just 1s and 0s

Join Date: Jan 2004

Location: in the lab

Posts: 4,410

office politics will become famous soon enough

Default Re: Prolog - Frame Inheritance and Loop Detection

ummm, what are you coding in? what course are you in?

at a quck glance, strings are usually in quotes. what arguments are you trying to pass?
office politics is offline  
Old 04-18-2007, 04:14 AM   #3 (permalink)
 
Newb Techie

Join Date: Mar 2006

Posts: 22

SmallGods

Default Re: Prolog - Frame Inheritance and Loop Detection

I study Computer Sciences, currently doing an Artificial Intelligence module, and I'm coding in a language called Prolog, short for "Programming Logic". Its a recursive language, and its pretty much unlike any other language out there...

It was a long shot that anyone here might know it to be honest, but I figured it was worth a try!
SmallGods is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On