Skip to content

Commit

Permalink
feat: make relationship names time-neutral
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Biville <[email protected]>
  • Loading branch information
dhrudevalia authored and fbiville committed Nov 21, 2024
1 parent 9a4c911 commit eb8f7b8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
8 changes: 4 additions & 4 deletions src/main/java/com/neo4j/data/importer/GedcomImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public Stream<Statistics> loadGedcom(@Name("file") String file) throws IOExcepti
UNWIND $spouseIdPairs AS spouseInfo
MATCH (spouse1:Person {id: spouseInfo.id1}),
(spouse2:Person {id: spouseInfo.id2})
CREATE (spouse1)-[r:IS_SPOUSE_OF]->(spouse2)
CREATE (spouse1)-[r:SPOUSE_OF]->(spouse2)
FOREACH (marriageInfo IN spouseInfo.events["MARR"] |
CREATE (spouse1)-[r:IS_MARRIED_TO]->(spouse2)
CREATE (spouse1)-[r:MARRIED_TO]->(spouse2)
SET r = marriageInfo
)
FOREACH (divorceInfo IN spouseInfo.events["DIV"] |
Expand All @@ -69,8 +69,8 @@ public Stream<Statistics> loadGedcom(@Name("file") String file) throws IOExcepti
WITH spouse1, spouse2
UNWIND $childIds AS childId
MATCH (child:Person {id: childId})
CREATE (child)-[:IS_CHILD_OF]->(spouse1)
CREATE (child)-[:IS_CHILD_OF]->(spouse2)
CREATE (child)-[:CHILD_OF]->(spouse1)
CREATE (child)-[:CHILD_OF]->(spouse2)
""",
attributes)
.getQueryStatistics();
Expand Down
51 changes: 25 additions & 26 deletions src/test/java/com/neo4j/data/importer/GedcomImporterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ void loads_relationships() {

assertThat(relationships)
.hasSize(17)
.filteredOn(r -> r.type().equals("IS_SPOUSE_OF"))
.filteredOn(r -> r.type().equals("SPOUSE_OF"))
.hasSize(3);

assertThat(relationships)
.filteredOn(r -> r.type().equals("IS_CHILD_OF"))
.filteredOn(r -> r.type().equals("CHILD_OF"))
.hasSize(14);

assertThat(nodesCreated).isEqualTo(11);
Expand All @@ -119,23 +119,23 @@ void loads_relationships() {
var patty = new Person(List.of("Patty"), List.of("Bouvier"), "F");
assertThat(relationships)
.containsExactlyInAnyOrder(
familyRel(homer, "IS_SPOUSE_OF", marge),
familyRel(abraham, "IS_SPOUSE_OF", mona),
familyRel(clancy, "IS_SPOUSE_OF", jacqueline),
familyRel(homer, "IS_CHILD_OF", abraham),
familyRel(homer, "IS_CHILD_OF", mona),
familyRel(marge, "IS_CHILD_OF", clancy),
familyRel(marge, "IS_CHILD_OF", jacqueline),
familyRel(lisa, "IS_CHILD_OF", marge),
familyRel(lisa, "IS_CHILD_OF", homer),
familyRel(bart, "IS_CHILD_OF", marge),
familyRel(bart, "IS_CHILD_OF", homer),
familyRel(maggie, "IS_CHILD_OF", marge),
familyRel(maggie, "IS_CHILD_OF", homer),
familyRel(selma, "IS_CHILD_OF", jacqueline),
familyRel(selma, "IS_CHILD_OF", clancy),
familyRel(patty, "IS_CHILD_OF", jacqueline),
familyRel(patty, "IS_CHILD_OF", clancy));
familyRel(homer, "SPOUSE_OF", marge),
familyRel(abraham, "SPOUSE_OF", mona),
familyRel(clancy, "SPOUSE_OF", jacqueline),
familyRel(homer, "CHILD_OF", abraham),
familyRel(homer, "CHILD_OF", mona),
familyRel(marge, "CHILD_OF", clancy),
familyRel(marge, "CHILD_OF", jacqueline),
familyRel(lisa, "CHILD_OF", marge),
familyRel(lisa, "CHILD_OF", homer),
familyRel(bart, "CHILD_OF", marge),
familyRel(bart, "CHILD_OF", homer),
familyRel(maggie, "CHILD_OF", marge),
familyRel(maggie, "CHILD_OF", homer),
familyRel(selma, "CHILD_OF", jacqueline),
familyRel(selma, "CHILD_OF", clancy),
familyRel(patty, "CHILD_OF", jacqueline),
familyRel(patty, "CHILD_OF", clancy));
}
}

Expand Down Expand Up @@ -164,7 +164,7 @@ void parses_same_sex_marriages() {
var relationships = driver
.executableQuery(
"""
MATCH (i: Person)-[r:IS_SPOUSE_OF]->(j: Person)
MATCH (i: Person)-[r:SPOUSE_OF]->(j: Person)
WHERE i.gender = j.gender
RETURN i, r, j
""")
Expand All @@ -175,7 +175,7 @@ void parses_same_sex_marriages() {

var john = new Person(List.of("John"), List.of("Smith"), "M");
var steven = new Person(List.of("Steven"), List.of("Stevens"), "M");
assertThat(relationships).containsExactlyInAnyOrder(familyRel(john, "IS_SPOUSE_OF", steven));
assertThat(relationships).containsExactlyInAnyOrder(familyRel(john, "SPOUSE_OF", steven));
}
}

Expand All @@ -187,8 +187,8 @@ void processes_remarriages() {
var relationships = driver
.executableQuery(
"""
MATCH (i: Person)-[r:IS_SPOUSE_OF]-(j: Person)
MATCH (i)-[:IS_SPOUSE_OF]-(k: Person)
MATCH (i: Person)-[r:SPOUSE_OF]-(j: Person)
MATCH (i)-[:SPOUSE_OF]-(k: Person)
WHERE id(j) <> id(k)
RETURN i, r, j""")
.execute(Collectors.toList())
Expand All @@ -200,8 +200,7 @@ WHERE id(j) <> id(k)
var peter = new Person(List.of("Peter"), List.of("Sweet"), "M");
var juan = new Person(List.of("Juan"), List.of("Donalds"), "M");

assertThat(relationships)
.contains(familyRel(mary, "IS_SPOUSE_OF", peter), familyRel(mary, "IS_SPOUSE_OF", juan));
assertThat(relationships).contains(familyRel(mary, "SPOUSE_OF", peter), familyRel(mary, "SPOUSE_OF", juan));
;
}
}
Expand Down Expand Up @@ -239,7 +238,7 @@ void parses_detailed_marriage_information() {
"""
MATCH (john:Person {first_names: ["John"], last_names: ["DOE"]}),
(jane:Person {first_names: ["Jane"], last_names: ["DOE"]}),
(john)-[r:IS_MARRIED_TO]->(jane)
(john)-[r:MARRIED_TO]->(jane)
RETURN r
""")
.execute(Collectors.toList())
Expand Down

0 comments on commit eb8f7b8

Please sign in to comment.