keep_triples_by_hash
- keep_triples_by_hash(triples: Iterable[TripleType], converter: Converter, triple_hashes: str | Iterable[str], *, progress: bool = False) Iterable[TripleType][source]
Keep triples whose triple hash (under the given converter) is in the given collection.
- Parameters:
triples – An iterable of triples
converter – A converter
triple_hashes – A hash or hashs to check triples for
progress – Should a progress bar be shown?
- Returns:
A sub-iterable of triples whose triple hash under the given constructor appears in the given collection
>>> from curies import Triple, Converter >>> from curies.vocabulary import exact_match, subclass_of >>> converter = Converter.from_prefix_map( ... { ... "DOID": "http://purl.obolibrary.org/obo/DOID_", ... "skos": "http://www.w3.org/2004/02/skos/core#", ... "mesh": "http://id.nlm.nih.gov/mesh/", ... "umls": "https://uts.nlm.nih.gov/uts/umls/concept/", ... } ... ) >>> c1, c2, c3 = "DOID:0050577", "mesh:C562966", "DOID:225" >>> m1 = Triple.from_curies(c1, exact_match.curie, c2) >>> m2 = Triple.from_curies(c2, exact_match.curie, c3) >>> m3 = Triple.from_curies(c1, subclass_of.curie, c3) >>> m1_hash = "081f943d3791dae3a85f8eb9190fee3fbdc47ba269a374e4a0a28a2b0b982625" >>> assert list(keep_triples_by_hash([m1, m2, m3], converter, m1_hash)) == [m1]