如何建立家庭关系逻辑? [英] How to create family relation logic?

查看:217
本文介绍了如何建立家庭关系逻辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力使



我正在寻找一个更智能的方法来做到这一点。创建规则,例如父亲的姐姐=父女母亲的姐姐=母女
我也希望查询父亲的妻子的妹妹,但不想单独定义它们。

解决方案

Prolog是一个合理的选择...例如,我有这个小型图书馆绘制这样的家谱树

a href =https://i.stack.imgur.com/opCJg.jpg =nofollow noreferrer>

从这个定义中(流派定义只用于改变节点的颜色)

 : -  module(elizabeth,[elizabeth / 0])。 
: - use_module(谱系)。

伊丽莎白: - 家谱(伊丽莎白,'伊丽莎白二世家族')。

女性('伊丽莎白二世')。
女性('Elizabeth Bowes-Lyon女士')。
女('Teck玛丽公主')。
女('Cecilia Cavendish-Bentinck')。

parent_child('George VI','Elizabeth II')。
parent_child('Elizabeth Bowes-Lyon夫人','Elizabeth II')。

parent_child('George V','George VI')。
parent_child('Teck玛丽公主','乔治六世')。

parent_child('Cecilia Cavendish-Bentinck','Elizabeth Elizabeth Bowes-Lyon夫人')。
parent_child('Claude Bowes-Lyon','Elizabeth Elizabeth Bowes-Lyon夫人')。它需要SWI-Prolog和Graphviz。

$ b

edit 添加一些事实

 女性('Rose Bowes-Lyon')。 
parent_child('Cecilia Cavendish-Bentinck','Rose Bowes-Lyon')。
parent_child('Claude Bowes-Lyon','Rose Bowes-Lyon')。

和规则

  is_maternal_aunt(Person,Aunt): -  
parent_child(Parent,Person),
女性(Parent),
parent_child(GranParent,Parent),
parent_child (GranParent,阿姨),
阿姨\ =家长。

我们得到

 ? -  is_maternal_aunt(X,Y)。 
X ='Elizabeth II',
Y ='Rose Bowes-Lyon';


I'm trying to make this but for a different language. In this language there are different kinds of names for uncles and aunts. We call paternal aunt something else and maternal aunt something else.

I came across a graph database 'neo4j'. I created 5 members. I got this approach to work just like I want. But the problem in this is that I've to create n * (n-1) relationships. I'm create a full tree here and not just 5 members of a family.

Also, this is more like brute force. I'm creating all the possibilities.

I'm looking for a smarter way to do this. Creating rules like for example Father's sister = paternal-aunt and Mother's sister = maternal-aunt I also want queries Father's wife's sister but don't want to define them separately.

解决方案

Prolog is a reasonable choice... For instance I have this small library to draw 'genealogy trees' like this

from this definition (genre definitions are used only to change node' color)

:- module(elizabeth, [elizabeth/0]).
:- use_module(genealogy).

elizabeth :- genealogy(elizabeth, 'Elizabeth II Family').

female('Elizabeth II').
female('Lady Elizabeth Bowes-Lyon').
female('Princess Mary of Teck').
female('Cecilia Cavendish-Bentinck').

parent_child('George VI', 'Elizabeth II').
parent_child('Lady Elizabeth Bowes-Lyon','Elizabeth II').

parent_child('George V', 'George VI').
parent_child('Princess Mary of Teck', 'George VI').

parent_child('Cecilia Cavendish-Bentinck','Lady Elizabeth Bowes-Lyon').
parent_child('Claude Bowes-Lyon', 'Lady Elizabeth Bowes-Lyon').

It requires SWI-Prolog and Graphviz.

edit adding some facts

female('Rose Bowes-Lyon').
parent_child('Cecilia Cavendish-Bentinck','Rose Bowes-Lyon').
parent_child('Claude Bowes-Lyon', 'Rose Bowes-Lyon').

and the rule

is_maternal_aunt(Person, Aunt) :-
    parent_child(Parent, Person),
    female(Parent),
    parent_child(GranParent, Parent),
    parent_child(GranParent, Aunt),
    Aunt \= Parent.

we get

?- is_maternal_aunt(X,Y).
X = 'Elizabeth II',
Y = 'Rose Bowes-Lyon' ;

这篇关于如何建立家庭关系逻辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