Converting a natural query to Dgraph Query

Hi,

Did anyone tried to convert a natural query to dgraph query?

My Schema is,

<against>: uid @reverse .
<game>: string @index(trigram) .
<name>: string @index(term) .
<player>: uid @reverse .

How to convert “List all opponents of Aman”?
The actual query is ,

{
 player_against(func:eq(name, "Aman"))
   {
    name
    ~player{
      game
    ~against{
      game
      player{
        name
      }
    }
  }
 }
}

Did anyone tried? if yes, let me know.
Thanks

Not sure if I understood, but try this.

{
 var(func:eq(name, "Aman"))
   {
    ~player {
    ~against {
      PL as player 
    }
  }
 }

   player_against_Aman(func: uid(PL)) {
    uid
    name
 }
}

@MichelDiz, the scenario is as follows,

  • There are 4 different types of games, let say (Carom, TT, Pool, Chess)
  • Each game can have any n no of teams, let say (CR_1, CR_2, TT_1, TT_2, …etc)
  • A player can participate in all games or at-least in one game.
  • Some games compromises of 2 team members (TT, Carom) or some with 1 (Chess)
  • I want to create a knowledge graph of a tournament.

In the given below dataset, AA, BB, CC, DD are player’s name. XX, XY, XZ are the different teams of game X (I kept XX, XY, XZ, in order to apply regex such that to find out the what is the game team XY is playing?)

Schema

<against>: uid @reverse .
<team>: string @index(trigram) .
<name>: string @index(term) .
<player>: uid @reverse .
SAMPLE {
set {
   _:a <name> "AA" .
   _:b <name> "BB" .
   _:c <name> "CC" .
   _:d <name> "DD" .
   _:c <name> "EE" .
   _:d <name> "FF" .
   _:e <name> "GG" .
   _:f <name> "HH" .

   _:xx <team> "XX" .
   _:xx <player> _:a .
   _:xx <player> _:b .

   _:xy <team> "XY" .
   _:xy <player> _:c .
   _:xy <player> _:d .

   _:xz <team> "XZ" .
   _:xz <player> _:e .
   _:xz <player> _:f .

    _:ya <team> "YA" .
    _:ya <player> _:d

    _:xb <team> "YB" .
    _:xb <player> _:d

    _:yc <team> "YC" .
    _:yc <player> _:yd

   _:ya<against> _:yb.
   _:yb<against> _:yc.
}
}

So these are some specific queries as below,
What all games AA is playing?
Who is AA team-member in XX?
Get all the X teams along with player name? (X is a game, XX, XY, XY are the different teams of that particular team.)

For a dgraph there is a 3 different queries which is working. Is it possible to construct a Dgraph query based on the natural text?

Thanks.

There’s no “games” in the example but you have

{
  q(func: eq(name, "AA")){
    uid
    ~player {
      uid
      team
    }
  }
}

OR

{
  var(func: eq(name, "AA")) {
   G as  ~player 
  }

  q(func: uid(G)){
      uid
      team
}
}

Not sure what you mean, in relation to the sample provided.

“X is a game”

There’s no “X” in the sample.

{
  q(func: eq(team, "XX")){
    uid
    player {
       uid
       name
     }
  }
}

What you mean exact?

I understand your needs, but the sample doesn’t help. Or you formulate the sample or wait until I create a sample based in your questions. Cheers.