def get_signatures(signature_block=None, only_curated=False): """Get all signatures from ES. Args: signature_block (str, optional): string representation of selected signature block. If empty or None returns all signature blocks. Defaults to None. only_curated (bool, optional): If set to true return only curated signatures, otherwise return all. Defaults to False. Returns: list: dicts of signatures. Example: >>> get_signatures("ABDa", True) [Signature(...), Signature(...), Signature(...)] """ query = get_literature_records_query(signature_block, only_curated) results = [] for record in query.scan(): record = record.to_dict() for author in record.get("authors"): if only_curated and not author.get("curated_relation"): continue if signature_block and author.get( "signature_block") != signature_block: continue signature = Signature.build(author, record) # Skip signatures marked as curated which do not have author_id if only_curated and not signature.get("author_id"): continue results.append(signature) PublicationCache.clear() return results
def test_build_signature_with_non_curated_author(non_curated_author, record): result = Signature.build(non_curated_author, record) expected_result = Signature( author_affiliation="Rutgers U., Piscataway", author_id=None, author_name="Doe, John", publication=Publication( abstract="2 curated authors with recid", authors=["Doe, John"], collaborations=["ATLAS"], keywords=["effective action", "approximation: semiclassical"], publication_id=374836, title="Title", topics=["Theory-HEP"], ), signature_block="JOhn", signature_uuid="94fc2b0a-dc17-42c2-bae3-ca0024079e52", is_curated_author_id=False, ) assert result == expected_result
def non_curated_signature(): signature = Signature( author_affiliation="Texas U.", author_id=None, author_name="Weinberg, Steven", publication=Publication( abstract="Author not curated", authors=["Weinberg, Steven"], collaborations=[], keywords=["book"], publication_id=406190, title="The Quantum theory of fields. Vol. 1: Foundations", topics=["Theory-HEP", "General Physics"], ), signature_block="WANBARGs", signature_uuid="5e550ded-e955-4a22-b906-8af5aaa9f1e2", is_curated_author_id=False, ) return signature
def curated_signature(): signature = Signature( author_affiliation="Rutgers U., Piscataway", author_id=989440, author_name="Seiberg, Nana", publication=Publication( abstract="abstract", authors=["Seiberg, N.", "Jimmy"], collaborations=["ATLAS", "CMS"], keywords=["effective action", "approximation: semiclassical"], publication_id=374836, title="Title", topics=["Theory-HEP", "Physics"], ), signature_block="SABARGn", signature_uuid="94fc2b0a-dc17-42c2-bae3-ca0024079e52", is_curated_author_id=True ) return signature
def test_build_signature_uses_publication_cache(curated_author, record): Signature.build(curated_author, record) assert record["control_number"] in PublicationCache.cache
def test_build_many_signatures_with_one_publication(non_curated_author, curated_author, record): signature1 = Signature.build(non_curated_author, record=record) signature2 = Signature.build(curated_author, record=record) assert signature1.publication is signature2.publication