southeast(awka,is_in_south-east_Nigeria).
southeast(orlu,is_in_south-east_Nigeria).
southeast(owerri,is_in_south-east_Nigeria).
southeast(aba,is_in_south-east_Nigeria).
city(awka,southeast).
city(orlu,southeast).
city(owerri,southeast).
city(aba,southeast).
city(C,Z):-southeast(C,Z).
答案 0 :(得分:1)
Prolog是一种基于关系数据模型的语言。
因此,在设计RDBMS时需要同样的谨慎。 也许你应该引入一些额外的关系,例如
% state(ID, Name)
state(1, 'Nigeria').
% region(ID, StateID, Name)
region(1, 1, 'south east').
% city(ID, Name, RegionId)
city(1, awka, 1).
city(2, orlu, 1).
% etc...
并通过DB提供查询:
city_in_region(City, Location) :-
city(_, City, RegionId),
region(RegionId, StateId, Region),
state(StateId, State),
format(atom(Location), '~s is in ~s of ~s', [City, Region, State]).
你得到了
?- city_in_region(C,R).
C = awka,
R = 'awka is in south east of Nigeria' ;
C = orlu,
R = 'orlu is in south east of Nigeria'.