The requirement is to design a knowledge graph in which some entity/predicate has temporal feature.
Consider an example like Linkedin.
Alice worked at company Microsoft since 2002-02-02, and this is her first job;
And Alice worked at company Amazon since 2012-02-02, and this is not her first job;
How to design with Dgraph to store all of Alice’s jobs and easy to query at which company did her work at specified time?
I think about using facets as below, but the old data will be lost.
Do you have any good idea? Thank you in advance.
Hi @wanglj
In my opinion a more flexible structure is to have a type for companies and one specific type for job history. I’m using GraphQL type here and you can use dql equivalent:
type Person {
PersonID: ID!
name: String
workHistory: [WorkHistory]
}
type Company {
CompanyID: ID!
name: String!
workHistories: [WorkHistory]
}
type WorkHistory {
WorkHistoryID: ID!
company: Company! @hasInverse(field: "workHistories")
person: Person @hasInverse(field: "workHistory")
date: Date
}
Now with this schema I do not need to store which work place is the first and I can get the result using a query.
What you can get easy with this structure(LinkedIn Example):
1- First place somebody worked at:
query {
getPerson(PersonID: "0x2") {
name
workHistories(first: -1) {
WorkHistoryID
company {
CompanyID
name
}
}
}
}
2- Workers of specific company:
query {
getCompany(ComponayID: "0x1") {
CompanyID
workHistories {
WorkHistoryID
person {
name
}
}
}
}