org.neo4j.graphdb.Relationship.getStartNodeId()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(4.8k)|赞(0)|评价(0)|浏览(121)

本文整理了Java中org.neo4j.graphdb.Relationship.getStartNodeId方法的一些代码示例,展示了Relationship.getStartNodeId的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Relationship.getStartNodeId方法的具体详情如下:
包路径:org.neo4j.graphdb.Relationship
类名称:Relationship
方法名:getStartNodeId

Relationship.getStartNodeId介绍

[英]Returns the id of the start node of this relationship. For a definition of how start node relates to Direction as arguments to the Node#getRelationships() in Node, see the class documentation of Relationship.

Note that this id can get reused in the future, if this relationship and the given node are deleted.
[中]返回此关系的开始节点的id。有关开始节点如何作为节点中节点#getRelationships()的参数与方向关联的定义,请参阅Relationship的类文档。
请注意,如果删除此关系和给定节点,该id将来可以被重用。

代码示例

代码示例来源:origin: neo4j/neo4j

/**
   * A convenience operation that, given an id of a node that is attached to this
   * relationship, returns the id of the other node. For example if <code>id</code> is
   * the start node id, the end node id will be returned, and vice versa.
   * <p>
   * This operation will throw a runtime exception if <code>id</code> is
   * not the id of either of this relationship's nodes.
   * <p>
   * Note that this id can get reused in the future, if this relationship and the given node are deleted.
   *
   * @param id the id of the start or end node of this relationship
   * @return the id of the other node
   * @throws RuntimeException if the given node id is not the id of either the start or end
   *             node of this relationship.
   */
  default long getOtherNodeId( long id )
  {
    long start = getStartNodeId();
    long end = getEndNodeId();
    if ( id == start )
    {
      return end;
    }
    else if ( id == end )
    {
      return start;
    }
    throw new NotFoundException( "Node[" + id + "] not connected to this relationship[" + getId() + "]" );
  }
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldIterateThroughRelationshipsInReverse()
{
  // given
  Path path = new PathProxy( proxySPI, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} );
  Iterator<Relationship> iterator = path.reverseRelationships().iterator();
  Relationship relationship;
  // then
  assertTrue( iterator.hasNext() );
  assertThat( relationship = iterator.next(), instanceOf( Relationship.class ) );
  assertEquals( 200, relationship.getId() );
  assertEquals( 3, relationship.getStartNodeId() );
  assertEquals( 2, relationship.getEndNodeId() );
  assertTrue( iterator.hasNext() );
  assertThat( relationship = iterator.next(), instanceOf( Relationship.class ) );
  assertEquals( 100, relationship.getId() );
  assertEquals( 1, relationship.getStartNodeId() );
  assertEquals( 2, relationship.getEndNodeId() );
  assertFalse( iterator.hasNext() );
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldIterateThroughRelationships()
{
  // given
  Path path = new PathProxy( proxySPI, new long[] {1, 2, 3}, new long[] {100, 200}, new int[] {0, ~0} );
  Iterator<Relationship> iterator = path.relationships().iterator();
  Relationship relationship;
  // then
  assertTrue( iterator.hasNext() );
  assertThat( relationship = iterator.next(), instanceOf( Relationship.class ) );
  assertEquals( 100, relationship.getId() );
  assertEquals( 1, relationship.getStartNodeId() );
  assertEquals( 2, relationship.getEndNodeId() );
  assertTrue( iterator.hasNext() );
  assertThat( relationship = iterator.next(), instanceOf( Relationship.class ) );
  assertEquals( 200, relationship.getId() );
  assertEquals( 3, relationship.getStartNodeId() );
  assertEquals( 2, relationship.getEndNodeId() );
  assertFalse( iterator.hasNext() );
}

代码示例来源:origin: neo4j/neo4j

private boolean relationshipExistsByQuery( RelationshipIndex index, Node startNode, Node endNode, boolean specifyStartNode )
{
  boolean found = false;
  try ( Transaction tx = db.beginTx(); IndexHits<Relationship> query = index
      .query( "key", QueryContext.numericRange( "key", 0, 3 ), specifyStartNode ? startNode : null, null ) )
  {
    for ( Relationship relationship : query )
    {
      if ( relationship.getStartNodeId() == startNode.getId() && relationship.getEndNodeId() == endNode.getId() )
      {
        found = true;
        break;
      }
    }
    tx.success();
  }
  return found;
}

代码示例来源:origin: graphaware/neo4j-nlp

private Set<Long> getKeywordIds(Node annotatedText) {
  Set<Long> ids = new HashSet<>();
  if (annotatedText != null) {
    annotatedText.getRelationships(Direction.INCOMING, Relationships.DESCRIBES).forEach(relationship -> {
      ids.add(relationship.getStartNodeId());
    });
  }
  return ids;
}

代码示例来源:origin: org.neo4j/neo4j-graphdb-api

/**
   * A convenience operation that, given an id of a node that is attached to this
   * relationship, returns the id of the other node. For example if <code>id</code> is
   * the start node id, the end node id will be returned, and vice versa.
   * <p>
   * This operation will throw a runtime exception if <code>id</code> is
   * not the id of either of this relationship's nodes.
   * <p>
   * Note that this id can get reused in the future, if this relationship and the given node are deleted.
   *
   * @param id the id of the start or end node of this relationship
   * @return the id of the other node
   * @throws RuntimeException if the given node id is not the id of either the start or end
   *             node of this relationship.
   */
  default long getOtherNodeId( long id )
  {
    long start = getStartNodeId();
    long end = getEndNodeId();
    if ( id == start )
    {
      return end;
    }
    else if ( id == end )
    {
      return start;
    }
    throw new NotFoundException( "Node[" + id + "] not connected to this relationship[" + getId() + "]" );
  }
}

相关文章