Reputation: 225
I am using Grakn with the Python driver. I am trying a use case where the user can search for a song, for example Despacito, and then get recommendations of other similar songs. The result must contain songs of the same genre, and from the same producer. When I search for a song, I am able to get the related entities like singer, producer and genre of the song. What I want next are the other songs related to this producer and genre.
from grakn.client import GraknClient
uri = "localhost:48555"
keyspace = "grakn_demo"
client = GraknClient(uri=uri)
session = client.session(keyspace=keyspace)
tx = session.transaction().write()
graql = 'match $s isa song, has producer "Records X", song-name "Despacito", singer "Luis Fonsi", genre "Reggaeton"; get;'
tx.query(graql)
Upvotes: 1
Views: 122
Reputation: 920
Graql give results based on the constraints you provide, essentially ruling out any result that doesn't match the criteria you give. In your query you restrict $s
to have a particular song-name
and singer
. Removing these constraints will give you the results you ask for:
match $s isa song, has producer "Records X", has genre "Reggaeton"; get;
This now matches for any song which has a particular producer and genre. :)
Upvotes: 1
Reputation: 71
If you have specific name of the producer and genre, you can use this query
match $s isa song,
has producer "Records X",
has song-name $songName,
has singer $singerName,
has genre "Reggaeton";
get;
You will get all the songs (and their names and singers) which have genre "Reggaeton" and producer "Records X".
If you don't know the name of the genre and producer, you can get them first by the song name and then execute the seconds query to get similar
songs
Query to get producer and genre by the song name. After that you can use first query
match $s isa song,
has producer $producer,
has song-name "Despacito",
has genre $genre;
get;
Upvotes: 2