How to model kinship network in Dgraph


(James) #1

First, I am a newbie to dgraph and graphdb.

My simplified use case is that there are 2 entities, people and company.
People invests in company, and people may have different relationships, like parent/child, husband/wife, siblings, friends. These are all kinship relationship, but of different types.
The questions to be answered will be find the path between people and company, such as Person A’s wife’s older sister’s son’s friend invest a company.

What is the best way to model the relationship between peoples?

  1. name predicate as kin, add specific kind (parent/child, siblings…) as facet
    con: not easy to tell the relationship, like who is parent, who is child.
  2. put kinship as vertex, connect people to kinship
  3. create different predicate for different kinships.
  4. any other suggestion?

Thanks a lot!


(Jeff Hull) #2

Hi @thetuxedo,

I would do #3 - create different predicate for different kinship. So you would do:


_:person1 <hasSpouse> _:person2 .
_:person2 <investsIn> _:company1 .

Then for the “type” edges, instead of having a “type” predicate, which is discouraged due to sharding concerns as well as transaction conflicts (see https://docs.dgraph.io/howto/#giving-nodes-a-type), you would do

_:person1 <person> "" .
_:person2 <person> "" .
_:company1 <company> "" .

Then to filter on “type”, you would use the functions has(person) (will ID all people) or has(company) (will ID all companies)


(James) #3

thanks a lot for the reply.

I don’t get this part, what does the double quote means?
_:person1 “”
_:person2 “”
_:company1 “”


(Jeff Hull) #4

Sorry about that, I forgot to preformat the text. Just altered the original post to fix the formatting.

It’s a little counter-intuitive, but saying:

_:person1 <person> "" .

In this case is the same as saying “_:person1 is a person”. It would also be possible to do this instead:

_:person1 <type> "Person" .

But the dgraph team recommends against using a generic “type” edge (see https://docs.dgraph.io/howto/#giving-nodes-a-type). The “” is meaningless and serves only to create the edge, the presence of which then indicates the type of _:person. Hope this makes sense.