annotate app/models/TPGraph.java @ 74:c5ddd2cc52e1 draft

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