コード例 #1
0
  public void testReadingTinkerGraph(Graph graph) throws Exception {
    if (!config.ignoresSuppliedIds) {

      this.stopWatch();
      GraphMLReader.inputGraph(
          graph, GraphMLReader.class.getResourceAsStream("graph-example-1.xml"));
      BaseTest.printPerformance(graph.toString(), null, "graph-example-1 loaded", this.stopWatch());

      assertEquals(count(graph.getVertex("1").getOutEdges()), 3);
      assertEquals(count(graph.getVertex("1").getInEdges()), 0);
      Vertex marko = graph.getVertex("1");
      assertEquals(marko.getProperty("name"), "marko");
      assertEquals(marko.getProperty("age"), 29);
      int counter = 0;
      for (Edge e : graph.getVertex("1").getOutEdges()) {
        if (e.getInVertex().getId().equals("2")) {
          // assertEquals(e.getProperty("weight"), 0.5);
          assertEquals(e.getLabel(), "knows");
          assertEquals(e.getId(), "7");
          counter++;
        } else if (e.getInVertex().getId().equals("3")) {
          assertEquals(Math.round((Float) e.getProperty("weight")), 0);
          assertEquals(e.getLabel(), "created");
          assertEquals(e.getId(), "9");
          counter++;
        } else if (e.getInVertex().getId().equals("4")) {
          assertEquals(Math.round((Float) e.getProperty("weight")), 1);
          assertEquals(e.getLabel(), "knows");
          assertEquals(e.getId(), "8");
          counter++;
        }
      }

      assertEquals(count(graph.getVertex("4").getOutEdges()), 2);
      assertEquals(count(graph.getVertex("4").getInEdges()), 1);
      Vertex josh = graph.getVertex("4");
      assertEquals(josh.getProperty("name"), "josh");
      assertEquals(josh.getProperty("age"), 32);
      for (Edge e : graph.getVertex("4").getOutEdges()) {
        if (e.getInVertex().getId().equals("3")) {
          assertEquals(Math.round((Float) e.getProperty("weight")), 0);
          assertEquals(e.getLabel(), "created");
          assertEquals(e.getId(), "11");
          counter++;
        } else if (e.getInVertex().getId().equals("5")) {
          assertEquals(Math.round((Float) e.getProperty("weight")), 1);
          assertEquals(e.getLabel(), "created");
          assertEquals(e.getId(), "10");
          counter++;
        }
      }

      assertEquals(counter, 5);
    }
  }
コード例 #2
0
  public void testEdgeCentricRemoving() {
    final Graph graph = graphTest.generateGraph();

    final Edge a =
        graph.addEdge(
            null, graph.addVertex(null), graph.addVertex(null), convertId(graph, "knows"));
    final Edge b =
        graph.addEdge(
            null, graph.addVertex(null), graph.addVertex(null), convertId(graph, "knows"));
    final Edge c =
        graph.addEdge(
            null, graph.addVertex(null), graph.addVertex(null), convertId(graph, "knows"));

    Object cId = c.getId();

    if (graph.getFeatures().supportsEdgeIteration) assertEquals(count(graph.getEdges()), 3);

    a.remove();
    b.remove();

    if (graph.getFeatures().supportsEdgeRetrieval) assertNotNull(graph.getEdge(cId));

    if (graph.getFeatures().supportsEdgeIteration) assertEquals(count(graph.getEdges()), 1);

    graph.shutdown();
  }
