-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support divorces, add marriage information
The existing `IS_MARRIED_TO` has been changed to `IS_SPOUSE_OF`. `IS_SPOUSE_OF` is inferred from family's `HUSB` / `WIFE` tags. `IS_MARRIED_TO` relationships are now only created if there are marriage family event information (`MARR` Gedcom tag). `DIVORCED` relationships are created from family divorce event information (`DIV` Gedcom tag).
- Loading branch information
Showing
9 changed files
with
256 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/main/java/com/neo4j/data/importer/extractors/EventFacts.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.neo4j.data.importer.extractors; | ||
|
||
import com.joestelmach.natty.Parser; | ||
import java.time.LocalDate; | ||
import java.time.ZoneId; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import org.folg.gedcom.model.EventFact; | ||
|
||
class EventFacts { | ||
|
||
/** | ||
* extractFlat extracts all events' place and location into a single, "flat" map | ||
*/ | ||
public static Map<String, Object> extractFlat(List<EventFact> facts, Parser dateParser) { | ||
var attributes = new HashMap<String, Object>(); | ||
facts.forEach(fact -> { | ||
attributes.putAll(extractFact( | ||
fact, | ||
dateParser, | ||
(eventFact) -> | ||
String.format("%s_", eventFact.getDisplayType().toLowerCase(Locale.ROOT)))); | ||
}); | ||
return attributes; | ||
} | ||
|
||
/** | ||
* extract all events' place and location, categorized by event tag | ||
*/ | ||
public static Map<String, List<Map<String, Object>>> extract(List<EventFact> facts, Parser dateParser) { | ||
var attributes = new HashMap<String, List<Map<String, Object>>>(); | ||
for (EventFact fact : facts) { | ||
var eventsPerTag = | ||
attributes.computeIfAbsent(fact.getTag().toUpperCase(Locale.ROOT), (key) -> new ArrayList<>()); | ||
eventsPerTag.add(extractFact(fact, dateParser)); | ||
} | ||
return attributes; | ||
} | ||
|
||
private static Map<String, Object> extractFact(EventFact eventFact, Parser dateParser) { | ||
return extractFact(eventFact, dateParser, (fact) -> ""); | ||
} | ||
|
||
private static Map<String, Object> extractFact( | ||
EventFact fact, Parser dateParser, Function<EventFact, String> keyQualifierFn) { | ||
var attributes = new HashMap<String, Object>(2); | ||
String date = fact.getDate(); | ||
String keyQualifier = keyQualifierFn.apply(fact); | ||
String type = fact.getType(); | ||
if (type != null) { | ||
attributes.put(String.format("%stype", keyQualifier), type); | ||
} | ||
if (date != null) { | ||
attributes.put(String.format("raw_%sdate", keyQualifier), date); | ||
var localDate = parseLocalDate(dateParser, date); | ||
if (localDate != null) { | ||
attributes.put(String.format("%sdate", keyQualifier), localDate); | ||
} | ||
} | ||
String place = fact.getPlace(); | ||
if (place != null) { | ||
attributes.put(String.format("%slocation", keyQualifier), place); | ||
} | ||
return attributes; | ||
} | ||
|
||
private static LocalDate parseLocalDate(Parser dateParser, String date) { | ||
var parse = dateParser.parse(date); | ||
if (parse.size() != 1) { | ||
return null; | ||
} | ||
|
||
var dateGroup = parse.get(0); | ||
if (dateGroup.getDates().size() != 1 || dateGroup.isDateInferred()) { | ||
// Dates should be parsed explicitly from input. | ||
// Inferred dates are likely to be set using current time and therefore incorrect. | ||
return null; | ||
} | ||
|
||
var parsedDate = dateGroup.getDates().get(0); | ||
|
||
return LocalDate.ofInstant(parsedDate.toInstant(), ZoneId.systemDefault()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 8 additions & 1 deletion
9
src/main/java/com/neo4j/data/importer/extractors/FamilyExtractors.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
package com.neo4j.data.importer.extractors; | ||
|
||
import com.joestelmach.natty.Parser; | ||
import java.util.function.Supplier; | ||
import org.folg.gedcom.model.Family; | ||
|
||
public class FamilyExtractors implements Supplier<AttributeExtractor<Family>> { | ||
|
||
private final Parser dateParser; | ||
|
||
public FamilyExtractors(Parser dateParser) { | ||
this.dateParser = dateParser; | ||
} | ||
|
||
@Override | ||
public AttributeExtractor<Family> get() { | ||
return new DefaultFamilyExtractor(); | ||
return new DefaultFamilyExtractor(dateParser); | ||
} | ||
} |
7 changes: 5 additions & 2 deletions
7
src/main/java/com/neo4j/data/importer/extractors/PersonExtractors.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.