Getting started with Cayley and Graph Databases


#1

Hello everyone!

A few days ago I discovered the graph databases, they seemed fantastic! Now I’m doing a test to learn a little more of it, so I looked for an example which is quite complex and quite similar to what I’m currently creating

I decided to take one of my favorite anime’s and create their basic relationships (the anime), the n-quad file looks something like this:

anime:neon_genesis_evangelion type tv .
anime:neon_genesis_evangelion name "Neon Genesis Evangelion" .
anime:neon_genesis_evangelion "adaptation" manga:neon_genesis_evangelion .
anime:neon_genesis_evangelion "summary" anime:neon_genesis_evangelion_death_and_rebirth .
anime:neon_genesis_evangelion "sequel" anime:the_end_of_evangelion .
anime:neon_genesis_evangelion "alternative_version" anime:evangelion_you_are_not_alone .
anime:neon_genesis_evangelion "alternative_version" anime:evangelion_you_can_not_advance .
anime:neon_genesis_evangelion "alternative_version" anime:evangelion_you_can_not_redo .
anime:neon_genesis_evangelion "alternative_version" anime:evangelion_three_plus_one .
anime:neon_genesis_evangelion "has_character" character:asuka_langley_souryuu . 
anime:neon_genesis_evangelion "has_character" character:rei_ayanami .
anime:neon_genesis_evangelion "has_character" character:shinji_ikari .
anime:neon_genesis_evangelion "has_character" character:misato_katsuragi .
anime:neon_genesis_evangelion "has_character" character:kaworu_nagisa .

manga:neon_genesis_evangelion name "Neon Genesis Evangelion" .
manga:neon_genesis_evangelion "adaptation" anime:neon_genesis_evangelion .

anime:neon_genesis_evangelion_death_and_rebirth type movie .
anime:neon_genesis_evangelion_death_and_rebirth name "Neon Genesis Evangelion: Death & Rebirth" .

anime:the_end_of_evangelion type movie .
anime:the_end_of_evangelion name "The End of Evangelion" .

anime:evangelion_you_are_not_alone type movie .
anime:evangelion_you_are_not_alone name "Evangelion: 1.0 You Are (Not) Alone" .

anime:evangelion_you_can_not_advance type movie .
anime:evangelion_you_can_not_advance name "Evangelion: 2.0 You Can (Not) Advance" .

anime:evangelion_you_can_not_redo type movie .
anime:evangelion_you_can_not_redo name "Evangelion: 3.0 You Can (Not) Redo" .

anime:evangelion_three_plus_one type movie .
anime:evangelion_three_plus_one name "Evangelion: 3.0+1.0" .

character:asuka_langley_souryuu name "Asuka Langley Souryuu" .

character:rei_ayanami name "Rei Ayanami" .

character:shinji_ikari name "Shinji Ikari" .

character:misato_katsuragi name "Misato Katsuragi" .

character:kaworu_nagisa name "Kaworu Nagisa" .

A pretty simplified version of My anime list data (mostly because it is tedious to write by hand all the data) , the anime has a type and name, has adaptations, characters etc… everything fine, easy to implement and usable if I query q.V("anime:neon_genesis_evangelion").Out("has_character").All() it is supposed to return all characters of the anime

But I came up with a few questions after that, and that’s why I created this post!

  • The characters has aditional info in respect to the anime that actually are acting, so some of them are the Main characters and the others are the supporting characters, how represent that in Cayley taking in mind that in some animes they can be Main and anothers they are Support?

  • Lets say that I want only and specific type of anime relationship in respect to the actual one, for example I want the relationships that are movies, how do I do that?

  • There is no a way to make it simpler by adding properties to every Edge in the graph?, so I don’t need to write every query like get adaptation, get spin-off, get sequel etc… and just say something like q.V("anime:neon_genesis_evangelion").Out("has_relationship").All() and return all adaptation, sequel etc… and the Edge has a property that tell me the type of relationship (adaptation etc…)

Thank you for your time and attention and hope can help me ^^

Greetings


PD: If is any english problem in my post feel free to tell, I’m still learning!


#2

The characters has aditional info in respect to the anime that actually are acting, so some of them are the Main characters and the others are the supporting characters, how represent that in Cayley taking in mind that in some animes they can be Main and anothers they are Support?

You can solve this with an extra quad:
anime:X is_main_character_in Y .
anime:X is_supporting_character_in Z .

Lets say that I want only a specific type of anime relationship in respect to the actual one, for example I want the relationships that are movies, how do I do that?

What do you mean exactly? All anime movies? Then you make movie a subject (movie type class .) and go In from there: g.V(“movie”).In(‘type’)

There is no a way to make it simpler by adding properties to every Edge in the graph?, so I don’t need to write every query like get adaptation, get spin-off, get sequel etc… and just say something like q.V(“anime:neon_genesis_evangelion”).Out(“has_relationship”).All() and return all adaptation, sequel etc… and the Edge has a property that tell me the type of relationship (adaptation etc…)

Everything is a relationship so you can pass multiple predicates to get them all in one query.

Probably someone with more experience can add something to this comment or correct me if I’m wrong.
And I’m not a native English speaker, but your English seems fine to me.


#3

Thanks for your answer @Jorgen !

I had not thought about it, thank you!

For example some animes has this:

anime:the_end_of_evangelion type movie .

So if I want to get all adaptation, sequel, summary etc that are type movie how would I do it?

I quite don’t understand what do you mean ^^’