コード例 #3
0
 public boolean alterEdgeVertexInVertex(
     Mutation vertexInMutation, Edge edge, Visibility newVisibility) {
   ColumnVisibility currentColumnVisibility = visibilityToAccumuloVisibility(edge.getVisibility());
   ColumnVisibility newColumnVisibility = visibilityToAccumuloVisibility(newVisibility);
   if (currentColumnVisibility.equals(newColumnVisibility)) {
     return false;
   }
   EdgeInfo edgeInfo =
       new EdgeInfo(
           getNameSubstitutionStrategy().deflate(edge.getLabel()),
           edge.getVertexId(Direction.OUT));
   vertexInMutation.putDelete(
       AccumuloVertex.CF_IN_EDGE, new Text(edge.getId()), currentColumnVisibility);
   vertexInMutation.put(
       AccumuloVertex.CF_IN_EDGE, new Text(edge.getId()), newColumnVisibility, edgeInfo.toValue());
   return true;
 }
コード例 #4
0
  @Override
  public void handle(HttpServletRequest request, HttpServletResponse response, HandlerChain chain)
      throws Exception {
    final String graphEdgeId = getAttributeString(request, "graphEdgeId");
    final String visibilitySource = getRequiredParameter(request, "visibilitySource");

    User user = getUser(request);
    Authorizations authorizations = getAuthorizations(request, user);
    String workspaceId = getActiveWorkspaceId(request);

    Edge graphEdge = graph.getEdge(graphEdgeId, authorizations);
    if (graphEdge == null) {
      respondWithNotFound(response);
      return;
    }

    if (!graph.isVisibilityValid(new Visibility(visibilitySource), authorizations)) {
      LOGGER.warn(
          "%s is not a valid visibility for %s user", visibilitySource, user.getDisplayName());
      respondWithBadRequest(response, "visibilitySource", getString(request, "visibility.invalid"));
      chain.next(request, response);
      return;
    }

    LOGGER.info(
        "changing edge (%s) visibility source to %s",
        graphEdge.getId().toString(), visibilitySource);

    GraphUtil.VisibilityAndElementMutation<Edge> setPropertyResult =
        GraphUtil.updateElementVisibilitySource(
            visibilityTranslator,
            graphEdge,
            GraphUtil.getSandboxStatus(graphEdge, workspaceId),
            visibilitySource,
            workspaceId,
            authorizations);
    auditRepository.auditEdgeElementMutation(
        AuditAction.UPDATE,
        setPropertyResult.elementMutation,
        graphEdge,
        graphEdge.getVertex(Direction.OUT, authorizations),
        graphEdge.getVertex(Direction.IN, authorizations),
        "",
        user,
        setPropertyResult.visibility.getVisibility());

    this.graph.flush();

    this.workQueueRepository.pushGraphPropertyQueue(
        graphEdge,
        null,
        LumifyVisibilityProperties.VISIBILITY_JSON_PROPERTY.getPropertyName(),
        workspaceId,
        visibilitySource);

    JSONObject json = JsonSerializer.toJson(graphEdge, workspaceId, authorizations);
    respondWithJson(response, json);
  }
コード例 #5
0
ファイル: CFG.java プロジェクト: christ66/findbugs
 /**
  * Look up an Edge by its id.
  *
  * @param id the id of the edge to look up
  * @return the Edge, or null if no matching Edge was found
  */
 public Edge lookupEdgeById(int id) {
   Iterator<Edge> i = edgeIterator();
   while (i.hasNext()) {
     Edge edge = i.next();
     if (edge.getId() == id) {
       return edge;
     }
   }
   return null;
 }
コード例 #6
0
 @Override
 public Edge getEdge(String edgeId, EnumSet<FetchHint> fetchHints, Authorizations authorizations) {
   LOGGER.warn("Performing scan of all edges! Override getEdge.");
   for (Edge edge : getEdges(fetchHints, authorizations)) {
     if (edge.getId().equals(edgeId)) {
       return edge;
     }
   }
   return null;
 }
