Hyper-edge problem, not sure if there is a better way to solve this, any help will be welcome

Hello everyone, I'm new to Neo4j and I have something in my datamodel that would be perfect to map as an hyper-edge, but Neo4j doesn't seem to support that.

Let me start with an example:

Newsletter#1
  Interest{name: 'Local News'} -[:INTERESTED]->(Element {name: 'Brazil'})
  Interest{name: 'Mercosul Tech'} -[:INTERESTED]->(Element {name: 'Latin America'}, Element{name: 'Technology'})

Story#1
  Tag-[]->(Element {name: 'Uruguai'})
Story#2
  Tag-[]->(Element {name: 'Technology'})
Story#3
  Tag-[]->(Element {name: 'Technology'})
  Tag-[]->(Element {name: 'Brazil'})
Story#4
  Tag-[]->(Element {name: 'Technology'})
  Tag-[]->(Element {name: 'Latin America'})
  Tag-[]->(Element {name: 'Uruguai'})

Story#3 will be in the "Local News" section of the newsletter
Story#4 will be in the "Mercosul Tech" section
Stories 1 and 2 will not be in the newsletter

so in my view, the Interest-[INTERESTED]-(Element*) should be an hyper-edge where it can point to one or more Element per node/interest
and that relationship will map to stories that have at least the same elements

Is there an easy or simple way to map and query this in Neo4j?

I have this working in a SQL database today, and it is implemented with a combination of complex queries, I'm trying to port it to a graph database to better model the relationships between these elements, but I have this complex case that doesn't seem to have a direct mapping.

yes, you could use something a Singleton. its a pattern used in object oriented programming, you only need to create a unique id for interest node, then you could access to the elements of that interest.

you could reed more about singleton here: IBM Developer

Thanks,

I'm familiar with the singleton pattern, just not sure how that applies to a Neo4J relationship

do you have any idea how I could query starting from the "newsletter instance" stories with tags that match the interested elements as I showed in the sample data?

@urubatan Hyper-edges in Neo4j are implemented as nodes. Check out @Luanne_Misquitt’s NODES 2019 talk where she derives how to model this: It Depends and why it's the most frequent answer to modelling questions - YouTube

1 Like

@urubatan not quite sure a hyperedge is needed yet. Of course I don't have details of your use cases and model but at first glance, a potential model could be

where the data you have in your example would look like

Obvious questions would be whether newsletter sections are common across all newsletters but share different interests- this would require a change in the model, and so on

Hope this helps as a pointer to how you could think of transforming the ER model to a graph model

Hi @Luanne_Misquitt
the thing here is that for example, in "Mercosul Tech" it is one interest "Latin America" + "Technology" and not Latin America or Technology

So the Interest "Mercosul Tech" is associated with both Elements "Latin America" and "Technology" and this combination is an hyper-edge, that should connect only to stories that also have both Elements

I'm watching your presentation now, but I do not think that using a node to represent an Hyper-Edge will solve my problem as it should, since using a node can be used to enforce rules applied to an Hyper-Edge but doesn't have all the functionality but maybe I can write a graph query to match what I need using the "Node Hyper-Graph implementation" :D

Thank you for the pointer, I'm watching the presentation right now

Yes, I don't see a hyperedge either. Rules can be modelled in graphs as well, but it may be overkill for your case, and you might be better off enforcing them via triggers, or other business logic.