可以代表(使用的Cypher)你描述像這樣的例子:
CREATE (tom:Person)
SET tom.name = "Tom",
tom.age = 20
CREATE (helen:Person)
SET helen.name = "Helen",
helen.age = 30
CREATE (tom)-[:FRIENDS_WITH]->(helen)
CREATE (c:Car {desc: "2015 Red Honda Fit"})
CREATE (tom)-[:HAS_CAR]->(c)
CREATE (p:Phone {desc: "iPhone 6s"})
CREATE (helen)-[:HAS_PHONE]->(p)
這導致類似如下的圖表:
您可以查詢商機對於Tom(與您描述的模式匹配的路徑)是這樣的:
MATCH (p:Phone)<-[:HAS_PHONE]-(friend:Person)-[:FRIENDS_WITH]-(t:Person {name: "Tom"})-[:HAS_CAR]->(c:Car)
WHERE t.age > 18 AND friend.age > 18
RETURN t.name AS Tom, friend.name AS business_partner,
p.desc AS phone, c.desc AS car
該查詢返回:
╒═══╤════════════════╤═════════╤══════════════════╕
│Tom│business_partner│phone │car │
╞═══╪════════════════╪═════════╪══════════════════╡
│Tom│Helen │iPhone 6s│2015 Red Honda Fit│
└───┴────────────────┴─────────┴──────────────────┘
Here是證明這個Neo4j的控制檯實例。
哦,它很好用!謝謝!!!順便說一下,它也可以用sparql或swrl規則來完成(也許你知道)? – user3068938