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

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

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

Relationship.isType介绍

[英]Indicates whether this relationship is of the type type. This is a convenience method that checks for equality using the contract specified by RelationshipType, i.e. by checking for equal RelationshipType#name().
[中]指示此关系是否为type类型。这是一种方便的方法,可以使用RelationshipType指定的约定来检查相等性,即通过检查相等的RelationshipType#name()。

代码示例

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

@Test
public void testRelationshipIsType()
{
  Node node1 = getGraphDb().createNode();
  Node node2 = getGraphDb().createNode();
  Relationship rel = node1.createRelationshipTo( node2, TEST );
  assertTrue( rel.isType( TEST ) );
  assertTrue( rel.isType( TEST::name ) );
  assertFalse( rel.isType( TEST_TRAVERSAL ) );
  rel.delete();
  node1.delete();
  node2.delete();
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

private boolean isType(Relationship r, RelationshipType... relationshipTypes) {
  for (RelationshipType type : relationshipTypes) {
    if (r.isType(type)) return true;
  }
  return false;
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

private boolean isType(Relationship r, RelationshipType... relationshipTypes) {
  for (RelationshipType type : relationshipTypes) {
    if (r.isType(type)) return true;
  }
  return false;
}

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

for ( int i = 0; i < THRESHOLD / 2; i++ )
  assertTrue( relationships.next().isType( TEST ) );
  assertTrue( relationships.next().isType( TEST ) );

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

boolean relIsOfType = rel != null && rel.isType( type );
boolean prune =
    relIsOfType && (Long) path.endNode().getProperty( "timestamp" ) >= timestamp;

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

relationship ->
  if ( relationship.isType( RelationshipType.withName( firstType ) ) )
  else if ( relationship.isType( RelationshipType.withName( secondType ) ) )

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@UserFunction("apoc.label.exists")
  @Description("apoc.label.exists(element, label) - returns true or false related to label existance")
  public boolean exists(@Name("node") Object element, @Name("label") String label) {

    return element instanceof Node ? ((Node) element).hasLabel(org.neo4j.graphdb.Label.label(label)) :
        element instanceof Relationship ? ((Relationship) element).isType(RelationshipType.withName(label)) : false;

  }
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test public void testCreateRelationship() throws Exception {
  testCall(db, "CREATE (n),(m) WITH n,m CALL apoc.create.relationship(n,'KNOWS',{since:2010}, m) YIELD rel RETURN rel",
      (row) -> {
        Relationship rel = (Relationship) row.get("rel");
        assertEquals(true, rel.isType(RelationshipType.withName("KNOWS")));
        assertEquals(2010L, rel.getProperty("since"));
      });
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test public void testCreateVirtualRelationshipFunction() throws Exception {
  testCall(db, "CREATE (n),(m) WITH n,m RETURN apoc.create.vRelationship(n,'KNOWS',{since:2010}, m) AS rel",
      (row) -> {
        Relationship rel = (Relationship) row.get("rel");
        assertEquals(true, rel.isType(RelationshipType.withName("KNOWS")));
        assertEquals(2010L, rel.getProperty("since"));
      });
}
@Test public void testCreatePattern() throws Exception {

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test public void testCreateVirtualRelationship() throws Exception {
  testCall(db, "CREATE (n),(m) WITH n,m CALL apoc.create.vRelationship(n,'KNOWS',{since:2010}, m) YIELD rel RETURN rel",
      (row) -> {
        Relationship rel = (Relationship) row.get("rel");
        assertEquals(true, rel.isType(RelationshipType.withName("KNOWS")));
        assertEquals(2010L, rel.getProperty("since"));
      });
}
@Test public void testCreateVirtualRelationshipFunction() throws Exception {

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test
public void elements() throws Exception {
  TestUtil.testCall(db, "MATCH p = (a:A) RETURN apoc.path.elements(p) as e",(row) -> {
    List<PropertyContainer> pc = (List<PropertyContainer>) row.get("e");
    assertEquals(1,pc.size());
    assertEquals(true,((Node)pc.get(0)).hasLabel(Label.label("A")));
  });
  TestUtil.testCall(db, "MATCH p = (a:A)-->() RETURN apoc.path.elements(p) as e",(row) -> {
    List<PropertyContainer> pc = (List<PropertyContainer>) row.get("e");
    assertEquals(3,pc.size());
    assertEquals(true,((Node)pc.get(0)).hasLabel(Label.label("A")));
    assertEquals(true,((Relationship)pc.get(1)).isType(RelationshipType.withName("NEXT")));
    assertEquals(true,((Node)pc.get(2)).hasLabel(Label.label("B")));
  });
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

assertEquals(4,resultingNode.getDegree(Direction.OUTGOING));
assertEquals(1,c.getDegree(Direction.INCOMING));
assertEquals(true, r.isType(RelationshipType.withName("HAS_REL")));
assertEquals(Arrays.asList( "r2" , "r1"), Arrays.asList((String[])r.getProperty("p")));
assertEquals(true, r1.isType(RelationshipType.withName("HAS_REL")));
assertEquals(Arrays.asList( "r2" , "r1"), Arrays.asList((String[])r1.getProperty("p")));

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test public void testCreatePatternFull() throws Exception {
    testCall(db, "CALL apoc.create.vPatternFull(['Person'],{name:'John'},'KNOWS',{since:2010},['Person'],{name:'Jane'})",
        (row) -> {
          Node john = (Node) row.get("from");
          assertEquals(true, john.hasLabel(PERSON));
          assertEquals("John", john.getProperty("name"));
          Relationship rel = (Relationship) row.get("rel");
          assertEquals(true, rel.isType(RelationshipType.withName("KNOWS")));
          assertEquals(2010L, rel.getProperty("since"));
          Node jane = (Node) row.get("to");
          assertEquals(true, jane.hasLabel(PERSON));
          assertEquals("Jane", jane.getProperty("name"));
        });
  }
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test public void testCreatePattern() throws Exception {
  testCall(db, "CALL apoc.create.vPattern({_labels:['Person'],name:'John'},'KNOWS',{since:2010},{_labels:['Person'],name:'Jane'})",
      (row) -> {
        Node john = (Node) row.get("from");
        assertEquals(true, john.hasLabel(PERSON));
        assertEquals("John", john.getProperty("name"));
        Relationship rel = (Relationship) row.get("rel");
        assertEquals(true, rel.isType(RelationshipType.withName("KNOWS")));
        assertEquals(2010L, rel.getProperty("since"));
        Node jane = (Node) row.get("to");
        assertEquals(true, jane.hasLabel(PERSON));
        assertEquals("Jane", jane.getProperty("name"));
      });
}
@Test public void testCreatePatternFull() throws Exception {

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test
public void testMergeRelsEagerAggregationCombineSingleValuesProperty() throws Exception {
  long id = db.execute("Create (d:Person {name:'Daniele'})\n" + "Create (p:Country {name:'USA'})\n" + "Create (d)-[:TRAVELS_TO {year:1995, reason:\"work\"}]->(p)\n"
      + "Create (d)-[:GOES_TO {year:2010, reason:\"fun\"}]->(p)\n" + "Create (d)-[:FLIGHTS_TO {company:\"Air America\"}]->(p) RETURN id(p) as id ").<Long>columnAs("id").next();
  testCall(db, "MATCH (d:Person {name:'Daniele'})\n" + "MATCH (p:Country {name:'USA'})\n" + "MATCH (d)-[r:TRAVELS_TO]->(p)\n" + "MATCH (d)-[h:GOES_TO]->(p)\n"
          + "MATCH (d)-[l:FLIGHTS_TO]->(p)\n" + "call apoc.refactor.mergeRelationships([r,h,l],{properties:\"combine\"}) yield rel\n MATCH (d)-[u]->(p) " + "return p,d,u,u.to as to, count(u) as totRel",
      (r) -> {
        Node node = (Node) r.get("p");
        Long totRel = (Long) r.get("totRel");
        Relationship rel = (Relationship) r.get("u");
        assertEquals(id, node.getId());
        assertEquals(true, node.hasLabel(Label.label("Country")));
        assertEquals("USA", node.getProperty("name"));
        assertEquals(new Long(1),totRel);
        assertEquals(true, rel.isType(RelationshipType.withName("TRAVELS_TO")));
        assertEquals(Arrays.asList("work", "fun").toArray(), new ArrayBackedList(rel.getProperty("reason")).toArray());
        assertEquals(Arrays.asList(1995L, 2010L).toArray(), new ArrayBackedList(rel.getProperty("year")).toArray());
      });
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test
public void testMergeRelsEagerAggregationCombineArrayDifferentValuesTypeProperties() throws Exception {
  long id = db.execute("Create (d:Person {name:'Daniele'})\n" + "Create (p:Country {name:'USA'})\n" + "Create (d)-[:TRAVELS_TO {year:1995, reason:\"work\"}]->(p)\n"
      + "Create (d)-[:GOES_TO {year:[\"2010\",\"2015\"], reason:\"fun\"}]->(p)\n" + "Create (d)-[:FLIGHTS_TO {company:\"Air America\"}]->(p) RETURN id(p) as id ").<Long>columnAs("id").next();
  testCall(db, "MATCH (d:Person {name:'Daniele'})\n" + "MATCH (p:Country {name:'USA'})\n" + "MATCH (d)-[r:TRAVELS_TO]->(p)\n" + "MATCH (d)-[h:GOES_TO]->(p)\n"
          + "MATCH (d)-[l:FLIGHTS_TO]->(p)\n" + "call apoc.refactor.mergeRelationships([r,h,l],{properties:\"combine\"}) yield rel\n MATCH (d)-[u]->(p) " + "return p,d,u,u.to as to, count(u) as totRel",
      (r) -> {
        Node node = (Node) r.get("p");
        Long totRel = (Long) r.get("totRel");
        Relationship rel = (Relationship) r.get("u");
        assertEquals(id, node.getId());
        assertEquals(true, node.hasLabel(Label.label("Country")));
        assertEquals("USA", node.getProperty("name"));
        assertEquals(new Long(1),totRel);
        assertEquals(true, rel.isType(RelationshipType.withName("TRAVELS_TO")));
        assertEquals(Arrays.asList("work", "fun").toArray(), new ArrayBackedList(rel.getProperty("reason")).toArray());
        assertEquals(Arrays.asList("1995", "2010", "2015").toArray(), new ArrayBackedList(rel.getProperty("year")).toArray());
      });
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

assertEquals(4,resultingNode.getDegree(Direction.OUTGOING));
assertEquals(1,c.getDegree(Direction.INCOMING));
assertEquals(true, r.isType(RelationshipType.withName("HAS_REL")));
assertEquals("r1", r.getProperty("p"));
assertEquals(true, r1.isType(RelationshipType.withName("HAS_REL")));
assertEquals("r1", r1.getProperty("p"));

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test
public void testMergeRelsCombineEagerAggregation() throws Exception {
  long id = db.execute("Create (d:Person {name:'Daniele'})\n" + "Create (p:Country {name:'USA'})\n" + "Create (d)-[:TRAVELS_TO {year:1995, reason:\"work\"}]->(p)\n"
      + "Create (d)-[:GOES_TO {year:2010, reason:\"fun\"}]->(p)\n" + "Create (d)-[:FLIGHTS_TO {company:\"Air America\"}]->(p) RETURN id(p) as id ").<Long>columnAs("id").next();
  testCall(db, "MATCH (d:Person {name:'Daniele'})\n" + "MATCH (p:Country {name:'USA'})\n" + "MATCH (d)-[r:TRAVELS_TO]->(p)\n" + "MATCH (d)-[h:GOES_TO]->(p)\n"
          + "MATCH (d)-[l:FLIGHTS_TO]->(p)\n" + "call apoc.refactor.mergeRelationships([r,h,l],{properties:\"discard\"}) yield rel\n MATCH (d)-[u]->(p) " + "return p,d,u,u.to as to, count(u) as totRel",
      (r) -> {
        Node node = (Node) r.get("p");
        Long totRel = (Long) r.get("totRel");
        Relationship rel = (Relationship) r.get("u");
        assertEquals(id, node.getId());
        assertEquals(true, node.hasLabel(Label.label("Country")));
        assertEquals("USA", node.getProperty("name"));
        assertEquals(new Long(1),totRel);
        assertEquals(true, rel.isType(RelationshipType.withName("TRAVELS_TO")));
        assertEquals("work", rel.getProperty("reason"));
        assertEquals(1995L, rel.getProperty("year"));
      });
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test
public void testMergeRelsOverwriteEagerAggregation() throws Exception {
  long id = db.execute("Create (d:Person {name:'Daniele'})\n" + "Create (p:Country {name:'USA'})\n" + "Create (d)-[:TRAVELS_TO {year:1995, reason:\"work\"}]->(p)\n"
      + "Create (d)-[:GOES_TO {year:2010}]->(p)\n" + "Create (d)-[:FLIGHTS_TO {company:\"Air America\"}]->(p) RETURN id(p) as id ").<Long>columnAs("id").next();
  testCall(db, "MATCH (d:Person {name:'Daniele'})\n" + "MATCH (p:Country {name:'USA'})\n" + "MATCH (d)-[r:TRAVELS_TO]->(p)\n" + "MATCH (d)-[h:GOES_TO]->(p)\n"
          + "MATCH (d)-[l:FLIGHTS_TO]->(p)\n" + "call apoc.refactor.mergeRelationships([r,h,l],{properties:\"overwrite\"}) yield rel\n MATCH (d)-[u]->(p) " + "return p,d,u,u.to as to, count(u) as totRel",
      (r) -> {
        Node node = (Node) r.get("p");
        Long totRel = (Long) r.get("totRel");
        Relationship rel = (Relationship) r.get("u");
        assertEquals(id, node.getId());
        assertEquals(true, node.hasLabel(Label.label("Country")));
        assertEquals("USA", node.getProperty("name"));
        assertEquals(new Long(1),totRel);
        assertEquals(true, rel.isType(RelationshipType.withName("TRAVELS_TO")));
        assertEquals("work", rel.getProperty("reason"));
        assertEquals(2010L, rel.getProperty("year"));
      });
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test
public void testCollapseNode() throws Exception {
  Long id = db.execute("CREATE (f:Foo)-[:FOO {a:1}]->(b:Bar {c:3})-[:BAR {b:2}]->(f) RETURN id(b) as id").<Long>columnAs("id").next();
  testCall(db, "CALL apoc.refactor.collapseNode({ids},'FOOBAR')", map("ids", singletonList(id)),
      (r) -> {
        assertEquals(id, r.get("input"));
        Relationship rel = (Relationship) r.get("output");
        assertEquals(true, rel.isType(RelationshipType.withName("FOOBAR")));
        assertEquals(1L, rel.getProperty("a"));
        assertEquals(2L, rel.getProperty("b"));
        assertEquals(3L, rel.getProperty("c"));
        assertNotNull(rel.getEndNode().hasLabel(Label.label("Foo")));
        assertNotNull(rel.getStartNode().hasLabel(Label.label("Foo")));
      });
}

相关文章