コード例 #7
0
  public void testEdgeIterator() {
    Graph graph = graphTest.getGraphInstance();
    if (graphTest.supportsEdgeIteration) {
      List<String> ids = generateIds(3);
      Vertex v1 = graph.addVertex(convertId(ids.get(0)));
      Vertex v2 = graph.addVertex(convertId(ids.get(1)));
      Vertex v3 = graph.addVertex(convertId(ids.get(2)));
      Edge e1 = graph.addEdge(null, v1, v2, convertId("test"));
      Edge e2 = graph.addEdge(null, v2, v3, convertId("test"));
      Edge e3 = graph.addEdge(null, v3, v1, convertId("test"));

      if (graphTest.supportsVertexIteration) assertEquals(3, count(graph.getVertices()));
      if (graphTest.supportsEdgeIteration) assertEquals(3, count(graph.getEdges()));

      Set<String> edgeIds = new HashSet<String>();
      int count = 0;
      for (Edge e : graph.getEdges()) {
        count++;
        edgeIds.add(e.getId().toString());
        assertEquals(convertId("test"), e.getLabel());
        if (e.getId().toString().equals(e1.getId().toString())) {
          assertEquals(v1, e.getOutVertex());
          assertEquals(v2, e.getInVertex());
        } else if (e.getId().toString().equals(e2.getId().toString())) {
          assertEquals(v2, e.getOutVertex());
          assertEquals(v3, e.getInVertex());
        } else if (e.getId().toString().equals(e3.getId().toString())) {
          assertEquals(v3, e.getOutVertex());
          assertEquals(v1, e.getInVertex());
        } else {
          assertTrue(false);
        }
        // System.out.println(e);
      }
      assertEquals(3, count);
      assertEquals(3, edgeIds.size());
      assertTrue(edgeIds.contains(e1.getId().toString()));
      assertTrue(edgeIds.contains(e2.getId().toString()));
      assertTrue(edgeIds.contains(e3.getId().toString()));
    }
    graph.shutdown();
  }
コード例 #8
0
  public void testEdgeIterator() {
    Graph graph = graphTest.generateGraph();
    if (graph.getFeatures().supportsEdgeIteration) {
      Vertex v1 = graph.addVertex(convertId(graph, "1"));
      Vertex v2 = graph.addVertex(convertId(graph, "2"));
      Vertex v3 = graph.addVertex(convertId(graph, "3"));
      Edge e1 = graph.addEdge(null, v1, v2, convertId(graph, "test"));
      Edge e2 = graph.addEdge(null, v2, v3, convertId(graph, "test"));
      Edge e3 = graph.addEdge(null, v3, v1, convertId(graph, "test"));

      if (graph.getFeatures().supportsVertexIteration) assertEquals(3, count(graph.getVertices()));
      if (graph.getFeatures().supportsEdgeIteration) assertEquals(3, count(graph.getEdges()));

      Set<String> edgeIds = new HashSet<String>();
      int count = 0;
      for (Edge e : graph.getEdges()) {
        count++;
        edgeIds.add(e.getId().toString());
        assertEquals(convertId(graph, "test"), e.getLabel());
        if (e.getId().toString().equals(e1.getId().toString())) {
          assertEquals(v1, e.getVertex(Direction.OUT));
          assertEquals(v2, e.getVertex(Direction.IN));
        } else if (e.getId().toString().equals(e2.getId().toString())) {
          assertEquals(v2, e.getVertex(Direction.OUT));
          assertEquals(v3, e.getVertex(Direction.IN));
        } else if (e.getId().toString().equals(e3.getId().toString())) {
          assertEquals(v3, e.getVertex(Direction.OUT));
          assertEquals(v1, e.getVertex(Direction.IN));
        } else {
          assertTrue(false);
        }
        // System.out.println(e);
      }
      assertEquals(3, count);
      assertEquals(3, edgeIds.size());
      assertTrue(edgeIds.contains(e1.getId().toString()));
      assertTrue(edgeIds.contains(e2.getId().toString()));
      assertTrue(edgeIds.contains(e3.getId().toString()));
    }
    graph.shutdown();
  }
