Any hint for Graph Database? (Suggerimenti per query orientate ai grafi?)

114 views
Skip to first unread message

Andrea Sequenzia

unread,
Apr 6, 2016, 3:41:22 PM4/6/16
to OrientDB
Salve, sono uno studente del corso di informatica dell'Università di Catania, un mese fa mi è stato assegnato un progetto per una materia il quale mi chiedeva di creare un tutorial su OrientDB e creare un piccolo database di articoli scientifici, implementando qualche query orientata ai grafi.
Ho trovato questo database interessantissimo e ho fatto il tutto con molta passione ma ora non riesco proprio a pensare a delle query che abbiano senso nel tipo di database che il professore mi ha proposto. Per creare il database devo basarmi su un file .csv che ha delle query formate da due attributi, nome dell'articolo e nome dell'articolo che cita. Qualcuno ha suggerimenti per questo compito?  (Ho scritto in italiano visto che è un progetto "made in italy" e sono molto orgoglioso di questo) Scusate per la richiesta un po' fuori dal comune, ma la data di consegna si avvicina sempre di più. Grazie
Hi, I am a student of computer science at the University of Catania, a month ago I was assigned a project for a subject who asked me to create a tutorial on OrientDB and create a small database of scientific articles, implementing some oriented query to graphs.
I find this database very interesting and I did it all with a lot of passion but now I just can not think of the queries that make sense in the type of database that the professor asked me. To create the database I have to base myself on a .csv file that has the query formed by two attributes, name and name of the article that the article mentions. Does anyone have suggestions for this task?  Sorry for the request a bit off-topic, but the delivery date is getting closer. Thank you and sorry for bad english

scott molinari

unread,
Apr 7, 2016, 12:01:12 AM4/7/16
to OrientDB
Hi Andrea,

If you only have two attributes about articles, that isn't much of a graph. In fact, it isn't a graph. You could have a single article class with those two attributes in it and be done. No graph. In fact, you could put that data basically in any database. 

If you want to come up with a good graph database example to show how it helps with traversing relationships, you'll need to figure out the data and the relationships within the data you want to query and learn about. For instance, you mentioned scientific articles. What relationships can you find in them? What relationships would you like to explore? Authors to Articles? Topics to Authors? Articles to Authors and Topic? etc. etc. 

Once you know the relationships and data content and have it all set up, then we can help with querying the data in ODB. 

To help you get started though, you should take a look at the Studio app and open up the Greatful Dead database. Have a look at this article too, which helps you make sense of ODB. http://pettergraff.blogspot.de/2014/01/getting-started-with-orientdb.html

Scott

Andrea Sequenzia

unread,
Apr 7, 2016, 6:10:13 AM4/7/16
to OrientDB
I have implemented the database as follows:

It is formed by an only vertex class called Article with one attribute(Title, like "PhysRevB.51.17512"). It is exist one relationship "cites" between two articles. Now I want to create a query that calculete the strongly connected components, can I?

P.s:I can't add the author of article because in the .csv file, i have only the title of article.

Thanks for support

SavioL

unread,
Apr 7, 2016, 6:39:27 AM4/7/16
to orient-...@googlegroups.com
Pensavo tu avessi uno scenraio del tipo Classe ArticoliScentifici, e una Classe Citta. (dato che sono due entita distinte)
Una situazione simile a questa:
I thought you had a scenario like ArticoliScentifici class, and a City Class. (Since they are two separate entities)
A situation similar to this:







Ed da qui poter fare varie query, giusto come esempio:
And from here you can make various queries, just as an example:

1) Articoli pubblicati dalla citta di Catania. Articles published by the city of Catania.

select NomeArticolo, dataArticolo from (select expand(in('pubblicatoIn')) from citta where nomeCitta = "Catania")

----+------+-------------------+-------------------
#   |@CLASS|NomeArticolo       |dataArticolo      
----+------+-------------------+-------------------
0   |null  |Onde Gravitazionali|2016-02-01 00:00:00
1   |null  |Super Magnete      |2015-03-05 00:00:00
----+------+-------------------+-------------------


2) Le citta che hanno pubblicato almeno due articoli. Cities that have published at least two articles

select nomeCitta from citta where in('pubblicatoIn').size() > 1

