annotate app/models/TPGraph.java @ 82:cddb5ed942a6 draft

modified copyConsensusTree method
author one
date Sat, 09 Mar 2013 21:26:40 +0900
parents f744331287ea
children c6929060c85f
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
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
7 import com.tinkerpop.blueprints.Edge;
7
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
8 import com.tinkerpop.blueprints.Graph;
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
9 import com.tinkerpop.blueprints.Vertex;
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
10 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
11 import com.tinkerpop.gremlin.java.GremlinPipeline;
7
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
12
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
13 public class TPGraph {
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
14
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
15 private static TPGraph instance = new TPGraph();
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
16 private Object claimRootId;
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
17 private Object userRootId;
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
18
13
9b677755cb93 create action Claim/createClaim
one
parents: 9
diff changeset
19 /*
9b677755cb93 create action Claim/createClaim
one
parents: 9
diff changeset
20 * Edge type
9b677755cb93 create action Claim/createClaim
one
parents: 9
diff changeset
21 */
8
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
22 protected final String CHILD = "child";
57
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
23
7
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
24 private TPGraph() {
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
25
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 public static TPGraph getInstance() {
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
29 return instance;
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
30 }
61
0268b4239da1 modified initialData method
one
parents: 57
diff changeset
31
0268b4239da1 modified initialData method
one
parents: 57
diff changeset
32 public static void resetInstance() {
0268b4239da1 modified initialData method
one
parents: 57
diff changeset
33 instance = new TPGraph();
0268b4239da1 modified initialData method
one
parents: 57
diff changeset
34 }
7
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
35
52
f3db6edc61ad modify checkUnanimously
one
parents: 50
diff changeset
36 private Graph graph = null;
7
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
37 private String path = null;
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
38
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
39 public void setPath(String path) {
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
40 this.path = path;
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
41 }
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
42
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
43 public Graph newGraph() {
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
44 if (path == null) {
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
45 graph = new TinkerGraph();
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
46 } else {
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
47 graph = new TinkerGraph(path);
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
48
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
49 }
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
50 return graph;
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
51 }
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
52
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
53 public Graph getGraph() {
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
54 return graph;
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
55 }
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
56
76
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
57 public Vertex addVertex(Object vId) {
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
58 return graph.addVertex(vId);
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
59 }
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
60
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
61 public Vertex getVertex(Object vId) {
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
62 return graph.getVertex(vId);
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
63 }
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
64
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
65 public Edge getEdge(Object eId) {
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
66 return graph.getEdge(eId);
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
67 }
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
68
8
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
69 public void setClaimRootId(Object id) {
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
70 this.claimRootId = id;
7
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
71 }
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
72
8
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
73 public void setUserRootId(Object id) {
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
74 this.userRootId = id;
7
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
75 }
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
76
13
9b677755cb93 create action Claim/createClaim
one
parents: 9
diff changeset
77 public Object getClaimRootId() {
9b677755cb93 create action Claim/createClaim
one
parents: 9
diff changeset
78 return claimRootId;
9b677755cb93 create action Claim/createClaim
one
parents: 9
diff changeset
79 }
9b677755cb93 create action Claim/createClaim
one
parents: 9
diff changeset
80
8
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
81 public Object getUserRootId() {
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
82 return userRootId;
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
83 }
76
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
84
8
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
85 public Vertex getClaimRootVertex() {
76
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
86 return getVertex(claimRootId);
7
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
87 }
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
88
8
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
89 public Vertex getUserRootVertex() {
76
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
90 return getVertex(userRootId);
7
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
91 }
8
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
92
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
93 private Edge setLabel(Vertex fromV, Vertex toV, String label) {
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
94 return graph.addEdge(null, fromV, toV, label);
18
one
parents: 17
diff changeset
95 }
one
parents: 17
diff changeset
96
70
290a5883ac5e add TIMESTAMP. modified getClaimInfoTraverse.
one
parents: 61
diff changeset
97 public Edge setLabelFromRootUser(UserModel user) {
8
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
98 Vertex rootUser = getUserRootVertex();
18
one
parents: 17
diff changeset
99 // rootUser ---child---> newUser
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
100 return setLabel(rootUser, user.getVertex(), CHILD);
13
9b677755cb93 create action Claim/createClaim
one
parents: 9
diff changeset
101 }
8
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
102
70
290a5883ac5e add TIMESTAMP. modified getClaimInfoTraverse.
one
parents: 61
diff changeset
103 public Edge setLabelFromRootClaim(ClaimModel claim) {
13
9b677755cb93 create action Claim/createClaim
one
parents: 9
diff changeset
104 Vertex rootClaim = getClaimRootVertex();
18
one
parents: 17
diff changeset
105 // rootUser ---child---> newUser
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
106 return setLabel(rootClaim, claim.getVertex(), CHILD);
8
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
107 }
7b314898fddd create action User.getUser()
one
parents: 7
diff changeset
108
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
109 public Edge setLabelToAuthor(ClaimModel claim, String author) {
76
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
110 Vertex authorVertex = getVertex(author);
18
one
parents: 17
diff changeset
111 // claim ---author---> authorVertex(userVertex)
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
112 return setLabel(claim.getVertex(), authorVertex, NodeModel.L_AUTHOR);
16
7cdc9d19834f modified createClaim
one
parents: 13
diff changeset
113 }
7cdc9d19834f modified createClaim
one
parents: 13
diff changeset
114
74
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
115 public Edge setLabelPrev(ClaimModel fromClaim, ClaimModel toClaim) {
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
116 // fromClaim ---prev---> toClaim
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
117 return setLabel(fromClaim.getVertex(), toClaim.getVertex(), NodeModel.L_PREV );
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
118 }
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
119
20
34ea98c5a18c modified UserModel/getEdgeInUser
one
parents: 18
diff changeset
120 public Boolean setLabelToUsers(ClaimModel claim, String[] users, String label) {
18
one
parents: 17
diff changeset
121 for (String userName: users) {
76
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
122 Vertex userVertex = getVertex(userName);
57
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
123 if (userVertex == null) {
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
124 return false;
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
125 }
20
34ea98c5a18c modified UserModel/getEdgeInUser
one
parents: 18
diff changeset
126 setLabel(claim.getVertex(), userVertex, label);
18
one
parents: 17
diff changeset
127 }
one
parents: 17
diff changeset
128 return true;
16
7cdc9d19834f modified createClaim
one
parents: 13
diff changeset
129 }
9
d050b7fb4cda create getUserRequests action
one
parents: 8
diff changeset
130
36
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
131 public Boolean setLabelStatusToUser(ClaimModel claim, String userName, String label, String status) {
76
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
132 Vertex userVertex = getVertex(userName);
36
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
133 if (userVertex == null) {
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
134 return false;
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
135 }
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
136 Edge edge = setLabel(claim.getVertex(), userVertex, label);
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
137 edge.setProperty(NodeModel.STATUS, status);
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
138 return true;
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
139 }
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
140
30
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 27
diff changeset
141 public Boolean setLabelStatusToUsers(ClaimModel claim, String[] users, String label, String status) {
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 27
diff changeset
142 for (String userName: users) {
36
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
143 Boolean createFlag = setLabelStatusToUser(claim, userName, label, status);
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
144 if (!createFlag) {
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
145 return false;
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
146 }
30
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 27
diff changeset
147 }
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 27
diff changeset
148 return true;
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 27
diff changeset
149 }
80b5628f17d8 modified ClaimModel/getInfo action
one
parents: 27
diff changeset
150
25
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
151 public Edge setLabelMention(ClaimModel fromClaim, ClaimModel toClaim, String label) {
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
152 return setLabel(fromClaim.getVertex(), toClaim.getVertex(), label);
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
153 }
97b249d9fad1 fix infinite loop on getConsensus Action
one
parents: 24
diff changeset
154
40
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
155 public Object[] searchAllUser() {
76
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
156 Vertex userRootVertex = getVertex(getUserRootId());
40
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
157 GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>();
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
158 pipe.start(userRootVertex).out(CHILD);
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
159 ArrayList<Object> userArray = new ArrayList<Object>();
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
160 for (Vertex userVertex : pipe) {
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
161 userArray.add(userVertex.getId());
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
162 }
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
163 if (userArray.size() == 0) {
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
164 return null;
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
165 }
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
166 return userArray.toArray();
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
167 }
1d5c086e069b create getAllUsers() action.
one
parents: 36
diff changeset
168
36
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
169 public Boolean deleteRequestEdge(ClaimModel claim, HashSet<Object> userSet) {
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
170 GremlinPipeline<Vertex,Edge> pipeEdge = new GremlinPipeline<Vertex,Edge>();
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
171 pipeEdge.start(claim.getVertex()).outE(NodeModel.L_REQUEST);
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
172 ArrayList<Edge> deleteEdgeArray = new ArrayList<Edge>();
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
173 for (Edge e : pipeEdge) {
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
174 GremlinPipeline<Edge,Vertex> pipeUserVertex = new GremlinPipeline<Edge,Vertex>();
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
175 pipeUserVertex.start(e).inV();
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
176 Vertex userVertex = pipeUserVertex.next();
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
177 if (userSet.contains(userVertex.getId())) {
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
178 deleteEdgeArray.add(e);
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
179 }
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
180 }
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
181 for (Edge e : deleteEdgeArray) {
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
182 graph.removeEdge(e);
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
183 }
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
184 return true;
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
185 }
5f7fcdf98380 create editClaim
one
parents: 35
diff changeset
186
71
c76b3b60eb18 add comment
one
parents: 70
diff changeset
187 /*
c76b3b60eb18 add comment
one
parents: 70
diff changeset
188 * Return CLAIM numbers of top consensus vertex.
c76b3b60eb18 add comment
one
parents: 70
diff changeset
189 */
23
cad8e054fe4b modifying getConsensus action
one
parents: 20
diff changeset
190 public Object[] checkConsensus(HashSet<Object> set) {
cad8e054fe4b modifying getConsensus action
one
parents: 20
diff changeset
191 Iterator<Object> iter = set.iterator();
57
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
192 iter = set.iterator();
27
e246e0dac9c8 modified checkConsensus
one
parents: 26
diff changeset
193 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
194 Object childId = iter.next();
74
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
195 ArrayList<Object> array = getAllUpperVertexId(childId);
50
d6c623e92837 modified routes
one
parents: 40
diff changeset
196 for (Object parentId: array) {
71
c76b3b60eb18 add comment
one
parents: 70
diff changeset
197 /*
c76b3b60eb18 add comment
one
parents: 70
diff changeset
198 * If there is a number of the number of parent and child in the [set],
c76b3b60eb18 add comment
one
parents: 70
diff changeset
199 * remove [childId].
c76b3b60eb18 add comment
one
parents: 70
diff changeset
200 */
24
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
201 if (set.contains(parentId)) {
27
e246e0dac9c8 modified checkConsensus
one
parents: 26
diff changeset
202 if (set.contains(childId)) {
71
c76b3b60eb18 add comment
one
parents: 70
diff changeset
203 set.remove(childId);
27
e246e0dac9c8 modified checkConsensus
one
parents: 26
diff changeset
204 // This behavior is anxiety.
e246e0dac9c8 modified checkConsensus
one
parents: 26
diff changeset
205 iter = set.iterator();
e246e0dac9c8 modified checkConsensus
one
parents: 26
diff changeset
206 }
e246e0dac9c8 modified checkConsensus
one
parents: 26
diff changeset
207 childId = parentId;
24
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
208 }
23
cad8e054fe4b modifying getConsensus action
one
parents: 20
diff changeset
209 }
cad8e054fe4b modifying getConsensus action
one
parents: 20
diff changeset
210 }
24
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
211 return set.toArray();
23
cad8e054fe4b modifying getConsensus action
one
parents: 20
diff changeset
212 }
71
c76b3b60eb18 add comment
one
parents: 70
diff changeset
213
c76b3b60eb18 add comment
one
parents: 70
diff changeset
214 /*
c76b3b60eb18 add comment
one
parents: 70
diff changeset
215 * Return CLAIM numbers of above [id] CLAIM.
c76b3b60eb18 add comment
one
parents: 70
diff changeset
216 */
74
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
217 public ArrayList<Object> getAllUpperVertexId(Object id) {
76
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
218 Vertex startV = getVertex(id);
27
e246e0dac9c8 modified checkConsensus
one
parents: 26
diff changeset
219 ArrayList<Object> vertexArray = new ArrayList<Object>();
57
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
220 while (true) {
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
221 GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>();
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
222 pipe.start(startV).in(NodeModel.L_QUESTION, NodeModel.L_REFUTATION, NodeModel.L_SUGGESTION);
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
223 if (pipe.hasNext()) {
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
224 Vertex e = pipe.next();
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
225 vertexArray.add(e.getId());
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
226 startV = e;
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
227 } else {
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
228 break;
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
229 }
27
e246e0dac9c8 modified checkConsensus
one
parents: 26
diff changeset
230 }
e246e0dac9c8 modified checkConsensus
one
parents: 26
diff changeset
231 return vertexArray;
e246e0dac9c8 modified checkConsensus
one
parents: 26
diff changeset
232 }
e246e0dac9c8 modified checkConsensus
one
parents: 26
diff changeset
233
74
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
234 public Object getOneUpperClaimVertexId(Object id) {
76
41b6f3788cc3 TPGraph wrap graph
one
parents: 75
diff changeset
235 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
236 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
237 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
238 if (pipe.hasNext()) {
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
239 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
240 return v.getId();
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
241 } else {
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
242 return null;
81d1d7c7bcde create getConsensus action. but this action can not test because there is no createMention action.
one
parents: 23
diff changeset
243 }
23
cad8e054fe4b modifying getConsensus action
one
parents: 20
diff changeset
244 }
cad8e054fe4b modifying getConsensus action
one
parents: 20
diff changeset
245
74
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
246 public Object getTopClaimVertexId(Object id) {
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
247 Object v = id;
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
248 Object upV = id;
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
249 while (upV != null) {
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
250 v = upV;
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
251 upV = getOneUpperClaimVertexId(v);
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
252 }
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
253 return v;
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
254 }
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
255
82
cddb5ed942a6 modified copyConsensusTree method
one
parents: 78
diff changeset
256 private void recursiveCopyDownClaimsAndSetLabel(ClaimModel oldUpClaim, ClaimModel latestUpClaim,
cddb5ed942a6 modified copyConsensusTree method
one
parents: 78
diff changeset
257 String timestamp, String... labels) {
75
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
258 for (String label: labels) {
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
259 GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>();
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
260 pipe.start(oldUpClaim.getVertex()).out(label);
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
261 for (Vertex oldDownV : pipe) {
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
262 ClaimModel oldDownClaim = new ClaimModel(oldDownV);
82
cddb5ed942a6 modified copyConsensusTree method
one
parents: 78
diff changeset
263 ClaimModel latestDownClaim = oldDownClaim.cloneAndSetLabelPrev(timestamp);
75
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
264 setLabel(latestUpClaim.getVertex(), latestDownClaim.getVertex(), label);
82
cddb5ed942a6 modified copyConsensusTree method
one
parents: 78
diff changeset
265 recursiveCopyDownClaimsAndSetLabel(oldDownClaim, latestDownClaim, timestamp, labels);
75
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
266 }
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
267 }
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
268 }
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
269
82
cddb5ed942a6 modified copyConsensusTree method
one
parents: 78
diff changeset
270 private ClaimModel copyDownClaims(ClaimModel oldTopClaim, String timestamp) {
cddb5ed942a6 modified copyConsensusTree method
one
parents: 78
diff changeset
271 ClaimModel latestTopClaim = oldTopClaim.cloneAndSetLabelPrev(timestamp);
cddb5ed942a6 modified copyConsensusTree method
one
parents: 78
diff changeset
272 recursiveCopyDownClaimsAndSetLabel(oldTopClaim, latestTopClaim, timestamp,
75
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
273 NodeModel.L_REFUTATION, NodeModel.L_QUESTION, NodeModel.L_SUGGESTION);
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
274 return latestTopClaim;
74
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
275 }
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
276
82
cddb5ed942a6 modified copyConsensusTree method
one
parents: 78
diff changeset
277 public ClaimModel copyConsensusTree(ClaimModel claim, String timestamp) {
77
4c5b3e990712 modified TPGraph.java
one
parents: 76
diff changeset
278 ClaimModel oldTopClaim = new ClaimModel(getVertex(getTopClaimVertexId(claim.getId())));
82
cddb5ed942a6 modified copyConsensusTree method
one
parents: 78
diff changeset
279 ClaimModel latestTopClaim = copyDownClaims(oldTopClaim, timestamp);
75
9448734399db modified copyConsensusTree
one
parents: 74
diff changeset
280 return latestTopClaim;
74
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
281 }
c5ddd2cc52e1 create copyConsensusTree method.
one
parents: 71
diff changeset
282
7
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
283 public void shutdownGraph() {
57
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
284 if (path == null) {
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
285 return;
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
286 } else {
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
287 graph.shutdown();
ed77c5258568 modify getAllUpperClaims
one
parents: 52
diff changeset
288 }
7
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
289 }
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
290
2122c50278bd add Global.java, ande models/*
one
parents:
diff changeset
291 }