简体   繁体   English

具有不同标签和关系的不同节点的 Neo4j 子图(如果有)

[英]Neo4j subgraph of different nodes with different labels and relationship if any

I recently started using neo4j and its query language "cypher" for working with building/metering data.我最近开始使用 neo4j 及其查询语言“密码”来处理建筑/计量数据。

My current graph database consists of different nodes (with different labels such as: point,meter,elec,equip ..etc. just to name a few), and each having different properties (not relevant in this context).我当前的图形数据库由不同的节点组成(具有不同的标签,例如:point、meter、elec、equip ..etc。仅举几例),并且每个节点具有不同的属性(在此上下文中不相关)。

What I would like to do, is to get a sub-graph of different nodes which have different labels.我想做的是获得具有不同标签的不同节点的子图。 For instance I would like to get all the nodes labeled as "point" as well as the ones labeled "equip" and the ones labeled as "meter".例如,我想将所有节点标记为“点”以及标记为“装备”的节点和标记为“米”的节点。 To do so I tried the following query:为此,我尝试了以下查询:

MATCH (p:point)
MATCH (e:equip)
MATCH (m:meter)
RETURN p, e, m

However that does not work since: This query builds a cartesian product between disconnected patterns.但是,这不起作用,因为:此查询在断开连接的模式之间构建笛卡尔积。

I am trying to get these so that, if a node labeled "point" is connected to either an "equip" or "meter" node, I would get the relationship.我试图获得这些,以便如果标记为“点”的节点连接到“装备”或“仪表”节点,我将获得关系。 If nothing is connected to the "point" node, it would just be stand alone.如果没有任何东西连接到“点”节点,它就会是独立的。 Therefore I could have one subgraph with the "point" to "meter"/"equip" connections and visually identify the isolated "point".因此,我可以有一个带有“点”到“仪表”/“设备”连接的子图,并在视觉上识别孤立的“点”。

I also tried something like:我也尝试过类似的事情:

MATCH (p:point)--(e:equip)
RETURN p,e

But that only return the "point" nodes which are somewhat connected to an "equip" node.但这仅返回与“装备”节点有些连接的“点”节点。 Not giving me the isolated nodes labeled "point" as well.也没有给我标记为“点”的孤立节点。

Looking forward to your input on this (simple case I guess).期待您对此的意见(我猜是简单的情况)。

Best!最好的事物!

The following query will return each point node, along with a list of all its related equip nodes, and another list of all its related meter nodes.以下查询将返回每个point节点及其所有相关equip节点的列表,以及所有相关meter节点的另一个列表。

MATCH (p:point)
RETURN p, [(p)--(e:equip) | e] AS es, [(p)--(m:meter) | m] AS ms

For this specific subset example:对于这个特定的子集示例:

MATCH (p:point)--(e:equip)
RETURN p,e

If you are displaying a graph in the Neo4j Client it will show the output I think you want to see with a simple query like this (many variations on this will work just as well)如果您在 Neo4j 客户端中显示图形,它将显示我认为您希望通过这样的简单查询看到的输出(对此的许多变体也同样有效)

MATCH (a:ACTOR), (m:MOVIE)
OPTIONAL MATCH p=(a)--(m)
return a, m, relationships(p)

Translated to your dataset, something like this?翻译成你的数据集,像这样?

MATCH (p:point), (e:equip)
OPTIONAL MATCH t=(p)--(e)
return p, e, relationships(t)

run this in the neo4j browser and look at the table output, and you'll see the client is simplifying out extra return data as it create the display view (removing nulls, and duplicates)在 neo4j 浏览器中运行它并查看表输出,您将看到客户端在创建显示视图时正在简化额外的返回数据(删除空值和重复项)

If your goal is to minimize and restructure the returned data, the best approach may depend on what language you are calling from and how you need/want it formatted, but here is a quick example query using neo4j browser / desktop client that might give you some ideas and help with restructuring what comes back from a cypher query.如果您的目标是最小化和重组返回的数据,最好的方法可能取决于您调用的语言以及您需要/希望它如何格式化,但这里有一个使用 neo4j 浏览器/桌面客户端的快速示例查询可能会给你一些想法和帮助重组从密码查询返回的内容。

MATCH (a:ACTOR), (m:MOVIE)
OPTIONAL MATCH t=(a:ACTOR)--(m:MOVIE)
with collect(distinct a) + collect(distinct m) + collect(relationships(t)) as output
return output

Translated to your dataset, something like this?翻译成你的数据集,像这样?

MATCH (p:point), (e:equip)
OPTIONAL MATCH t=(p:point)--(e:equip)
with collect(distinct p) + collect(distinct e) + collect(relationships(t)) as output
return output

(compare the table output in neo4j client to the previous query) (将neo4j客户端中的表输出与之前的查询进行比较)

Reference article 参考文章

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Neo4j-查找从未与其他节点有任何关系的节点 - Neo4j - Find nodes who never had any relationship with a different node neo4j-我们可以在具有相同关系类型但具有不同值的相同节点之间创建多重关系吗? - neo4j - can we create the multiple relationship between same nodes with same relationship type but with different values? 如何返回neo4j中具有一定关系的节点,然后返回与第一个节点具有不同关系的节点? - How do I return nodes in neo4j that have a certain relationship, and then return nodes that have a different relationship with the first nodes? Neo4J - 如何合并具有相同属性值(名称)但节点标签不同的节点 - Neo4J - How to merge nodes with the same attribute value (name) but different node labels spring neo4j得到两个标签不同但关系相同的列表 - spring neo4j get two list of different labels but the same relationship 如何在Neo4j中跨不同标签之间的整个数据集创建关系 - How to create a relationship in Neo4j across an entire dataset between different labels 比较Neo4j中具有不同标签的两个节点的数据的某些属性 - Compare data of two nodes of different labels in Neo4j with some property Neo4J:查询节点中的任意一对节点之间是否存在一定数量的不同关系? - Neo4J: Query nodes where any pair of nodes are connected by a certain number of different relations? 如何在Neo4j中不使用标签就部分隔离子图 - How to partially isolate a subgraph without using labels in neo4j Neo4j返回某个子图中存在的所有节点和关系 - Neo4j return all nodes and relationships that exist in certain subgraph
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM