Thank you for your very helpful replies, Riccardo and Scott!

I think I also prefer the reification solution and being fully compliant 
with the graph model.

>From what I've read around the web so far, I've gotten the impression that 
graph databases are overall better than document databases.

So, from now on, I'll probably usually avoid drawing edges from vertexes to 
other edges.

And also avoid drawing edges between two edges, which I read elsewhere also 
isn't appropriate in a graph: 

https://github.com/orientechnologies/orientdb/issues/4078

http://stackoverflow.com/questions/28781749/am-i-supposed-to-be-able-to-create-edges-between-two-edges-and-or-an-edge-and-a


The rest of this post contains no questions, just info for anyone curious.

Again, I'm a newbie, so, if anyone has any feedback, suggestions, etc., I'd 
love to read them!


Happily, my renovated, hopefully now compliant graph can now easily be 
displayed in OrientDB Studio's visual graph editor, just by running the 
query "select from v".

And I was able to figure out how to write some queries for my renovated 
graph.


I completed my renovations before seeing Riccardo's second post - 
https://groups.google.com/d/msg/orient-database/NDrGteQLmf8/3FKYU9UhBQAJ 

So, I didn't include a "Concrete" class, just Riccardo's earlier ideas - 
vertexes of the "Statement" class and edges of classes "Subject" and 
"Object".  Thanks again, Riccardo!


I gave the Statement vertexes two properties: "name", which isn't used in 
queries and was just for display in my graph screenshot; and "verb", which 
is the property I used in some queries below.

Example name property from a Statement: "Bob likes Star Trek"

Example verb property from that Statement: "likes"


My renovated graph is now too big for me to easily make an ASCII art 
version, so, hopefully one or the other of these links will work:

http://astroblahhh.com/files_for_forums/OrientDB_Google_Group/Question_1/OrientDB-Question_1-Expanded_Graph.png

https://web.archive.org/web/20150825094101/http://astroblahhh.com/files_for_forums/OrientDB_Google_Group/Question_1/OrientDB-Question_1-Expanded_Graph.png


And, here's a DB export in JSON format, for anyone who wants to experiment 
with the data:

http://astroblahhh.com/files_for_forums/OrientDB_Google_Group/Question_1/apdb.json

https://web.archive.org/web/20150825094433/http://astroblahhh.com/files_for_forums/OrientDB_Google_Group/Question_1/apdb.json


Below are a bunch of queries I made.  They're largely pretty confusing, 
both to read and to write, but, this blog post showed me some of the syntax 
to use: http://orientdb.com/orientdb-improved-sql-filtering/

The official manual also helped: http://orientdb.com/docs/2.1/SQL.html

And lots of trial and error. :-)  Happily, I got much further than I 
thought I might, being a newbie to graph DBs. :-)  (With some familiarity 
with ordinary MySQL.)


This query gets all the subjects of Statements:

select expand( distinct(out('Subject').name ) ) from Statement

(Yields Bob, Joe and Jim.)


All the objects of Statements:

select expand( distinct(out('Object').name ) ) from Statement

(Yields "Star Trek", "Bob likes Star Trek", "Star Wars", "Joe's hat", "Jim 
likes Star Wars", "Jim's cup of tea", "Joe's spoon".)


All subjects who like something:

select distinct(out('Subject').name) from Statement where verb='likes'

(Yields "Bob", "Joe", "Jim".)


All subjects who have something:

select distinct(out('Subject').name) from Statement where verb='has'

(Yields "Joe", "Jim".)


All the Statements with the subject Joe:

select expand(in('Subject')[@class=Statement] ) from #9:1

(Yields "Joe likes Bob's like" (short for "Joe likes the fact that Bob 
likes Star Trek"), "Joe has a hat", "Joe likes Jim's like" (Joe likes the 
fact that Jim likes Star Wars), "Joe has a spoon".)


All Statements which say Joe likes something:

select expand(in('Subject')[@class=Statement][verb='likes'] ) from #9:1

(Yields "Joe likes Bob's like", "Joe likes Jim's like".)


All Statements which say Joe has something:

select expand(in('Subject')[@class=Statement][verb='has'] ) from #9:1

(Yields "Joe has a hat", "Joe has a spoon".)


All the things Joe is stated to have:

select expand(in('Subject')[@class=Statement][verb='has'].out('Object')) 
from #9:1

(Yields "Joe's hat", "Joe's spoon".)


All the things Joe is stated to like:

select expand(in('Subject')[@class=Statement][verb='likes'].out('Object')) 
from #9:1

(Yields "Bob likes Star Trek", "Jim likes Star Wars".)


All the things Jim is stated to like:

select expand(in('Subject')[@class=Statement][verb='likes'].out('Object')) 
from #9:3

(Yields "Star Wars", "Bob likes Star Trek".)


Everyone who likes the fact that Bob likes something:

select 
expand(in('Subject')[@class=Statement][verb='likes'].in('Object').out('Subject')
 
) from #9:0

(Yields "Joe", "Jim".)


----

Best wishes,
Apollia



On Sunday, August 23, 2015 at 5:03:32 PM UTC-4, Riccardo Tasso wrote:
>
> Hi,
>    if you really need to model this scenario...I guess this is a good way 
> to do it.
>
> Which are the queries you'd like to answer?
>
> Anyway this is somehow different from a graph database scenario and 
> probably I would use the lower level Document API with LINKs.
>
> Another possibility is to use what is called "reification" of your 
> relation.
> In your case create a class Statement, which extends Vertex.
> A statement has always an outgoing edge labeled "subject" and another 
> outgoing edge labeled "object".
> The first statement (s1) has subject Bob and object Star Trek.
> The second statement (s2) has subject Joe and object s1.
> Each statement of course may have a label or type.
>
> I prefer the reification solution, since you are compliant with the graph 
> model.
>
> Cheers,
>    Riccardo
>
> 2015-08-23 20:54 GMT+02:00 <[email protected] <javascript:>>:
>
>> On Sunday, August 23, 2015 at 4:17:15 AM UTC-4, scott molinari wrote:
>>>
>>> The image didn't work because the link is broken. The image throws a 403.
>>>
>>> Scott
>>>
>>
>> Thanks for the info!  With my 1st post, I had dragged/dropped the image 
>> from my computer into the Google Groups post editor, and, since the image 
>> appeared in my editor, it looked like it was going to work.  Oh, well.
>>
>>
>> The link in my 2nd post works for me: 
>> http://astroblahhh.com/temporary__files/orient_db_group/OrientDB-Question-1.png
>>
>> Archive.org also was able to access that link: 
>> https://web.archive.org/web/http://astroblahhh.com/temporary__files/orient_db_group/OrientDB-Question-1.png
>>
>>
>> But, in case the link from my 2nd post is also not working for some 
>> people, here's an ASCII art version of my picture:
>>
>>
>> |-----|             |-----------|
>> | Bob |----likes--->| Star Trek |
>> |-----|      ^      |-----------|
>>              |
>>              | likes
>>              |
>>           |-----|
>>           | Joe |
>>           |-----|
>>
>> Explanation: Joe likes the fact that Bob likes Star Trek.
>>
>> Here's a link to my original post, containing my questions: 
>> https://groups.google.com/d/msg/orient-database/NDrGteQLmf8/kOQ0gEZiBAAJ
>>
>> Sorry for all the confusion!
>>
>> Best wishes,
>> Apollia
>>
>> -- 
>>
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "OrientDB" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to