-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
279 additions
and
53 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
44 changes: 44 additions & 0 deletions
44
.../pipelines/clustering-gbif/src/main/java/org/gbif/pipelines/clustering/HashUtilities.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,44 @@ | ||
package org.gbif.pipelines.clustering; | ||
|
||
import static org.gbif.pipelines.core.parsers.clustering.OccurrenceRelationships.concatIfEligible; | ||
import static org.gbif.pipelines.core.parsers.clustering.OccurrenceRelationships.hashOrNull; | ||
import static org.gbif.pipelines.core.parsers.clustering.OccurrenceRelationships.isEligibleCode; | ||
import static org.gbif.pipelines.core.parsers.clustering.OccurrenceRelationships.isNumeric; | ||
|
||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import org.gbif.pipelines.core.parsers.clustering.OccurrenceFeatures; | ||
import org.gbif.pipelines.core.parsers.clustering.OccurrenceRelationships; | ||
|
||
/** Utility functions for hashing records to pregroup. */ | ||
public class HashUtilities { | ||
|
||
/** | ||
* Hashes the occurrenceID, catalogCode and otherCatalogNumber into a Set of codes. The | ||
* catalogNumber is constructed as it's code and also prefixed in the commonly used format of | ||
* IC:CC:CN and IC:CN. No code in the resulting set will be numeric as the cardinality of e.g. | ||
* catalogNumber=100 is too high to compute, and this is intended to be used to detect explicit | ||
* relationships with otherCatalogNumber. | ||
* | ||
* @return a set of hashes suitable for grouping specimen related records without other filters. | ||
*/ | ||
public static Set<String> hashCatalogNumbers(OccurrenceFeatures o) { | ||
Stream<String> cats = | ||
Stream.of( | ||
hashOrNull(o.getCatalogNumber(), false), | ||
hashOrNull(o.getOccurrenceID(), false), | ||
concatIfEligible( | ||
":", o.getInstitutionCode(), o.getCollectionCode(), o.getCatalogNumber()), | ||
concatIfEligible(":", o.getInstitutionCode(), o.getCatalogNumber())); | ||
|
||
if (o.getOtherCatalogNumbers() != null) { | ||
cats = | ||
Stream.concat(cats, o.getOtherCatalogNumbers().stream().map(c -> hashOrNull(c, false))); | ||
} | ||
|
||
return cats.map(OccurrenceRelationships::normalizeID) | ||
.filter(c -> isEligibleCode(c) && !isNumeric(c)) | ||
.collect(Collectors.toSet()); | ||
} | ||
} |
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
Oops, something went wrong.