private void saveVertexRelationships(
      List<VertexRelationship> vertexRelationships,
      List<TermMentionWithGraphVertex> termMentionsWithGraphVertices) {
    for (VertexRelationship vertexRelationship : vertexRelationships) {
      TermMentionWithGraphVertex sourceTermMentionsWithGraphVertex =
          findTermMentionWithGraphVertex(
              termMentionsWithGraphVertices, vertexRelationship.getSource());
      checkNotNull(sourceTermMentionsWithGraphVertex, "Could not find source");
      checkNotNull(sourceTermMentionsWithGraphVertex.getVertex(), "Could not find source vertex");

      Vertex targetVertex = graph.getVertex(vertexRelationship.getTargetId(), getAuthorizations());
      checkNotNull(sourceTermMentionsWithGraphVertex, "Could not find target vertex");

      String label = vertexRelationship.getLabel();
      checkNotNull(label, "label is required");

      Edge edge =
          trySingle(
              sourceTermMentionsWithGraphVertex
                  .getVertex()
                  .getEdges(targetVertex, Direction.OUT, label, getAuthorizations()));
      if (edge == null) {
        LOGGER.debug(
            "adding edge %s -> %s (%s)",
            sourceTermMentionsWithGraphVertex.getVertex().getId(), targetVertex.getId(), label);
        graph.addEdge(
            sourceTermMentionsWithGraphVertex.getVertex(),
            targetVertex,
            label,
            vertexRelationship.getVisibility(),
            getAuthorizations());
      }
    }
  }
示例#2
0
 private TermMentionWithGraphVertex findTermMentionWithGraphVertex(
     List<TermMentionWithGraphVertex> termMentionsWithGraphVertices, TermMention termMention) {
   for (TermMentionWithGraphVertex termMentionsWithGraphVertex : termMentionsWithGraphVertices) {
     if (termMentionsWithGraphVertex.getTermMention().getRowKey().getStartOffset()
             == termMention.getStart()
         && termMentionsWithGraphVertex.getTermMention().getRowKey().getEndOffset()
             == termMention.getEnd()
         && termMentionsWithGraphVertex.getVertex() != null) {
       return termMentionsWithGraphVertex;
     }
   }
   return null;
 }
示例#3
0
  private void saveRelationships(
      List<TermRelationship> relationships,
      List<TermMentionWithGraphVertex> termMentionsWithGraphVertices) {
    for (TermRelationship relationship : relationships) {
      TermMentionWithGraphVertex sourceTermMentionsWithGraphVertex =
          findTermMentionWithGraphVertex(
              termMentionsWithGraphVertices, relationship.getSourceTermMention());
      checkNotNull(
          sourceTermMentionsWithGraphVertex,
          "source was not found for " + relationship.getSourceTermMention());
      checkNotNull(
          sourceTermMentionsWithGraphVertex.getVertex(),
          "source vertex was not found for " + relationship.getSourceTermMention());
      TermMentionWithGraphVertex destTermMentionsWithGraphVertex =
          findTermMentionWithGraphVertex(
              termMentionsWithGraphVertices, relationship.getDestTermMention());
      checkNotNull(
          destTermMentionsWithGraphVertex,
          "dest was not found for " + relationship.getDestTermMention());
      checkNotNull(
          destTermMentionsWithGraphVertex.getVertex(),
          "dest vertex was not found for " + relationship.getDestTermMention());
      String label = relationship.getLabel();

      // TODO: a better way to check if the same edge exists instead of looking it up every time?
      Edge edge =
          singleOrDefault(
              sourceTermMentionsWithGraphVertex
                  .getVertex()
                  .getEdges(
                      destTermMentionsWithGraphVertex.getVertex(),
                      Direction.OUT,
                      label,
                      getAuthorizations()),
              null);
      if (edge == null) {
        graph.addEdge(
            sourceTermMentionsWithGraphVertex.getVertex(),
            destTermMentionsWithGraphVertex.getVertex(),
            label,
            relationship.getVisibility(),
            getAuthorizations());
      }
    }
    graph.flush();
  }