Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help required with inheritance rule

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Below is the code which i am trying to get to work:

domains
sweet, ingredient = symbol.

predicates
is_type_of(sweet, sweet).
is_type_of(ingredient, ingredient).
is_ingredient_of(ingredient, sweet).
is_light(sweet).

clauses

is_type_of(chocolate, sweet).
is_type_of(hard, sweet).
is_type_of(chewy, sweet).
is_type_of(whipped,sweet).
is_type_of(candyfloss,sweet).
is_type_of(marzipan,sweet).

is_type_of(sucrose, sugar).

is_type_of(solid, chocolate).
is_type_of(covered_bars, chocolate).

is_type_of(fruit_drops, hard).
is_type_of(mints, hard).
is_type_of(rock, hard).
is_type_of(butterscotch, hard).
is_type_of(brittles, hard).

is_type_of(caramel, chewy).
is_type_of(toffee, chewy).
is_type_of(gum, chewy).
is_type_of(gelatine, gelling_agent).

is_type_of(fudge, whipped).
is_type_of(marshmallow, whipped).
is_type_of(gelatine, whipping_agents).
is_type_of(egg_white, whipping_agents).

is_type_of(X,Z) IF is_type_of(X,Y)
AND is_type_of(Y,Z).

is_ingredient_of(sugar, sweet).

is_ingredient_of(cacao_beans, chocolate).
is_ingredient_of(cacao_butter, chocolate).

is_ingredient_of(glucose_syrup, hard).
is_ingredient_of(water, hard).
is_ingredient_of(butter, butterscotch).
is_ingredient_of(butter, brittles).
is_ingredient_of(nuts, brittles).

is_ingredient_of(milk, caramel).
is_ingredient_of(milk, toffee).
is_ingredient_of(gelling_agent, gum).

is_ingredient_of(air, whipped).
is_ingredient_of(whipping_agents, marshmallow).

is_ingredient_of(ground_almonds, marzipan).

is_ingredient_of(X,Y) IF is_type_of(Y,Z)
AND is_ingredient_of(X,Z).

is_light(X) IF is_ingredient_of(air, X).

The rule:
is_ingredient_of(X,Y) IF is_type_of(Y,Z)
AND is_ingredient_of(X,Z).
is supposed to make sweets inherit facts which apply to the categorie they are in. I don't think i'm making much sense so i give an example.

air is an ingredient of whipped so the rule such also make air an ingredient of marshmallow as marshmallow is a type of whipped.

This works someways. If i query it by saying is_ingredient_of(air,X) then X = whipped, marshmallow, fudge but if i query it by saying is_ingredient_of(X,marshmallow) then air does not come up. This of course mucks up the rule: is_light(X) IF is_ingredient_of(air, X).

Please help me

Princess_Becks
 
Hello. I guess you'd like to do this.

*** program ***

%%% facts

is_type_of(chocolate, sweet).
is_type_of(hard, sweet).
is_type_of(chewy, sweet).
is_type_of(whipped,sweet).
is_type_of(candyfloss,sweet).
is_type_of(marzipan,sweet).

is_type_of(sucrose, sugar).

is_type_of(solid, chocolate).
is_type_of(covered_bars, chocolate).

is_type_of(fruit_drops, hard).
is_type_of(mints, hard).
is_type_of(rock, hard).
is_type_of(butterscotch, hard).
is_type_of(brittles, hard).

is_type_of(caramel, chewy).
is_type_of(toffee, chewy).
is_type_of(gum, chewy).
is_type_of(gelatine, gelling_agent).

is_type_of(fudge, whipped).
is_type_of(marshmallow, whipped).
is_type_of(gelatine, whipping_agents).
is_type_of(egg_white, whipping_agents).

is_ingredient_of(sugar, sweet).

is_ingredient_of(cacao_beans, chocolate).
is_ingredient_of(cacao_butter, chocolate).

is_ingredient_of(glucose_syrup, hard).
is_ingredient_of(water, hard).
is_ingredient_of(butter, butterscotch).
is_ingredient_of(butter, brittles).
is_ingredient_of(nuts, brittles).

is_ingredient_of(milk, caramel).
is_ingredient_of(milk, toffee).
is_ingredient_of(gelling_agent, gum).

is_ingredient_of(air, whipped).
is_ingredient_of(whipping_agents, marshmallow).

is_ingredient_of(ground_almonds, marzipan).

%%% rule

type(X, Y) :-
is_type_of(X, Y).

type(X, Y) :-
is_type_of(Z, Y),
type(X, Z).

ingredient(X, Y) :-
is_ingredient_of(X, Y).

ingredient(X, Y) :-
is_ingredient_of(Z, Y),
ingredient(X, Z).

chain(X, Y) :-
type(X, Y)
;
ingredient(X, Y)
;
type(Y, ANY),
ingredient(X, ANY).

is_light(X) :-
chain(air, X).

*** sample ***

?- chain(air, X).
X = whipped ;
X = fudge ;
X = marshmallow ;
no

?- chain(X, marshmallow).
X = whipping_agents ;
X = air ;
X = sugar ;
no

?- is_light(X).
X = whipped ;
X = fudge ;
X = marshmallow ;
no

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top