コード例 #9
0
ファイル: Graph.java プロジェクト: ktchuang/ncku_netdb
 public Graph(List<Vertex> vertexes, List<Edge> edges) {
   this.vertexes = new HashSet<Integer>();
   for (int i = 0; i < vertexes.size(); i++) {
     Vertex v = vertexes.get(i);
     this.vertexes.add(v.getId());
   }
   this.edges = new HashSet<Long>();
   for (int i = 0; i < edges.size(); i++) {
     Edge e = edges.get(i);
     this.edges.add(e.getId());
   }
 }
コード例 #10
0
ファイル: NETWriter.java プロジェクト: jeffg2k/blueprints
 private void writeEdgeProperties(Writer writer, Edge e) throws IOException {
   Object blueprintsId = e.getId();
   if (!useId) {
     writeKey(writer, edgeIdKey);
     if (blueprintsId instanceof Number) {
       writeNumberProperty(writer, (Number) blueprintsId);
     } else {
       writeStringProperty(writer, blueprintsId);
     }
   }
   writeProperties(writer, e);
 }
コード例 #11
0
  public void testGetEdges() {
    Graph graph = graphTest.getGraphInstance();
    if (!graphTest.isRDFModel) {
      Vertex v1 = graph.addVertex(null);
      Vertex v2 = graph.addVertex(null);
      Vertex v3 = graph.addVertex(null);

      Edge e1 = graph.addEdge(null, v1, v2, "test1");
      Edge e2 = graph.addEdge(null, v2, v3, "test2");
      Edge e3 = graph.addEdge(null, v3, v1, "test3");

      this.stopWatch();
      assertEquals(graph.getEdge(e1.getId()), e1);
      assertEquals(graph.getEdge(e1.getId()).getInVertex(), v2);
      assertEquals(graph.getEdge(e1.getId()).getOutVertex(), v1);

      assertEquals(graph.getEdge(e2.getId()), e2);
      assertEquals(graph.getEdge(e2.getId()).getInVertex(), v3);
      assertEquals(graph.getEdge(e2.getId()).getOutVertex(), v2);

      assertEquals(graph.getEdge(e3.getId()), e3);
      assertEquals(graph.getEdge(e3.getId()).getInVertex(), v1);
      assertEquals(graph.getEdge(e3.getId()).getOutVertex(), v3);

      BaseTest.printPerformance(graph.toString(), 3, "edges retrieved", this.stopWatch());
    }
    graph.shutdown();
  }
コード例 #12
0
ファイル: Edge.java プロジェクト: pombredanne/codehaus-mojo
 public boolean equals(Object obj) {
   if (this == obj) {
     return true;
   }
   if (!(obj instanceof Node)) {
     return false;
   }
   Edge rhs = (Edge) obj;
   if (rhs.getId().equals(this.getId())) {
     return false;
   }
   return true;
 }
コード例 #13
0
 public void testTinkerGraphEdges(Graph graph) throws Exception {
   if (config.supportsEdgeIteration) {
     this.stopWatch();
     GraphMLReader.inputGraph(
         graph, GraphMLReader.class.getResourceAsStream("graph-example-1.xml"));
     BaseTest.printPerformance(graph.toString(), null, "graph-example-1 loaded", this.stopWatch());
     Set<String> edgeIds = new HashSet<String>();
     Set<String> edgeKeys = new HashSet<String>();
     Set<String> edgeValues = new HashSet<String>();
     int count = 0;
     for (Edge e : graph.getEdges()) {
       count++;
       edgeIds.add(e.getId().toString());
       for (String key : e.getPropertyKeys()) {
         edgeKeys.add(key);
         edgeValues.add(e.getProperty(key).toString());
       }
     }
     assertEquals(count, 6);
     assertEquals(edgeIds.size(), 6);
     assertEquals(edgeKeys.size(), 1);
     assertEquals(edgeValues.size(), 4);
   }
 }
