对城市进行分组的序言计划

时间:2011-09-07 10:18:34

标签: prolog

请在这里需要帮助,这是一个分配

一个序言,显示哪些城市在南方 -

尼日利亚东部。这是城市(abraka,oyo,awka,

orlu,markurdi,jalingo,owerri,aba,mushin,okigwe)。

abraka (city not in south-east)
oyo (city not in south-east)
awka (city in south-east)
orlu (city in south-east)
markudi (city not in south-east)
jalingo (city not in south-east)
owerri (city in south-east)
aba (city in south-east)
mushin (city not in south-east)
okaigwe (city in south-east)

我不知道该怎么办。谢谢你的任何

帮助。

1 个答案:

答案 0 :(得分:1)

您应该对(序言)问题做的第一件事就是根据您需要的查询为您的数据选择合适的表示。

在这种情况下,您需要有一个像is_city_in_south_east(City)这样的谓词。 因此,您可以将数据表示为:

is_city_in_SOuth_east(abraka).
is_city_in_south_east(awka).
city_is_not_in_south_east(oyo).
....

然而,这种表述太具体了。 更通用的是

city_location(abraka, south_east).
city_location(awka).
city_location(oyo, not_south_east).

我认为

abraka (city not in south-east)
oyo (city not in south-east)
awka (city in south-east)
orlu (city in south-east)
markudi (city not in south-east)
jalingo (city not in south-east)
owerri (city in south-east)
aba (city in south-east)
mushin (city not in south-east)
okaigwe (city in south-east)

只是数据库的人类可读表示。

如果这是您的程序的实际输入(例如在文本文件中),它会非常混乱;我认为最简单的方法是构建一个迷你解析器。