annotate app/models/TPGraph.java @ 109:2633ac31c233 draft

create updateRelationNode function
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Sun, 17 Mar 2013 22:39:58 +0900
parents d45f76774fd8
children 3440be06e501
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
1 package models;
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
2
27
e246e0dac9c8 modified checkConsensus
one
parents: 26
diff changeset
3 import java.util.ArrayList;
23
cad8e054fe4b modifying getConsensus action
one
parents: 20
diff changeset
4 import java.util.HashSet;
cad8e054fe4b modifying getConsensus action
one
parents: 20
diff changeset
5 import java.util.Iterator;
cad8e054fe4b modifying getConsensus action
one
parents: 20
diff changeset
6
84
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
7 import com.tinkerpop.blueprints.Direction;
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
8 import com.tinkerpop.blueprints.Edge;
7
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
9 import com.tinkerpop.blueprints.Graph;
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
10 import com.tinkerpop.blueprints.Vertex;
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
11 import com.tinkerpop.blueprints.impls.tg.TinkerGraph;
24
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
12 import com.tinkerpop.gremlin.java.GremlinPipeline;
7
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
13
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
14 public class TPGraph {
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
15
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
16 private static TPGraph instance = new TPGraph();
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
17 private Object claimRootId;
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
18 private Object userRootId;
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
19
13
9b677755cb93 create action Claim/createClaim
one
parents: 9
diff changeset
20 /*
9b677755cb93 create action Claim/createClaim
one
parents: 9
diff changeset
21 * Edge type
9b677755cb93 create action Claim/createClaim
one
parents: 9
diff changeset
22 */
8
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
23 protected final String CHILD = "child";
57
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
24
7
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
25 private TPGraph() {
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
26
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
27 }
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
28
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
29 public static TPGraph getInstance() {
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
30 return instance;
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
31 }
61
0268b4239da1 modified initialData method
one
parents: 57
diff changeset
32
0268b4239da1 modified initialData method
one
parents: 57
diff changeset
33 public static void resetInstance() {
85
d45f76774fd8 modified InitialData
one
parents: 84
diff changeset
34 if (instance.getGraph() != null) {
d45f76774fd8 modified InitialData
one
parents: 84
diff changeset
35 instance.shutdownGraph();
d45f76774fd8 modified InitialData
one
parents: 84
diff changeset
36 }
61
0268b4239da1 modified initialData method
one
parents: 57
diff changeset
37 instance = new TPGraph();
85
d45f76774fd8 modified InitialData
one
parents: 84
diff changeset
38 instance.newGraph();
61
0268b4239da1 modified initialData method
one
parents: 57
diff changeset
39 }
7
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
40
52
f3db6edc61ad modify checkUnanimously
one
parents: 50
diff changeset
41 private Graph graph = null;
7
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
42 private String path = null;
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
43
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
44 public void setPath(String path) {
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
45 this.path = path;
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
46 }
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
47
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
48 public Graph newGraph() {
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
49 if (path == null) {
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
50 graph = new TinkerGraph();
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
51 } else {
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
52 graph = new TinkerGraph(path);
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
53
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
54 }
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
55 return graph;
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
56 }
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
57
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
58 public Graph getGraph() {
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
59 return graph;
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
60 }
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
61
76
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
62 public Vertex addVertex(Object vId) {
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
63 return graph.addVertex(vId);
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
64 }
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
65
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
66 public Vertex getVertex(Object vId) {
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
67 return graph.getVertex(vId);
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
68 }
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
69
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
70 public Edge getEdge(Object eId) {
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
71 return graph.getEdge(eId);
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
72 }
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
73
8
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
74 public void setClaimRootId(Object id) {
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
75 this.claimRootId = id;
7
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
76 }
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
77
8
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
78 public void setUserRootId(Object id) {
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
79 this.userRootId = id;
7
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
80 }
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
81
13
9b677755cb93 create action Claim/createClaim
one
parents: 9
diff changeset
82 public Object getClaimRootId() {
9b677755cb93 create action Claim/createClaim
one
parents: 9
diff changeset
83 return claimRootId;
9b677755cb93 create action Claim/createClaim
one
parents: 9
diff changeset
84 }
9b677755cb93 create action Claim/createClaim
one
parents: 9
diff changeset
85
8
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
86 public Object getUserRootId() {
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
87 return userRootId;
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
88 }
76
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
89
8
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
90 public Vertex getClaimRootVertex() {
76
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
91 return getVertex(claimRootId);
7
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
92 }
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
93
8
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
94 public Vertex getUserRootVertex() {
76
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
95 return getVertex(userRootId);
7
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
96 }
8
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
97
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
98 private Edge setLabel(Vertex fromV, Vertex toV, String label) {
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
99 return graph.addEdge(null, fromV, toV, label);
18
one
parents: 17
diff changeset
100 }
one
parents: 17
diff changeset
101
70
290a5883ac5e add TIMESTAMP. modified getClaimInfoTraverse.
one
parents: 61
diff changeset
102 public Edge setLabelFromRootUser(UserModel user) {
8
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
103 Vertex rootUser = getUserRootVertex();
18
one
parents: 17
diff changeset
104 // rootUser ---child---> newUser
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
105 return setLabel(rootUser, user.getVertex(), CHILD);
13
9b677755cb93 create action Claim/createClaim
one
parents: 9
diff changeset
106 }
8
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
107
70
290a5883ac5e add TIMESTAMP. modified getClaimInfoTraverse.
one
parents: 61
diff changeset
108 public Edge setLabelFromRootClaim(ClaimModel claim) {
13
9b677755cb93 create action Claim/createClaim
one
parents: 9
diff changeset
109 Vertex rootClaim = getClaimRootVertex();
18
one
parents: 17
diff changeset
110 // rootUser ---child---> newUser
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
111 return setLabel(rootClaim, claim.getVertex(), CHILD);
8
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
112 }
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
113
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
114 public Edge setLabelToAuthor(ClaimModel claim, String author) {
76
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
115 Vertex authorVertex = getVertex(author);
18
one
parents: 17
diff changeset
116 // claim ---author---> authorVertex(userVertex)
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
117 return setLabel(claim.getVertex(), authorVertex, NodeModel.L_AUTHOR);
16
7cdc9d19834f modified createClaim
one
parents: 13
diff changeset
118 }
7cdc9d19834f modified createClaim
one
parents: 13
diff changeset
119
74
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
120 public Edge setLabelPrev(ClaimModel fromClaim, ClaimModel toClaim) {
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
121 // fromClaim ---prev---> toClaim
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
122 return setLabel(fromClaim.getVertex(), toClaim.getVertex(), NodeModel.L_PREV );
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
123 }
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
124
20
34ea98c5a18c modified UserModel/getEdgeInUser
one
parents: 18
diff changeset
125 public Boolean setLabelToUsers(ClaimModel claim, String[] users, String label) {
18
one
parents: 17
diff changeset
126 for (String userName: users) {
76
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
127 Vertex userVertex = getVertex(userName);
57
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
128 if (userVertex == null) {
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
129 return false;
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
130 }
20
34ea98c5a18c modified UserModel/getEdgeInUser
one
parents: 18
diff changeset
131 setLabel(claim.getVertex(), userVertex, label);
18
one
parents: 17
diff changeset
132 }
one
parents: 17
diff changeset
133 return true;
16
7cdc9d19834f modified createClaim
one
parents: 13
diff changeset
134 }
9
d050b7fb4cda create getUserRequests action
one
parents: 8
diff changeset
135
36
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
136 public Boolean setLabelStatusToUser(ClaimModel claim, String userName, String label, String status) {
76
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
137 Vertex userVertex = getVertex(userName);
36
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
138 if (userVertex == null) {
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
139 return false;
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
140 }
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
141 Edge edge = setLabel(claim.getVertex(), userVertex, label);
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
142 edge.setProperty(NodeModel.STATUS, status);
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
143 return true;
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
144 }
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
145
30
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 27
diff changeset
146 public Boolean setLabelStatusToUsers(ClaimModel claim, String[] users, String label, String status) {
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 27
diff changeset
147 for (String userName: users) {
36
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
148 Boolean createFlag = setLabelStatusToUser(claim, userName, label, status);
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
149 if (!createFlag) {
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
150 return false;
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
151 }
30
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 27
diff changeset
152 }
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 27
diff changeset
153 return true;
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 27
diff changeset
154 }
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 27
diff changeset
155
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
156 public Edge setLabelMention(ClaimModel fromClaim, ClaimModel toClaim, String label) {
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
157 return setLabel(fromClaim.getVertex(), toClaim.getVertex(), label);
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
158 }
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
159
40
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
160 public Object[] searchAllUser() {
76
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
161 Vertex userRootVertex = getVertex(getUserRootId());
40
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
162 GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>();
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
163 pipe.start(userRootVertex).out(CHILD);
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
164 ArrayList<Object> userArray = new ArrayList<Object>();
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
165 for (Vertex userVertex : pipe) {
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
166 userArray.add(userVertex.getId());
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
167 }
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
168 if (userArray.size() == 0) {
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
169 return null;
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
170 }
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
171 return userArray.toArray();
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
172 }
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
173
36
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
174 public Boolean deleteRequestEdge(ClaimModel claim, HashSet<Object> userSet) {
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
175 GremlinPipeline<Vertex,Edge> pipeEdge = new GremlinPipeline<Vertex,Edge>();
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
176 pipeEdge.start(claim.getVertex()).outE(NodeModel.L_REQUEST);
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
177 ArrayList<Edge> deleteEdgeArray = new ArrayList<Edge>();
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
178 for (Edge e : pipeEdge) {
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
179 GremlinPipeline<Edge,Vertex> pipeUserVertex = new GremlinPipeline<Edge,Vertex>();
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
180 pipeUserVertex.start(e).inV();
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
181 Vertex userVertex = pipeUserVertex.next();
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
182 if (userSet.contains(userVertex.getId())) {
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
183 deleteEdgeArray.add(e);
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
184 }
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
185 }
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
186 for (Edge e : deleteEdgeArray) {
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
187 graph.removeEdge(e);
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
188 }
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
189 return true;
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
190 }
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
191
71
c76b3b60eb18 add comment
one
parents: 70
diff changeset
192 /*
c76b3b60eb18 add comment
one
parents: 70
diff changeset
193 * Return CLAIM numbers of top consensus vertex.
c76b3b60eb18 add comment
one
parents: 70
diff changeset
194 */
23
cad8e054fe4b modifying getConsensus action
one
parents: 20
diff changeset
195 public Object[] checkConsensus(HashSet<Object> set) {
cad8e054fe4b modifying getConsensus action
one
parents: 20
diff changeset
196 Iterator<Object> iter = set.iterator();
57
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
197 iter = set.iterator();
27
e246e0dac9c8 modified checkConsensus
one
parents: 26
diff changeset
198 while (iter.hasNext()) {
24
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
199 Object childId = iter.next();
74
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
200 ArrayList<Object> array = getAllUpperVertexId(childId);
50
d6c623e92837 modified routes
one
parents: 40
diff changeset
201 for (Object parentId: array) {
71
c76b3b60eb18 add comment
one
parents: 70
diff changeset
202 /*
c76b3b60eb18 add comment
one
parents: 70
diff changeset
203 * If there is a number of the number of parent and child in the [set],
c76b3b60eb18 add comment
one
parents: 70
diff changeset
204 * remove [childId].
c76b3b60eb18 add comment
one
parents: 70
diff changeset
205 */
24
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
206 if (set.contains(parentId)) {
27
e246e0dac9c8 modified checkConsensus
one
parents: 26
diff changeset
207 if (set.contains(childId)) {
71
c76b3b60eb18 add comment
one
parents: 70
diff changeset
208 set.remove(childId);
27
e246e0dac9c8 modified checkConsensus
one
parents: 26
diff changeset
209 // This behavior is anxiety.
e246e0dac9c8 modified checkConsensus
one
parents: 26
diff changeset
210 iter = set.iterator();
e246e0dac9c8 modified checkConsensus
one
parents: 26
diff changeset
211 }
e246e0dac9c8 modified checkConsensus
one
parents: 26
diff changeset
212 childId = parentId;
24
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
213 }
23
cad8e054fe4b modifying getConsensus action
one
parents: 20
diff changeset
214 }
cad8e054fe4b modifying getConsensus action
one
parents: 20
diff changeset
215 }
24
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
216 return set.toArray();
23
cad8e054fe4b modifying getConsensus action
one
parents: 20
diff changeset
217 }
71
c76b3b60eb18 add comment
one
parents: 70
diff changeset
218
c76b3b60eb18 add comment
one
parents: 70
diff changeset
219 /*
c76b3b60eb18 add comment
one
parents: 70
diff changeset
220 * Return CLAIM numbers of above [id] CLAIM.
c76b3b60eb18 add comment
one
parents: 70
diff changeset
221 */
74
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
222 public ArrayList<Object> getAllUpperVertexId(Object id) {
76
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
223 Vertex startV = getVertex(id);
27
e246e0dac9c8 modified checkConsensus
one
parents: 26
diff changeset
224 ArrayList<Object> vertexArray = new ArrayList<Object>();
57
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
225 while (true) {
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
226 GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>();
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
227 pipe.start(startV).in(NodeModel.L_QUESTION, NodeModel.L_REFUTATION, NodeModel.L_SUGGESTION);
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
228 if (pipe.hasNext()) {
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
229 Vertex e = pipe.next();
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
230 vertexArray.add(e.getId());
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
231 startV = e;
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
232 } else {
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
233 break;
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
234 }
27
e246e0dac9c8 modified checkConsensus
one
parents: 26
diff changeset
235 }
e246e0dac9c8 modified checkConsensus
one
parents: 26
diff changeset
236 return vertexArray;
e246e0dac9c8 modified checkConsensus
one
parents: 26
diff changeset
237 }
e246e0dac9c8 modified checkConsensus
one
parents: 26
diff changeset
238
74
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
239 public Object getOneUpperClaimVertexId(Object id) {
76
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
240 Vertex startV = getVertex(id);
24
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
241 GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>();
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
242 pipe.start(startV).in(NodeModel.L_QUESTION, NodeModel.L_REFUTATION, NodeModel.L_SUGGESTION);
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
243 if (pipe.hasNext()) {
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
244 Vertex v = pipe.next();
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
245 return v.getId();
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
246 } else {
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
247 return null;
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
248 }
23
cad8e054fe4b modifying getConsensus action
one
parents: 20
diff changeset
249 }
cad8e054fe4b modifying getConsensus action
one
parents: 20
diff changeset
250
74
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
251 public Object getTopClaimVertexId(Object id) {
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
252 Object v = id;
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
253 Object upV = id;
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
254 while (upV != null) {
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
255 v = upV;
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
256 upV = getOneUpperClaimVertexId(v);
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
257 }
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
258 return v;
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
259 }
83
c6929060c85f modified clone method in ClaimModel.
one
parents: 82
diff changeset
260
82
cddb5ed942a6 modified copyConsensusTree method
one
parents: 78
diff changeset
261 private void recursiveCopyDownClaimsAndSetLabel(ClaimModel oldUpClaim, ClaimModel latestUpClaim,
cddb5ed942a6 modified copyConsensusTree method
one
parents: 78
diff changeset
262 String timestamp, String... labels) {
75
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
263 for (String label: labels) {
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
264 GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>();
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
265 pipe.start(oldUpClaim.getVertex()).out(label);
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
266 for (Vertex oldDownV : pipe) {
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
267 ClaimModel oldDownClaim = new ClaimModel(oldDownV);
82
cddb5ed942a6 modified copyConsensusTree method
one
parents: 78
diff changeset
268 ClaimModel latestDownClaim = oldDownClaim.cloneAndSetLabelPrev(timestamp);
75
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
269 setLabel(latestUpClaim.getVertex(), latestDownClaim.getVertex(), label);
82
cddb5ed942a6 modified copyConsensusTree method
one
parents: 78
diff changeset
270 recursiveCopyDownClaimsAndSetLabel(oldDownClaim, latestDownClaim, timestamp, labels);
75
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
271 }
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
272 }
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
273 }
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
274
82
cddb5ed942a6 modified copyConsensusTree method
one
parents: 78
diff changeset
275 private ClaimModel copyDownClaims(ClaimModel oldTopClaim, String timestamp) {
cddb5ed942a6 modified copyConsensusTree method
one
parents: 78
diff changeset
276 ClaimModel latestTopClaim = oldTopClaim.cloneAndSetLabelPrev(timestamp);
cddb5ed942a6 modified copyConsensusTree method
one
parents: 78
diff changeset
277 recursiveCopyDownClaimsAndSetLabel(oldTopClaim, latestTopClaim, timestamp,
75
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
278 NodeModel.L_REFUTATION, NodeModel.L_QUESTION, NodeModel.L_SUGGESTION);
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
279 return latestTopClaim;
74
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
280 }
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
281
82
cddb5ed942a6 modified copyConsensusTree method
one
parents: 78
diff changeset
282 public ClaimModel copyConsensusTree(ClaimModel claim, String timestamp) {
77
4c5b3e990712 modified TPGraph.java
one
parents: 76
diff changeset
283 ClaimModel oldTopClaim = new ClaimModel(getVertex(getTopClaimVertexId(claim.getId())));
82
cddb5ed942a6 modified copyConsensusTree method
one
parents: 78
diff changeset
284 ClaimModel latestTopClaim = copyDownClaims(oldTopClaim, timestamp);
75
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
285 return latestTopClaim;
74
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
286 }
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
287
84
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
288 public Object[] checkLatestVertices(Object[] vIds) {
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
289 ArrayList<Object> array = new ArrayList<Object>();
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
290 for (Object vId: vIds) {
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
291 GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>();
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
292 pipe.start(getVertex(vId)).in(NodeModel.L_PREV);
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
293 /*
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
294 * get latest claims.
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
295 * c1 <--prev-- c1' <--prev-- c1''
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
296 * c1'' is latest.
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
297 */
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
298 if (!pipe.hasNext()) {
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
299 array.add(vId);
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
300 }
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
301 }
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
302 return array.toArray();
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
303 }
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
304
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
305 public Object getLatestVertexId(Object id) {
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
306 Vertex v = getVertex(id);
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
307 if (v == null) {
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
308 return null;
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
309 }
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
310 GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>();
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
311 pipe.start(v).in(NodeModel.L_PREV);
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
312 while (pipe.hasNext()) {
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
313 /*
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
314 * get latest claims.
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
315 * v1 <--prev-- v1' <--prev-- v1''
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
316 * c1'' is latest.
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
317 */
85
d45f76774fd8 modified InitialData
one
parents: 84
diff changeset
318 v = pipe.next();
84
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
319 pipe.start(v).in(NodeModel.L_PREV);
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
320 }
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
321 return v.getId();
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
322 }
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
323
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
324 private ArrayList<Object> getVertexIdRecursiveTraverse(NodeModel vModel, Direction direction, String... labels) {
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
325 ArrayList<Object> array = new ArrayList<Object>();
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
326 ArrayList<Object> nextArray = new ArrayList<Object>();
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
327 Object[] ids = vModel.getVertexIdArrayTraverseLabel(direction, labels);
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
328 if (ids == null) {
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
329 return new ArrayList<Object>();
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
330 }
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
331 for (Object id: ids) {
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
332 array.add(id);
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
333 NodeModel nextModel = new NodeModel(getVertex(id));
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
334 ArrayList<Object> tmpArray = getVertexIdRecursiveTraverse(nextModel, direction, labels);
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
335 if (!tmpArray.isEmpty()) {
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
336 nextArray.addAll(tmpArray);
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
337 }
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
338 }
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
339 if (!nextArray.isEmpty()) {
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
340 array.addAll(nextArray);
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
341 }
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
342 return array;
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
343 }
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
344
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
345 /*
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
346 * [latestId, latestId-1, ..., id, ..., oldIds+1, oldIds]
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
347 */
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
348 public Object[] getClaimRevision(String id) {
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
349 NodeModel vModel = new NodeModel(getVertex(id));
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
350 if (vModel.getVertex() == null) {
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
351 return null;
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
352 }
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
353 ArrayList<Object> array = new ArrayList<Object>();
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
354 ArrayList<Object> inPrevIds = getVertexIdRecursiveTraverse(vModel, Direction.IN, NodeModel.L_PREV);
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
355 for (int i=inPrevIds.size()-1; i>=0; i--) {
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
356 array.add(inPrevIds.get(i));
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
357 }
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
358 array.add(id);
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
359 ArrayList<Object> outPrevIds = getVertexIdRecursiveTraverse(vModel, Direction.OUT, NodeModel.L_PREV);
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
360 array.addAll(outPrevIds);
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
361 return array.toArray();
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
362 }
bb547f2a3c88 create getClaimRevision methos
one
parents: 83
diff changeset
363
7
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
364 public void shutdownGraph() {
85
d45f76774fd8 modified InitialData
one
parents: 84
diff changeset
365 graph.shutdown();
7
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
366 }
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
367 }