Mercurial > hg > Members > nobuyasu > Consensus
changeset 52:f3db6edc61ad
modify checkUnanimously
author | one |
---|---|
date | Thu, 04 Oct 2012 17:04:38 +0900 |
parents | a76259e2ca9f |
children | a405991e39d8 |
files | app/Global.java app/models/ClaimModel.java app/models/TPGraph.java |
diffstat | 3 files changed, 114 insertions(+), 104 deletions(-) [+] |
line wrap: on
line diff
--- a/app/Global.java Thu Oct 04 16:14:56 2012 +0900 +++ b/app/Global.java Thu Oct 04 17:04:38 2012 +0900 @@ -7,7 +7,6 @@ import play.GlobalSettings; import play.Logger; - public class Global extends GlobalSettings { @Override @@ -20,14 +19,11 @@ Vertex userV = graph.addVertex(null); tpgraph.setUserRootId(userV.getId()); } - - @Override - public void onStop(Application app) { - Logger.info("Application shutdown..."); - - } - - - - + + @Override + public void onStop(Application app) { + Logger.info("Application shutdown..."); + + } + }
--- a/app/models/ClaimModel.java Thu Oct 04 16:14:56 2012 +0900 +++ b/app/models/ClaimModel.java Thu Oct 04 17:04:38 2012 +0900 @@ -2,7 +2,6 @@ import java.util.ArrayList; import java.util.HashSet; -import java.util.Iterator; import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.node.ObjectNode; @@ -17,11 +16,10 @@ public class ClaimModel extends NodeModel { - public ClaimModel(Vertex vertex) { super(vertex); } - + public void setClaimProperties(JsonNode toulmin, String type) { String title = toulmin.findPath(TITLE).getTextValue(); String contents = toulmin.findPath(CONTENTS).getTextValue(); @@ -48,6 +46,7 @@ } setProperty(TOULMIN, t); } + public ObjectNode getSimpleClaimInfo() { ObjectNode property = Json.newObject(); property.put(TYPE, Json.toJson(getProperty(TYPE))); @@ -58,7 +57,7 @@ property.put(USERS, Json.toJson(getUsersId())); return property; } - + public ObjectNode getClaimInfoTraverse() { ObjectNode property = Json.newObject(); property.put(TYPE, Json.toJson(getProperty(TYPE))); @@ -69,28 +68,29 @@ property.put(USERS, Json.toJson(getUsersIdAndStatus())); return property; } - + public Object[] getClaimMentionsRecursive() { - GremlinPipeline<Vertex,Edge> pipe = new GremlinPipeline<Vertex,Edge>(); - pipe.start(vertex).outE(L_QUESTION,L_REFUTATION,L_SUGGESTION); - ArrayList<Object> array = new ArrayList<Object>(); - for (Edge e:pipe) { + GremlinPipeline<Vertex, Edge> pipe = new GremlinPipeline<Vertex, Edge>(); + pipe.start(vertex).outE(L_QUESTION, L_REFUTATION, L_SUGGESTION); + ArrayList<Object> array = new ArrayList<Object>(); + for (Edge e : pipe) { String label = e.getLabel(); ObjectNode info = Json.newObject(); info.put(TYPE, Json.toJson(label)); - GremlinPipeline<Edge,Vertex> pipeChildVertex = new GremlinPipeline<Edge,Vertex>(); + GremlinPipeline<Edge, Vertex> pipeChildVertex = new GremlinPipeline<Edge, Vertex>(); pipeChildVertex.start(e).inV(); ClaimModel childClaim = new ClaimModel(pipeChildVertex.next()); info.put(CLAIM, childClaim.getClaimInfoTraverse()); info.put(ID, Json.toJson(childClaim.getId())); - array.add(info); + array.add(info); } return array.toArray(); } - - private Iterable<Vertex> getVertexIterable(Direction direction, String... labels) { - GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>(); - if (direction.equals(Direction.IN)){ + + private Iterable<Vertex> getVertexIterable(Direction direction, + String... labels) { + GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>(); + if (direction.equals(Direction.IN)) { pipe.start(vertex).in(labels); } else if (direction.equals(Direction.OUT)) { pipe.start(vertex).out(labels); @@ -107,8 +107,8 @@ return array; } - private Object[] getVertexArray(Direction direction,String... labels) { - Iterable<Vertex> iter = getVertexIterable(direction,labels); + private Object[] getVertexArray(Direction direction, String... labels) { + Iterable<Vertex> iter = getVertexIterable(direction, labels); if (iter == null) { return null; } @@ -120,16 +120,18 @@ } public Object[] getMentionsId() { - return getVertexArray(Direction.OUT, L_QUESTION,L_REFUTATION,L_SUGGESTION); + return getVertexArray(Direction.OUT, L_QUESTION, L_REFUTATION, + L_SUGGESTION); } - + public Object[] getUsersId() { return getVertexArray(Direction.OUT, L_REQUEST); } - - private Iterable<Edge> getEdgeIterable(Direction direction, String... labels) { - GremlinPipeline<Vertex,Edge> pipe = new GremlinPipeline<Vertex, Edge>(); - if (direction.equals(Direction.IN)){ + + private Iterable<Edge> getEdgeIterable(Direction direction, + String... labels) { + GremlinPipeline<Vertex, Edge> pipe = new GremlinPipeline<Vertex, Edge>(); + if (direction.equals(Direction.IN)) { pipe.start(vertex).inE(labels); } else if (direction.equals(Direction.OUT)) { pipe.start(vertex).outE(labels); @@ -145,14 +147,13 @@ } return array; } - - - public Object[] getEdgeArray(Direction direction,String... labels) { - Iterable<Edge> iter = getEdgeIterable(direction, labels); -/* - GremlinPipeline<Vertex,Edge> pipe = new GremlinPipeline<Vertex,Edge>(); - pipe.start(vertex).outE(labels); - */ + + public Object[] getEdgeArray(Direction direction, String... labels) { + Iterable<Edge> iter = getEdgeIterable(direction, labels); + /* + * GremlinPipeline<Vertex,Edge> pipe = new + * GremlinPipeline<Vertex,Edge>(); pipe.start(vertex).outE(labels); + */ ArrayList<Object> array = new ArrayList<Object>(); for (Edge e : iter) { array.add(e.getId()); @@ -162,48 +163,49 @@ } return array.toArray(); } - + public Object[] getRequestEdges() { - return getEdgeArray(Direction.OUT,L_REQUEST); + return getEdgeArray(Direction.OUT, L_REQUEST); } - + public ObjectNode getUserRequestStatus(UserModel user) { - GremlinPipeline<Vertex,Edge> pipeEdge = new GremlinPipeline<Vertex,Edge>(); + GremlinPipeline<Vertex, Edge> pipeEdge = new GremlinPipeline<Vertex, Edge>(); pipeEdge.start(vertex).outE(L_REQUEST); ObjectNode info = Json.newObject(); for (Edge e : pipeEdge) { - GremlinPipeline<Edge,Vertex> pipeChildVertex = new GremlinPipeline<Edge,Vertex>(); + GremlinPipeline<Edge, Vertex> pipeChildVertex = new GremlinPipeline<Edge, Vertex>(); pipeChildVertex.start(e).inV(); Vertex childVertex = pipeChildVertex.next(); if (childVertex.getId() == user.getId()) { info.put(STATUS, Json.toJson(e.getProperty(STATUS))); break; } - } + } return info; } - - public Boolean updateUserRequestStatus(ClaimModel claim, UserModel user, String status) { - GremlinPipeline<Vertex,Edge> pipeEdge = new GremlinPipeline<Vertex,Edge>(); + + public Boolean updateUserRequestStatus(ClaimModel claim, UserModel user, + String status) { + GremlinPipeline<Vertex, Edge> pipeEdge = new GremlinPipeline<Vertex, Edge>(); pipeEdge.start(vertex).outE(L_REQUEST); for (Edge e : pipeEdge) { - GremlinPipeline<Edge,Vertex> pipeChildVertex = new GremlinPipeline<Edge,Vertex>(); + GremlinPipeline<Edge, Vertex> pipeChildVertex = new GremlinPipeline<Edge, Vertex>(); pipeChildVertex.start(e).inV(); Vertex childVertex = pipeChildVertex.next(); if (childVertex.getId() == user.getId()) { e.setProperty(STATUS, status); break; } - } + } return true; } - + public Object[] getUsersIdAndStatus() { - GremlinPipeline<Vertex,Edge> pipeEdge = new GremlinPipeline<Vertex,Edge>(); + GremlinPipeline<Vertex, Edge> pipeEdge = new GremlinPipeline<Vertex, Edge>(); pipeEdge.start(vertex).outE(L_REQUEST); ArrayList<Object> array = new ArrayList<Object>(); for (Edge e : pipeEdge) { - GremlinPipeline<Edge,Vertex> pipeChildVertex = new GremlinPipeline<Edge,Vertex>(); + GremlinPipeline<Edge, Vertex> pipeChildVertex = new GremlinPipeline<Edge, Vertex>(); ObjectNode info = Json.newObject(); pipeChildVertex.start(e).inV(); Vertex childVertex = pipeChildVertex.next(); @@ -217,7 +219,7 @@ public Object[] getRequestUsersId() { return getVertexArray(Direction.OUT, NodeModel.REQUESTS); } - + public void editRequestsEdgeUsers(Object[] updateUsers) { TPGraph tpGraph = TPGraph.getInstance(); Object[] currentUsers = getUsersId(); @@ -229,14 +231,15 @@ if (currentUsersHashSet.contains(updateUser)) { currentUsersHashSet.remove(updateUser); } else { - tpGraph.setLabelStatusToUser(this, updateUser.toString(), L_REQUEST, UNKNOWN); + tpGraph.setLabelStatusToUser(this, updateUser.toString(), + L_REQUEST, UNKNOWN); } } tpGraph.deleteRequestEdge(this, currentUsersHashSet); } - + public Object getAuthorId() { - GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>(); + GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>(); pipe.start(vertex).out(L_AUTHOR); if (!pipe.hasNext()) { return null; @@ -244,21 +247,19 @@ Vertex authorV = pipe.next(); return authorV.getId(); } - - public long getAgreedNumber(Object[] requestEdges) { return getEdgeStatusNumber(requestEdges, AGREED); } - + public long getDeninedNumber(Object[] requestEdges) { - return getEdgeStatusNumber(requestEdges, DENIED); + return getEdgeStatusNumber(requestEdges, DENIED); } - + public long getDeniedNumber(Object[] requestEdges) { return getEdgeStatusNumber(requestEdges, DENIED); } - + private long getEdgeStatusNumber(Object[] requestEdges, String checkStatus) { TPGraph tpGraph = TPGraph.getInstance(); Graph graph = tpGraph.getGraph(); @@ -272,60 +273,72 @@ } return count; } - - private Boolean checkUnanimously(String inverseRefutationStatus, String queAndSugStatus, long requestsNumber, long agreedNumber, long deniedNumber) { + + private Boolean checkUnanimously(String inverseRefutationStatus, + String queAndSugStatus, long requestsNumber, long agreedNumber, + long deniedNumber) { String preStatus = getProperty(STATUS).toString(); - if ( inverseRefutationStatus == null && queAndSugStatus == null) { + if (inverseRefutationStatus == null && queAndSugStatus == null) { if (requestsNumber == agreedNumber) { setProperty(STATUS, PASS); } else if (requestsNumber == deniedNumber) { - setProperty(STATUS, FAILED); + setProperty(STATUS, FAILED); } else { - setProperty(STATUS, UNKNOWN); - } - } else if (inverseRefutationStatus != null && queAndSugStatus == null) { - if (inverseRefutationStatus.equals(FAILED)) { - setProperty(STATUS, FAILED); - } else if (requestsNumber == agreedNumber && inverseRefutationStatus.equals(PASS)) { - setProperty(STATUS, PASS); - } else { - setProperty(STATUS, UNKNOWN); + setProperty(STATUS, UNKNOWN); } } else if (inverseRefutationStatus == null && queAndSugStatus != null) { if (requestsNumber == agreedNumber && queAndSugStatus.equals(PASS)) { setProperty(STATUS, PASS); - } else if (requestsNumber == deniedNumber && queAndSugStatus.equals(FAILED)) { - setProperty(STATUS, FAILED); - } - } else if (inverseRefutationStatus.equals(queAndSugStatus)){ - setProperty(STATUS, inverseRefutationStatus); - } else { - setProperty(STATUS, UNKNOWN); + } else if (requestsNumber == deniedNumber + && queAndSugStatus.equals(FAILED)) { + setProperty(STATUS, FAILED); + } + } else if (inverseRefutationStatus != null & queAndSugStatus == null) { + if (requestsNumber == agreedNumber && inverseRefutationStatus.equals(PASS)) { + setProperty(STATUS, PASS); + } else if (requestsNumber == deniedNumber + && inverseRefutationStatus.equals(FAILED)) { + setProperty(STATUS, FAILED); + } + }else if (inverseRefutationStatus != null & queAndSugStatus != null) { + String childStatus = UNKNOWN; + if (inverseRefutationStatus.equals(queAndSugStatus)) { + childStatus = inverseRefutationStatus; + } + if ( requestsNumber == agreedNumber && childStatus.equals(PASS) ){ + setProperty(STATUS, PASS); + } else if ( requestsNumber == deniedNumber && childStatus.equals(DENIED)) { + setProperty(STATUS, FAILED); + } else { + setProperty(STATUS, UNKNOWN); + } } String nowStatus = getProperty(STATUS).toString(); return nowStatus.equals(preStatus); } - - private Boolean checkMajority(long requestsNumber, long agreedNumber, long deniedNumber) { + + private Boolean checkMajority(long requestsNumber, long agreedNumber, + long deniedNumber) { // TODO return false; } - + public void computeAndUpdateStatus() { /* Check child claim */ String inverseRefutationStatus = checkRefutationClaims(); String queAndSugStatus = checkQuestionAndSuggestionClaims(); /* Check user request status */ - Object[] requestEdges = getRequestEdges(); + Object[] requestEdges = getRequestEdges(); String type = getProperty(TYPE).toString(); - long requestsNumber = requestEdges.length; + long requestsNumber = requestEdges.length; long agreedNumber = getAgreedNumber(requestEdges); long deniedNumber = getDeninedNumber(requestEdges); Boolean notChanged = false; if (type.equals(UNANIMOUSLY)) { - notChanged = checkUnanimously(inverseRefutationStatus, queAndSugStatus, requestsNumber, agreedNumber, deniedNumber); + notChanged = checkUnanimously(inverseRefutationStatus, + queAndSugStatus, requestsNumber, agreedNumber, deniedNumber); } else if (type.equals(MAJORITY)) { - + } else { notChanged = false; } @@ -333,14 +346,15 @@ return; } ClaimModel parentClaim = new ClaimModel(getParentVertex()); - if (parentClaim.getVertex() == null) { // If parentClaim is Root. + if (parentClaim.getVertex() == null) { // If parentClaim is Root. return; } - parentClaim.computeAndUpdateStatus(); + parentClaim.computeAndUpdateStatus(); } - + private String checkQuestionAndSuggestionClaims() { - Iterable<Vertex> iter = getVertexIterable(Direction.OUT, L_QUESTION, L_SUGGESTION); + Iterable<Vertex> iter = getVertexIterable(Direction.OUT, L_QUESTION, + L_SUGGESTION); if (iter == null) { return null; } @@ -356,7 +370,7 @@ } return status; } - + private String checkRefutationClaims() { Iterable<Vertex> iter = getVertexIterable(Direction.OUT, L_REFUTATION); if (iter == null) { @@ -377,9 +391,9 @@ if (status.equals(FAILED)) { return PASS; } - return UNKNOWN; + return UNKNOWN; } - + private String checkAllChildsStatus() { String queAndSugStatus = checkQuestionAndSuggestionClaims(); String refutationStatus = checkRefutationClaims(); @@ -391,10 +405,10 @@ return UNKNOWN; } } - + private Vertex getParentVertex() { - GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>(); - pipe.start(vertex).in(L_QUESTION,L_REFUTATION,L_SUGGESTION); + GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>(); + pipe.start(vertex).in(L_QUESTION, L_REFUTATION, L_SUGGESTION); if (pipe.hasNext()) { return pipe.next(); }