0

I'm building a system that analyses sentences and stores the frequency that words follow one another. The idea is that after analysing the following sentences:

  • what is the time
  • the time is 4pm

The database would contain:

  [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)

I could do it with an RDBMS, but it seems a graph database should be a better fit so I'm trying to do it with Dgraph. I've used this schema:

type Word {
  text: String! @id
}
type Transition {
  from: Word 
  to: Word
  count: Int!
}

In Transition, I'm using null values in from and to represent the start- and end-of-sentence markers respectively.

I've managed to write a query to get words that follow the sentence start:

  query GetFirstWords {
    queryTransition(filter: {not: {has: from}}) {
      to {
        text
      }
      count
    }
  }

I've not managed to get the other words though. The most logical thing (to me) based on the above was:

  query GetNextWords {
    queryTransition(filter: {from: {text: {eq: "what"}}}) {
      to {
        text
      }
      count
    }
  }

But that (and most other things I've tried) end up with errors like:

Field 'from' is not defined by type 'TransitionFilter'.

You probably already know I'm a beginner with Dgraph and GraphQL, so it's totally likely the schema I'm using isn't suitable. I tried adding an ID parameter to it also, in case the lack of a non-string ID was the problem, but no joy. I'm also confused that lots of GraphQL examples I see don't look like the Dgraph ones, and also don't work, e.g. nothing works without the queryTransition part, and is there extra schema somewhere where TransitionFilter etc are defined?

0 Answers0