----+------+---------
#   |@CLASS|nomeCitta
----+------+---------
0   |null  |Catania 
1   |null  |Milano  
----+------+---------


3) articoli pubblicati che sono inerenti alla 'fusione'. published  that are inherent to the 'fusion'

select NomeArticolo from ArticoloScentifico where NomeArticolo lucene 'fusione*'
----+------+----------------
#   |@CLASS|NomeArticolo   
----+------+----------------
0   |null  |Fusione a freddo
----+------+----------------


Vedo che il tuo DB è strutturato in maniera divera :)
I see your DB is structured differently.

Cosa intendi con "componenti fortemente connesse"??
What do you mean "strongly connected components" ??

Andrea Sequenzia

unread,
Apr 7, 2016, 6:43:35 AM4/7/16
to OrientDB
https://it.wikipedia.org/wiki/Componente_fortemente_connessa Non è utile a livello pratico in questo caso ma è un esempio di come sfruttare la teoria dei grafi(It is not useful on a practical level in this case but it is an example of how to exploit the graph theory.)

3) articoli pubblicati da milano che sono inerenti alla 'fusione'. published by milano that are inherent to the 'fusion'

SavioL

unread,
Apr 7, 2016, 7:11:04 AM4/7/16
to orient-...@googlegroups.com
Ok, (scusa ho letto velocemente e al posto di 'cita' ho inteso 'citta').
Quindi nel tuo caso, vorresti trovare tutti i vertici "fortemente connessi" , senza la dipendenza della direzione (grafo non orientato), per cui otterresti come risultato tutti gli articoli presenti nell'immagine che hai pubblicato. corretto?

Ok, (sorry I read it quickly and instead of 'city' i intended 'city').
So in your case, you want to find all the "highly connected" summits without the dependence of the direction (undirected graph), so you would get as a result all items in the image that you published. correct?


Andrea Sequenzia

unread,
Apr 7, 2016, 7:53:46 AM4/7/16
to orient-...@googlegroups.com
Dovrei tener conto della dipendenza (grafo orientato)

Il giorno giovedì 7 aprile 2016 13:11:04 UTC+2, SavioL ha scritto:
Ok, (scusa ho letto velocemente e al posto di 'cita' o inteso 'citta').

Quindi nel tuo caso, vorresti trovare tutti i vertici "fortemente connessi" , senza la dipendenza della direzione (grafo non orientato), per cui otterresti come risultato tutti gli articoli presenti nell'immagine che hai pubblicato. corretto?

Ok, (sorry I read it quickly and instead of 'city' or intended 'city').

SavioL

