Prolog 人工智能语言中文论坛---打造优质Prolog学习交流园地
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Prolog 人工智能语言中文论坛---打造优质Prolog学习交流园地

一个供Prolog爱好者学习与交流的地方


您没有登录。 请登录注册

以prolog程式建立十組家庭生活型態

3 posters

向下  留言 [第1页/共1页]

1以prolog程式建立十組家庭生活型態 Empty 以prolog程式建立十組家庭生活型態 周六 十一月 17, 2012 8:23 pm

Jessicaluin



[hide][/hide][hide][/hide]主程式如下:

family(
person( tom, fox, date(7,may,1960), works(bbc, 15200)),
person( ann, fox, date(9,may,1961), unemployed),
[person( pat, fox, date(5,may,1983), unemployed),
person( jim, fox, date(5,may,1983), unemployed)].

Our database would then be comprised of a sequence of facts like this describing all families that are of interest
to our program.Prolog is,in fact, a very suitable language for retrieving the desired information from such a database.
One nice thing about prologis that we can refer to objects without actually specifying all the components of these objects.
We can merely indicate the structure of objects that we are interested in ,and leave the particular components in the
structures unspecified or only partially specified.

family(person(_,armstrong,_,_),_,_)


The underscore characters denote different anonymous variables; we do not care about their values.Further.we can refer to all
families with three children by the term:

family(_,_[_,_])

To find all married women that have at least three children we can pose the question:

?- family(_,person(Name,Surname,_,_),[_,_,_|_]).



翻譯如下:

主程式如下:

家庭(
人(湯姆狐狸,日(5月7日,1960年),工程(英國廣播公司,15200)),
人(ANN,狐狸,日期(9),1961年5月,無業),
[人(PAT,狐狸,日(5,5月,1983年),無業),
人(吉姆,狐狸,日期(5),1983年5月,無業)。

我們的數據庫中,然後將包括一個序列的事實描述,有興趣的所有家庭
到我們的program.Prolog是,事實上,從這樣的一個數據庫中檢索所需的信息的一個非常合適的語言。
一個很好的事情普洛斯,我們可以參考的對象,而無需實際指定這些對象的所有組件。
我們可以只顯示對象的結構,我們有興趣,和離開的具體部件的
結構未指定或只有部分指定的。

家庭(人(_,阿姆斯特朗,_,_),_,_)


下劃線的字符表示不同的匿名變量,我們不關心他們的values.Further.we指的是所有
家庭的術語,有三個孩子:

家庭(_,_[_,_)

要找到所有的已婚婦女至少有三個孩子,我們可以提出這樣的問題:

- 家庭(_,人(姓名,身份證號碼,_,_),_,_,_ |_])。

因為要建立10組家庭 然後增加查詢功能
例如:查詢有幾個小孩或是有工作的夫妻或是小孩的生日等等功能
我是想說寫個查詢小孩年齡或生日 或是 單親家庭的話
要怎麼寫呢??請大大們幫忙 [hide][/hide][hide][/hide][hide][/hide][quote][code][hide][/hide][hide][/hide]

yauhsien



找到题目来源,原来是 Ivan Bratko, "Prolog Programming for Artificial Intelligence" 第四章开始的范例。

http://yauhsien.wordpress.com

Mercury Liao


Admin



你问的这个好像前不久有人问过了,可以请参:

http://prolog.longluntan.net/t55-topic

然后建议此种问题讨论的文章放进"问题讨论区"哈。

http://prolog.longluntan.net

返回页首  留言 [第1页/共1页]

您在这个论坛的权限:
不能在这个论坛回复主题