如何在 Neo4j 中使用类型层次结构? [英] How to work with type hierarchies in Neo4j?

查看:38
本文介绍了如何在 Neo4j 中使用类型层次结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以在 Neo4j 中模拟类型层次结构吗?例如,如果我想构建汽车的类层次结构,我可能有一个基本类型Car",然后有扩展它的子类,如SportCar"等.

Is there some way to model type hierarchies in Neo4j? If for example I want to build a class hierarchy of cars, I might have a base type of "Car" and then have sub classes that extend that, like "SportCar", etc.

我希望能够创建SportCar"的实例,但运行查询以获取所有Car".这可能吗?如果是这样,技术是什么?

I'd like to be able to create instances of "SportCar", but run a query to get all "Car"s. Is this possible? If so what is the technique?

我认为我想要做的是创建一个标签层次结构" - 但我只是认为 neo4j 不支持.

I think what I'm trying to do is create a "label hierarchy" - but I just don't think that's supported in neo4j.

推荐答案

Paul,

首先,我建议您阅读Graph Databases",这是一本免费的 O'Reilly 电子书,可在 此链接.

First, I'd recommend that you read "Graph Databases", a free O'Reilly e-book available at this link.

作为快速回答,有很多方法可以做这种事情,最好的选择取决于您要解决的问题.一种方法是构造一个汽车"节点,然后将您的SportCar"节点与具有类型关系的汽车"节点相关联,例如

As a quick stab at an answer, there are numerous ways to do this sort of thing, and the best choice depends on the problem you are trying to solve. One way would be to construct a "Car" node, then relate your "SportCar" nodes to the "Car" node with a typed relationship like

CREATE (m:Car)
MATCH (m:CAR) WITH m CREATE (n:SportCar)-[:IS_A]->(m)

并创建其他类型的汽车,并将它们与 Car 节点相关联.

and create other types of cars, also relating them to the Car node.

然后您可以通过

MATCH (m:Car)<-[:IS_A]-(n) RETURN n

您也可以只在每个节点上放置 Car 和 SportCar(以及 LuxoCar 等)标签.这只是众多方法中的两种.

You can also just put Car and SportCar (and LuxoCar, etc) labels on each node. And that's just two of many approaches.

恩惠与平安,

吉姆

这篇关于如何在 Neo4j 中使用类型层次结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