일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- 엔터프라이즈 블록체인
- Play2
- Play2 로 웹 개발
- play 강좌
- Akka
- Adapter 패턴
- 플레이프레임워크
- 주키퍼
- 블록체인
- 하이퍼레저 패브릭
- 스칼라 강좌
- 하이브리드앱
- akka 강좌
- Actor
- 안드로이드 웹뷰
- 파이썬
- 파이썬 동시성
- 파이썬 데이터분석
- Golang
- hyperledger fabric
- 파이썬 강좌
- 파이썬 머신러닝
- CORDA
- 그라파나
- 이더리움
- 스위프트
- 스칼라 동시성
- play2 강좌
- 스칼라
- Hyperledger fabric gossip protocol
- Today
- Total
HAMA 블로그
Neo4j - Traversal 본문
33.8. Traversal
The Matrix
이것은 우리가 순회할 첫번째 그래프 모습이다.
친구들 / 친구들의 친구들
실제 순회를 돌아보고 결과를 찍어보자.
결과:
누가 매트릭스를 코드했나?
:결과
이제 우리는 알게됬다.
순서에 따라서 경로를 걸어보자
토이그래프를 만들자
Now, the order of relationships (REL1
→ REL2
→ REL3
) is stored in an ArrayList
. Upon traversal, the Evaluator
can check against it to ensure that only paths are included and returned that have the predefined order of relationships:
어떻게 경로를 걸어갈지 정의하자.
Note that we set the uniqueness to Uniqueness.NODE_PATH
as we want to be able to revisit the same node dureing the traversal, but not the same path.
순회를 하고 결과를 찍어보자
결과:
여기서 우리는 패스 아웃풋을 표현하기위해 커스텀 클래스를 사용했다.
Uniqueness of Paths in traversals
This example is demonstrating the use of node uniqueness. Below an imaginary domain graph with Principals that own pets that are descendant to other pets.
In order to return all descendants of Pet0
which have the relation owns
to Principal1
(Pet1
and Pet3
), the Uniqueness of the traversal needs to be set to NODE_PATH
rather than the default NODE_GLOBAL
so that nodes can be traversed more that once, and paths that have different nodes but can have some nodes in common (like the start and end node) can be returned.
This will return the following paths:
In the default path.toString()
implementation, (1)--[knows,2]-->(4)
denotes a node with ID=1 having a relationship with ID 2 or type knows
to a node with ID-4.
Let’s create a new TraversalDescription
from the old one, having NODE_GLOBAL
uniqueness to see the difference.
Tip The |
Now only one path is returned:
Social network
Social networks (know as social graphs out on the web) are natural to model with a graph. This example shows a very simple social model that connects friends and keeps track of status updates.
The data model for a social network is pretty simple: Persons
with names and StatusUpdates
with timestamped text. These entities are then connected by specific relationships.
Person
friend
: relates two distinctPerson
instances (no self-reference)status
: connects to the most recentStatusUpdate
StatusUpdate
next
: points to the nextStatusUpdate
in the chain, which was posted before the current one
Status graph instance
The StatusUpdate
list for a Person
is a linked list. The head of the list (the most recent status) is found by following status
. Each subsequent StatusUpdate
is connected by next
.
Here’s an example where Andreas Kollegger micro-blogged his way to work in the morning:
To read the status updates, we can create a traversal, like so:
This gives us a traverser that will start at one StatusUpdate
, and will follow the chain of updates until they run out. Traversers are lazy loading, so it’s performant even when dealing with thousands of statuses — they are not loaded until we actually consume them.
Activity stream
Once we have friends, and they have status messages, we might want to read our friends status' messages, in reverse time order — latest first. To do this, we go through these steps:
- Gather all friend’s status update iterators in a list — latest date first.
- Sort the list.
- Return the first item in the list.
- If the first iterator is exhausted, remove it from the list. Otherwise, get the next item in that iterator.
- Go to step 2 until there are no iterators left in the list.
Animated, the sequence looks like this.
The code looks like:
http://neo4j.com/docs/stable/tutorials-java-embedded-traversal.html
'NoSQL' 카테고리의 다른 글
Neo4j - 인덱스 사용하기 (0) | 2015.10.30 |
---|---|
Neo4j 인사이드 : 파일 스토리지 (0) | 2015.10.30 |
시계열 DB (OpenTSDB , 인플럭스 DB , Graphite ) 정리 (0) | 2015.10.22 |
MongoDB vs Couchbase (2) (0) | 2015.09.03 |
MongoDB vs Couchbase (1) (0) | 2015.09.03 |