コード例 #14
0
  public void testGetEdges() {
    Graph graph = graphTest.generateGraph();
    Vertex v1 = graph.addVertex(null);
    Vertex v2 = graph.addVertex(null);
    Vertex v3 = graph.addVertex(null);

    Edge e1 = graph.addEdge(null, v1, v2, convertId(graph, "test1"));
    Edge e2 = graph.addEdge(null, v2, v3, convertId(graph, "test2"));
    Edge e3 = graph.addEdge(null, v3, v1, convertId(graph, "test3"));

    if (graph.getFeatures().supportsEdgeRetrieval) {
      this.stopWatch();
      assertEquals(graph.getEdge(e1.getId()), e1);
      assertEquals(graph.getEdge(e1.getId()).getVertex(Direction.IN), v2);
      assertEquals(graph.getEdge(e1.getId()).getVertex(Direction.OUT), v1);

      assertEquals(graph.getEdge(e2.getId()), e2);
      assertEquals(graph.getEdge(e2.getId()).getVertex(Direction.IN), v3);
      assertEquals(graph.getEdge(e2.getId()).getVertex(Direction.OUT), v2);

      assertEquals(graph.getEdge(e3.getId()), e3);
      assertEquals(graph.getEdge(e3.getId()).getVertex(Direction.IN), v1);
      assertEquals(graph.getEdge(e3.getId()).getVertex(Direction.OUT), v3);

      printPerformance(graph.toString(), 3, "edges retrieved", this.stopWatch());
    }

    assertEquals(getOnlyElement(v1.getEdges(Direction.OUT)), e1);
    assertEquals(getOnlyElement(v1.getEdges(Direction.OUT)).getVertex(Direction.IN), v2);
    assertEquals(getOnlyElement(v1.getEdges(Direction.OUT)).getVertex(Direction.OUT), v1);

    assertEquals(getOnlyElement(v2.getEdges(Direction.OUT)), e2);
    assertEquals(getOnlyElement(v2.getEdges(Direction.OUT)).getVertex(Direction.IN), v3);
    assertEquals(getOnlyElement(v2.getEdges(Direction.OUT)).getVertex(Direction.OUT), v2);

    assertEquals(getOnlyElement(v3.getEdges(Direction.OUT)), e3);
    assertEquals(getOnlyElement(v3.getEdges(Direction.OUT)).getVertex(Direction.IN), v1);
    assertEquals(getOnlyElement(v3.getEdges(Direction.OUT)).getVertex(Direction.OUT), v3);

    graph.shutdown();
  }
コード例 #15
0
  public void testTransactionsForEdges() {
    TransactionalGraph graph = (TransactionalGraph) graphTest.generateGraph();

    Vertex v = graph.addVertex(null);
    Vertex u = graph.addVertex(null);
    graph.stopTransaction(Conclusion.SUCCESS);

    this.stopWatch();
    Edge e =
        graph.addEdge(
            null, graph.getVertex(v.getId()), graph.getVertex(u.getId()), convertId(graph, "test"));

    assertEquals(graph.getVertex(v.getId()), v);
    assertEquals(graph.getVertex(u.getId()), u);
    if (graph.getFeatures().supportsEdgeRetrieval) assertEquals(graph.getEdge(e.getId()), e);

    vertexCount(graph, 2);
    edgeCount(graph, 1);

    graph.stopTransaction(Conclusion.FAILURE);
    printPerformance(
        graph.toString(),
        1,
        "edge not added in failed transaction (w/ iteration)",
        this.stopWatch());

    assertEquals(graph.getVertex(v.getId()), v);
    assertEquals(graph.getVertex(u.getId()), u);
    if (graph.getFeatures().supportsEdgeRetrieval) assertNull(graph.getEdge(e.getId()));

    if (graph.getFeatures().supportsVertexIteration) assertEquals(count(graph.getVertices()), 2);
    if (graph.getFeatures().supportsEdgeIteration) assertEquals(count(graph.getEdges()), 0);

    this.stopWatch();

    e =
        graph.addEdge(
            null, graph.getVertex(u.getId()), graph.getVertex(v.getId()), convertId(graph, "test"));

    assertEquals(graph.getVertex(v.getId()), v);
    assertEquals(graph.getVertex(u.getId()), u);
    if (graph.getFeatures().supportsEdgeRetrieval) assertEquals(graph.getEdge(e.getId()), e);

    if (graph.getFeatures().supportsVertexIteration) assertEquals(count(graph.getVertices()), 2);
    if (graph.getFeatures().supportsEdgeIteration) assertEquals(count(graph.getEdges()), 1);
    assertEquals(e, getOnlyElement(graph.getVertex(u.getId()).getEdges(Direction.OUT)));
    graph.stopTransaction(Conclusion.SUCCESS);
    printPerformance(
        graph.toString(),
        1,
        "edge added in successful transaction (w/ iteration)",
        this.stopWatch());

    if (graph.getFeatures().supportsVertexIteration) assertEquals(count(graph.getVertices()), 2);
    if (graph.getFeatures().supportsEdgeIteration) assertEquals(count(graph.getEdges()), 1);

    assertEquals(graph.getVertex(v.getId()), v);
    assertEquals(graph.getVertex(u.getId()), u);
    if (graph.getFeatures().supportsEdgeRetrieval) assertEquals(graph.getEdge(e.getId()), e);
    assertEquals(e, getOnlyElement(graph.getVertex(u.getId()).getEdges(Direction.OUT)));

    graph.shutdown();
  }
