---
# System prepended metadata

title: Neo4J介紹

---

# Neo4J介紹

###### links
* https://jamboard.google.com/d/1pAHteH5f2QI3VIha0qpfTrDorZHKUyIPnCz1FUUNLg8/edit?usp=sharing

## https://neo4j.com/

## https://spark.apache.org/

![](https://i.imgur.com/bJFUPT6.png)

## https://neo4j.com/labs/apoc/
## https://neo4j.com/docs/graph-data-science/current/

## Intro to cypher
```cypher!

match (n) return n
match (x:Person) return x
match (x:Movie) return x
    return x

```
```
match(x:Person)
where x.name = "Tom Hanks"
    return x
```

```
match(x:Person)-[]-(y)
where x.name = "Tom Hanks"
    return x,y
    

```
```
match(x:Movie) where x.title="Apollo 13" return x
match(x:Movie)-[]-(y) where x.title="Apollo 13" return x,y

match(x:Movie)-[:ACTED_IN]-(y) where x.title="Apollo 13" return x,y
match(x:Movie)-[:DIRECTED]-(y) where x.title="Apollo 13" return x,y

match(x:Movie)-[:DIRECTED]-(y) where x.title="Apollo 13" return x,y

```

```
match(x:Person)-[]-(y)-[]-(z)
where x.name = "Tom Hanks"
    return x,y,z
```
	Kevin Bacon
    ```
    match(x:Person)-[]-(y)-[]-(z)
where x.name = "Kevin Bacon"
    return x,y,z
    ```
```
match(x:Person{name:"Tom Hanks"})-[]-(x_movie) return x,x_movie
match(x:Person{name:"Tom Hanks"})-[:ACTED_IN]-(x_movie) return x,x_movie
match(x:Movie{title:"Apollo 13"})<-[:DIRECTED]-(y) return y.name
match(x:Person{name:"Tom Hanks"})-[:ACTED_IN]->(co_movie)<-[:ACTED_IN]-(y) return x,co_movie,y


```

```
match(x:Movie{title:"Apollo 13"})-[r]-(y) return x.title,type(r),y.name
match (y)-[r]-(x:Movie{title:"Apollo 13"}) return x.title,type(r),y.name
match(x:Person{name:"Tom Hanks"})-[*1..2]-(y) return x,y

```

```
match(x:Person{name:"Kevin Bacon"}) return x
match(x:Person{name:"Meg Ryan"}) return x
MATCH p = shortestPath(
    (x:Person{name:"Kevin Bacon"})-[*]-(y:Person{name:"Meg Ryan"})
) return p
```

```
CREATE
  (alice:User {name: 'Alice'}),
  (bridget:User {name: 'Bridget'}),
  (charles:User {name: 'Charles'}),
  (doug:User {name: 'Doug'}),
  (mark:User {name: 'Mark'}),
  (michael:User {name: 'Michael'}),

  (alice)-[:FOLLOWS {score: 1}]->(doug),
  (alice)-[:FOLLOWS {score: -2}]->(bridget),
  (alice)-[:FOLLOWS {score: 5}]->(charles),
  (mark)-[:FOLLOWS {score: 1.5}]->(doug),
  (mark)-[:FOLLOWS {score: 4.5}]->(michael),
  (bridget)-[:FOLLOWS {score: 1.5}]->(doug),
  (charles)-[:FOLLOWS {score: 2}]->(doug),
  (michael)-[:FOLLOWS {score: 1.5}]->(doug)
```

```
CALL gds.graph.project(
  'myGraph1',
  'User',
  {
    FOLLOWS: {
      orientation: 'REVERSE',
      properties: ['score']
    }
  }
)
```
```
CALL gds.degree.stream('myGraph1')
YIELD nodeId, score
RETURN gds.util.asNode(nodeId).name AS name, score AS followers
ORDER BY followers DESC, name DESC
```