       connection = new Connection(row.connection, row.connectionCreator)
       new Triplet(connection, startResource, endResource, data)
 
-    console.log("makeTriplet defined")
-
     pushOutgoingTriplets = (set) ->
       for row in set
         startResource = new Resource(row.resource, row.resourceCreator)

    else
      userNodeId = 0

    outgoingRelation =  '(resource) -[:RELATED_TO]-> (connection) -[:RELATED_TO]-> (otherResource)'
    incomingRelation =  '(resource) <-[:RELATED_TO]- (connection) <-[:RELATED_TO]- (otherResource)'

    make2dot0Relation = (direction) ->  "(originRs) -[:RELATED_TO]- () -[:RELATED_TO]- #{direction}"

    outgoing2dot0Relation = make2dot0Relation(outgoingRelation)
    incoming2dot0Relation = make2dot0Relation(incomingRelation)

    #make2dot5Relation = (direction) ->  "(originRs) -[:RELATED_TO]- () -[:RELATED_TO]- () -[:RELATED_TO]- () -[:RELATED_TO]- #{direction} -[:RELATED_TO]- () -[:RELATED_TO]- () -[:RELATED_TO]- () -[:RELATED_TO]- (originRs)"
    make2dot5Relation = (direction) -> "originRs -[:RELATED_TO*4]- #{direction} -[:RELATED_TO*4]- originRs"

    incoming2dot5Relation = make2dot5Relation(incomingRelation)
    outgoing2dot5Relation = make2dot5Relation(outgoingRelation)

    baseQuery = (origin, relation) ->"""
                           START #{origin} = node({resourceNodeId}), user = node(#{userNodeId})
                           MATCH #{relation},
                           (#{origin}) -[:CREATED_BY]- (resourceCreator),
                           (otherResource) -[:CREATED_BY]- (otherResourceCreator),
                           (otherResource) -[?:RELATED_TO]- (otherResourceConnections),
                           (connection) -[?:VOTED_UP]- (upvotes),
                           (connection) -[?:VOTED_DOWN]- (downvotes),
                           (connection) -[:CREATED_BY]- (connectionCreator),
                           (user) -[hasVotedUp?:VOTED_UP]-> (connection),
                           (user) -[hasVotedDown?:VOTED_DOWN]-> (connection),
                           (connection) -[?:COMMENT_OF]- (comments)
                           RETURN connection, connectionCreator, resource, resourceCreator, otherResource, otherResourceCreator,
                           count(distinct comments) AS commentCount,
                           count(distinct otherResourceConnections) AS otherResourceConnectionCount,
                           count(distinct upvotes) AS upVoteCount,
                           count(distinct downvotes) AS downVoteCount,
                           count(distinct hasVotedUp) AS userVotedUp,
                           count(distinct hasVotedDown) AS userVotedDown
                           """

    query1 = (relation) -> baseQuery("resource", relation)

    query2 = (relation) -> baseQuery("originRs", relation)

    console.log("query strings defined")

    outgoingQuery =      query1(outgoingRelation)
    incomingQuery =      query1(incomingRelation)
    outgoing2dot0Query = query2(outgoing2dot0Relation)
    incoming2dot0Query = query2(incoming2dot0Relation)
    outgoing2dot5Query = query2(outgoing2dot5Relation)
    incoming2dot5Query = query2(incoming2dot5Relation)

    console.log("queries defined")

    resource = Resources.find(resourceId, _)
    params =

        endResourceConnectionCount = row.otherResourceConnectionCount
        triplets.push makeTriplet(row, startResource, endResource, startResourceConnectionCount, endResourceConnectionCount)

    pushOutgoingTriplets(outgoingResults)
    pushOutgoingTriplets(outgoing2dot0Results)
    pushOutgoingTriplets(outgoing2dot5Results)

    pushIncomingTriplets = (set) ->
      for row in set