コード例 #16
0
  private TermMentionWithGraphVertex saveTermMention(
      Vertex artifactGraphVertex,
      TermMention termMention,
      String workspaceId,
      String visibilitySource) {
    LOGGER.debug(
        "Saving term mention '%s':%s:%s (%d:%d)",
        termMention.getSign(),
        termMention.getOntologyClassUri(),
        termMention.getPropertyKey(),
        termMention.getStart(),
        termMention.getEnd());
    Vertex vertex = null;
    if (visibilitySource == null) {
      visibilitySource = termMention.getVisibility().getVisibilityString();
    }

    JSONObject visibilityJson = new JSONObject();
    visibilityJson.put(VisibilityTranslator.JSON_SOURCE, visibilitySource);
    Visibility visibility = visibilityTranslator.toVisibility(visibilityJson).getVisibility();

    Visibility visibilityWithWorkspaceId;
    JSONObject visibilityJsonWithWorkspaceId;
    if (!workspaceId.equals("")) {
      visibilityJsonWithWorkspaceId =
          GraphUtil.updateVisibilitySourceAndAddWorkspaceId(null, visibilitySource, workspaceId);
      visibilityWithWorkspaceId =
          visibilityTranslator.toVisibility(visibilityJsonWithWorkspaceId).getVisibility();
    } else {
      visibilityWithWorkspaceId = visibility;
      visibilityJsonWithWorkspaceId = visibilityJson;
    }

    TermMentionRowKey termMentionRowKey =
        new TermMentionRowKey(
            artifactGraphVertex.getId().toString(),
            termMention.getPropertyKey(),
            termMention.getStart(),
            termMention.getEnd());
    TermMentionModel termMentionModel = new TermMentionModel(termMentionRowKey);
    termMentionModel.getMetadata().setSign(termMention.getSign(), visibility);
    termMentionModel
        .getMetadata()
        .setOntologyClassUri(termMention.getOntologyClassUri(), visibility);
    if (termMention.getProcess() != null && !termMention.getProcess().equals("")) {
      termMentionModel.getMetadata().setAnalyticProcess(termMention.getProcess(), visibility);
    }

    Concept concept = ontologyRepository.getConceptByIRI(termMention.getOntologyClassUri());
    if (concept == null) {
      LOGGER.error("Could not find ontology graph vertex '%s'", termMention.getOntologyClassUri());
      return null;
    }
    termMentionModel.getMetadata().setConceptGraphVertexId(concept.getTitle(), visibility);

    if (termMention.isResolved()) {
      String title = termMention.getSign();
      ElementMutation<Vertex> vertexElementMutation;
      if (termMention.getUseExisting()) {
        graph.flush(); // make sure the previous term mentions have made it into the graph
        if (termMention.getId() != null) {
          vertex = graph.getVertex(termMention.getId(), getAuthorizations());
        } else {
          vertex =
              singleOrDefault(
                  graph
                      .query(getAuthorizations())
                      .has(LumifyProperties.TITLE.getPropertyName(), title)
                      .has(LumifyProperties.CONCEPT_TYPE.getPropertyName(), concept.getTitle())
                      .vertices(),
                  null);
        }
      }

      Map<String, Object> metadata = new HashMap<String, Object>();
      LumifyVisibilityProperties.VISIBILITY_JSON_PROPERTY.setMetadata(
          metadata, visibilityJsonWithWorkspaceId);

      if (vertex == null) {
        if (termMention.getId() != null) {
          vertexElementMutation =
              graph.prepareVertex(termMention.getId(), visibilityWithWorkspaceId);
        } else {
          vertexElementMutation = graph.prepareVertex(visibilityWithWorkspaceId);
        }
        LumifyProperties.TITLE.setProperty(
            vertexElementMutation, title, metadata, visibilityWithWorkspaceId);
        LumifyProperties.CONCEPT_TYPE.setProperty(
            vertexElementMutation, concept.getTitle(), metadata, visibilityWithWorkspaceId);
      } else {
        vertexElementMutation = vertex.prepareMutation();
      }

      for (TermMention.TermMentionProperty termMentionProperty : termMention.getNewProperties()) {
        vertexElementMutation.addPropertyValue(
            termMentionProperty.getKey(),
            termMentionProperty.getName(),
            termMentionProperty.getValue(),
            metadata,
            visibilityWithWorkspaceId);
      }

      LumifyVisibilityProperties.VISIBILITY_JSON_PROPERTY.setProperty(
          vertexElementMutation,
          visibilityJsonWithWorkspaceId,
          metadata,
          visibilityWithWorkspaceId);
      vertexElementMutation.addPropertyValue(
          graph.getIdGenerator().nextId(),
          LumifyProperties.ROW_KEY.getPropertyName(),
          termMentionRowKey.toString(),
          metadata,
          visibilityWithWorkspaceId);

      if (!(vertexElementMutation instanceof ExistingElementMutation)) {
        vertex = vertexElementMutation.save(getAuthorizations());
        auditRepository.auditVertexElementMutation(
            AuditAction.UPDATE,
            vertexElementMutation,
            vertex,
            termMention.getProcess(),
            getUser(),
            visibilityWithWorkspaceId);
      } else {
        auditRepository.auditVertexElementMutation(
            AuditAction.UPDATE,
            vertexElementMutation,
            vertex,
            termMention.getProcess(),
            getUser(),
            visibilityWithWorkspaceId);
        vertex = vertexElementMutation.save(getAuthorizations());
      }

      // TODO: a better way to check if the same edge exists instead of looking it up every time?
      Edge edge =
          singleOrDefault(
              artifactGraphVertex.getEdges(
                  vertex, Direction.OUT, artifactHasEntityIri, getAuthorizations()),
              null);
      if (edge == null) {
        edge =
            graph.addEdge(
                artifactGraphVertex, vertex, artifactHasEntityIri, visibility, getAuthorizations());
        LumifyVisibilityProperties.VISIBILITY_JSON_PROPERTY.setProperty(
            edge,
            visibilityJsonWithWorkspaceId,
            metadata,
            visibilityWithWorkspaceId,
            getAuthorizations());
        auditRepository.auditRelationship(
            AuditAction.CREATE,
            artifactGraphVertex,
            vertex,
            edge,
            termMention.getProcess(),
            "",
            getUser(),
            visibilityWithWorkspaceId);
      }

      graph.flush();
      if (workspaceId != null && !workspaceId.equals("")) {
        Workspace workspace = workspaceRepository.findById(workspaceId, getUser());
        workspaceRepository.updateEntityOnWorkspace(
            workspace, vertex.getId(), null, null, null, getUser());
      }

      termMentionModel
          .getMetadata()
          .setVertexId(vertex.getId().toString(), visibility)
          .setEdgeId(edge.getId().toString(), visibility);
    }

    getTermMentionRepository().save(termMentionModel, FlushFlag.NO_FLUSH);
    return new TermMentionWithGraphVertex(termMentionModel, vertex);
  }