unread,
Apr 7, 2016, 8:03:42 AM4/7/16
to OrientDB
quindi grafo orientato, (nell'immagine non si vedono i versi degli archi).. hai un'immagine che mostra la direzione?

So directed graph, (in the picture there aren't lines of direction) .. have you an image that shows the direction?

Andrea Sequenzia

unread,
Apr 7, 2016, 8:08:06 AM4/7/16
to OrientDB

Scusa non avevo notato che la direzione non si vedeva.
sorry I had not noticed that the direction could not be seen.

Andrea Sequenzia

unread,
Apr 7, 2016, 9:23:12 AM4/7/16
to OrientDB
Comunque mi va bene pure calcolare le componenti connesse.

SavioL

unread,
Apr 7, 2016, 9:34:22 AM4/7/16
to orient-...@googlegroups.com
Per calcolare un cfc serve implementare un algoritmo (es Kosaraju, SCC, Tarjan, ) non credo si possa fare tutto con query/traverse. Una classe Java fatta ad hoc che lo calcola potrebbe esserti utile?

To calculate a cfc serves implement an algorithm (eg Kosaraju, SCC, Tarjan,) I do not think you can do it with queries / traverse. A Java class done ad hoc which calculates that might be useful to you?

Andrea Sequenzia

unread,
Apr 7, 2016, 9:55:37 AM4/7/16
to OrientDB
Dovrei studiarmi le API Java di OrientDB, poco tempo a disposizione

SavioL

unread,
Apr 7, 2016, 11:35:17 AM4/7/16
to orient-...@googlegroups.com
capisco, tieni presente che se fatto in java le API sarebbero poche ( connessione, salvarsi i vertici per esempio in un lista classica) e poi tutto il resto sono operazioni che implementano l'algoritmo.
Altrimenti un'altra soluzione potrebbe essere fare una funzione in Javascript (che implementa sempre l'algoritmo).
Questo se vuoi ottenere sia il cfc oppure il fc (dato che potrebbero in generale esserci nodi separati dal grafo).

I understand, please note that if done in Java APIs would be few (connection, save the vertices as in a classic list) and then all the rest are operations that implement the algorithm.
If not, a solution could be to make a function in Javascript.
That if you want to get both the CFC or the FC (since it may generally be separated from the graph nodes for a generic db).

Con il solo utilizzo della query potresti ottenedere una cosa del genere (scan di tutti i nodi connessi (sia in IN che in OUT) ad un nodo di partenza) pero non so quanto possa esserti utilie...
 
traverse both("cites") from (select from Articoli where nome = "A256")

----+-----+--------+-----+--------+---------
#   |@RID |@CLASS  |nome |in_cites|out_cites
----+-----+--------+-----+--------+---------
0   |#16:0|Articoli|A256 |[size=1]|null    
1   |#16:1|Articoli|A1822|[size=1]|[size=1]
2   |#16:2|Articoli|17512|null    |[size=2]
3   |#16:4|Articoli|1052 |[size=1]|[size=2]
4   |#16:5|Articoli|323  |[size=1]|null    
5   |#16:3|Articoli|7753 |[size=1]|null    
----+-----+--------+-----+--------+---------


Andrea Sequenzia

unread,
Apr 10, 2016, 4:44:29 AM4/10/16
to OrientDB
Se dovessi trovare l'articolo con il maggior numero di citazioni?
If I want to find the article with the highest number of citations?

SavioL

unread,
Apr 11, 2016, 9:05:55 AM4/11/16
to OrientDB
Per avere il numero di citazioni (conteggio archi entranti):
To get the number of citations (counting incoming edges):

SELECT nome, in().size("cites") AS numeroCitazioni FROM Articoli UNWIND numeroCitazioni

risultato:
----+------+-----+---------------
#   |@CLASS|nome |numeroCitazioni
----+------+-----+---------------
0   |null  |A256 |1             
1   |null  |A1822|1             
2   |null  |17512|0             
3   |null  |7753 |1             
4   |null  |1052 |1             
5   |null  |323  |1             
----+------+-----+---------------

Andrea Sequenzia

unread,
Apr 18, 2016, 7:00:47 AM4/18/16
to OrientDB
Grazie, ho provato a trovare l'articolo maggiormente citato con la seguente query:
Select Titolo, in().size("cites") as numerocitazioni from Articolo where numerocitazioni >=( SELECT max(in().size("cites")) FROM Articolo)
Ma non da niente come risultato. Come risolvere?

SavioL

unread,
Apr 18, 2016, 8:41:30 AM4/18/16
to orient-...@googlegroups.com
L'alias "numerocitazioni" non puoi usarlo direttamente, ma riesci a usarlo nella query esterna a quello in cui l'hai creato.
Poi nel where devi usare 'in' e non  >= perchè il risultato del max credo sia visto come una lista.
Giusto per correttezza il nome dell'arco "cites" è piu corretto metterlo dentro "in()" e non nel size.

The alias "times cited" can not use it directly, but you can use it in the outer query to the one in which you created it.
Then in where you have to use 'in' and not> = max because the result I think is seen as a list.
Just to correct the arc name "cites" it is more correct to put it in "in()" and not in size.

Questa dovrebbe funzionare come query:

select from (Select nome, in("cites").size() as numerocitazioni from Articolo) where numerocitazioni in (SELECT max(in("cites").size()) FROM Articolo)



Andrea Sequenzia

unread,
Apr 18, 2016, 4:23:42 PM4/18/16
to OrientDB
Grazie mille funziona. Ho trovato un "bug" (non so se lo sia) nel database che sto usando, ovvero c'è una sorta di arco fantasma. Mi spiego meglio, quando stampo tutti gli archi del database, questo arco non compare nella lista ma sia negli archi in di un certo articolo sia nel conteggio nelle query esso compare e se clicco su di esso mi compare la finestra Page not found. P.s nel graph editor non compare 
Reply all
Reply to author
Forward
0 new messages