Hi all, I’m new to graph databases, but I was showing my daughter how to make a random chatbot the other day and thought I’d try and use Dgraph as a backend for it. The bot’s graph has weighted edges, however, and nothing I’ve tried is working
The bot’s real basic, all it does is analyse sentences and store the frequencies that words follow one another. If I give it the following sentences:
- “what is the time”
- “the time is 4pm”
Analysing those as its first input would populate its database with:
[start of sentence]: followed by ("what": 1 time, "the": 1 time)
"what": followed by............. ("is": 1 time)
"is": followed by................("the": 1 time, "4pm": 1 time)
"the": followed by...............("time": 1 time)
"time": followed by..............([end of sentence]: 1 time, "is": 1 time)
"4pm": followed by...............([end of sentence]: 1 time)
My original thought was to have a schema like this:
type Word {
text: String! @id
}
type Transition {
from: Word
to: Word
count: Int!
}
The Transition nodes would do the heavy lifting, the Word nodes are only really there for the Transitions to link to. Nulls in Transition.from and Transition.to would indicate the start and end of a sentence.
It’s pretty easy to find sentence-starting Transitions this way:
query GetFirstWords {
queryTransition(filter: {not: {has: from}}) {
to {
text
}
count
}
}
Except I can’t figure out how to continue from there! I’ve tried adding ID and @search and @hasinverse in various places, but no joy. Pretty much everything I’ve tried results in one of the following two errors:
Field 'from' is not defined by type 'TransitionFilter'.```
or
Syntax Error: Expected Name, found String 'time'.
I don’t feel like I have the data structure right, but I’ve no idea what else to try so any help would be amazing! (Even if that help is telling me I’m trying to do something GraphQL doesn’t do!)