コード例 #17
0
  /** Specified in Node */
  protected Node makeBinary(Collection newedges, Edge[] edgemapping, Node caller) {
    // O(n) each edge is visited 1 time in the first part
    // In the second part an upper bound of the total number
    // of runs through the while-loop is O(n) (number of edges).
    Iterator it = edges.iterator();
    Edge e1, e2, newedge1, newedge2, next;
    InnerNode thiscopy = new InnerNode();
    Node tmp;

    // first part (recursion)
    while (it.hasNext()) { // Invoke recursively    //Like the copy-method
      next = (Edge) it.next();
      if (next.to != caller) {
        tmp = next.to.makeBinary(newedges, edgemapping, this);
        e1 = thiscopy.addNeighbour(tmp);
        e2 = tmp.addNeighbour(thiscopy);
        e1.backedge = e2;
        e2.backedge = e1;
        edgemapping[next.getId()] = e1;
        edgemapping[next.getBackEdge().getId()] = e2;
      }
    }

    // second part (fixing degree with a while-loop)
    while ((thiscopy.edges.size() > 2 && caller != null)
        || thiscopy.edges.size() > 3) { // not binary
      // System.out.println(thiscopy+" has "+thiscopy.edges.size()+" edges");
      it = thiscopy.edges.iterator();
      e1 =
          (Edge)
              it.next(); // 1               //Save two outgoing edges (e1 and e2) for binarification
      if (e1.to == caller) e1 = (Edge) it.next(); // 1 or 2
      it.remove(); // Remove this edge from the edge list, see why below **
      e2 = (Edge) it.next(); // 2 or 3
      if (e2.to == caller)
        e2 =
            (Edge)
                it
                    .next(); // 3  //since edges.size() >=4 I can get three elements out without
                             // problems
      it.remove(); // Remove this edge from the edge list, see why below **

      // e1 and e2 are two outgoing edges that does not lead back to the caller

      InnerNode newnode = new InnerNode(); // Make a new node to attach e1 and e2 to

      newedge1 = thiscopy.addNeighbour(newnode); // attach this node to the new node
      newedge2 = newnode.addNeighbour(thiscopy); // and vice versa
      newedge1.backedge = newedge2;
      newedge2.backedge = newedge1;
      newedges.add(newedge1); // Since these edges are new edges, add them to the collection
      newedges.add(newedge2);

      // Now instead of using removeNeighbour and that stuff, we use a 'hack'. We change the
      // endpoint of the
      // edges between 'e1' and 'thiscopy' to 'e1' and 'newnode', and 'e2' and 'thiscopy' to 'e2'
      // and 'newnode' respectively.
      // This way any new edge already added to the newedges-collection is still valid.

      e1.from = newnode; // change the endpoints
      e2.from = newnode;
      e1.getBackEdge().to = newnode; //
      e2.getBackEdge().to = newnode;

      // now we need to remove e1 and e2 from this nodes edgelist and add them to newnode's edge
      // list, but we
      // already did half of that above **
      newnode.edges.add(e1);
      newnode.edges.add(e2); // the other half well done.

      // For each run of this while-loop one neighbour is added and two are removed, hence it must
      // terminate.
    }

    return thiscopy;
  }