From e5bcf8ba46b6851b677078358b7ffd26072c2523 Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Fri, 11 Dec 2020 02:17:06 +0100 Subject: add generic doi version case --- fuzzycat/utils.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'fuzzycat/utils.py') diff --git a/fuzzycat/utils.py b/fuzzycat/utils.py index ef3b418..2dc2adb 100644 --- a/fuzzycat/utils.py +++ b/fuzzycat/utils.py @@ -3,12 +3,26 @@ import itertools import re import string +from glom import glom, PathAccessError + printable_no_punct = string.digits + string.ascii_letters + string.whitespace # More correct: https://www.johndcook.com/blog/2016/02/04/regular-expression-to-match-a-chemical-element/ CHEM_FORMULA = re.compile(r"([A-Z]{1,2}[0-9]{1,2})+") +def dict_key_exists(doc, path): + """ + Return true, if a value at a given path exists. XXX: probably in glom, too. + """ + try: + _ = glom(doc, path) + except PathAccessError: + return False + else: + return True + + def has_doi_prefix(v, prefix="10.1234"): """ Returns False, if we cannot parse v or prefix does not match. -- cgit v1.2.3