diff options
-rw-r--r-- | python/fatcat_tools/transforms.py | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/python/fatcat_tools/transforms.py b/python/fatcat_tools/transforms.py index b9b22e0b..e95d6d30 100644 --- a/python/fatcat_tools/transforms.py +++ b/python/fatcat_tools/transforms.py @@ -44,7 +44,7 @@ def test_check_kbart(): assert check_kbart(1950, dict(year_spans=[[1900, 1920], [1990, 2000]])) == False assert check_kbart(1950, dict(year_spans=[[1900, 1920], [1930, 2000]])) == True -def release_to_elasticsearch(entity): +def release_to_elasticsearch(entity, force_bool=True): """ Converts from an entity model/schema to elasticsearch oriented schema. @@ -205,17 +205,27 @@ def release_to_elasticsearch(entity): if is_longtail_oa: is_oa = True - t['is_oa'] = bool(is_oa) - t['is_longtail_oa'] = bool(is_longtail_oa) - t['in_kbart'] = bool(in_kbart) - t['in_jstor'] = bool(in_jstor) - t['in_web'] = bool(in_web) - t['in_dweb'] = bool(in_dweb) + + if force_bool: + t['is_oa'] = bool(is_oa) + t['is_longtail_oa'] = bool(is_longtail_oa) + t['in_kbart'] = bool(in_kbart) + t['in_jstor'] = bool(in_jstor) + t['in_web'] = bool(in_web) + t['in_dweb'] = bool(in_dweb) + else: + t['is_oa'] = is_oa + t['is_longtail_oa'] = is_longtail_oa + t['in_kbart'] = in_kbart + t['in_jstor'] = in_jstor + t['in_web'] = in_web + t['in_dweb'] = in_dweb + t['in_ia'] = bool(in_ia) t['is_preserved'] = bool(is_preserved or in_ia or in_kbart or in_jstor) return t -def container_to_elasticsearch(entity): +def container_to_elasticsearch(entity, force_bool=True): """ Converts from an entity model/schema to elasticsearch oriented schema. @@ -290,13 +300,19 @@ def container_to_elasticsearch(entity): t['in_doaj'] = bool(in_doaj) t['in_road'] = bool(in_road) - t['in_doi'] = bool(in_doi) t['in_sherpa_romeo'] = bool(in_sherpa_romeo) - t['is_oa'] = bool(in_doaj or in_road or is_longtail_oa or is_oa) - t['is_longtail_oa'] = bool(is_longtail_oa) t['any_kbart'] = bool(any_kbart) - t['any_jstor'] = bool(any_jstor) - t['any_ia_sim'] = bool(any_ia_sim) + t['is_longtail_oa'] = bool(is_longtail_oa) + if force_bool: + t['in_doi'] = bool(in_doi) + t['is_oa'] = bool(in_doaj or in_road or is_longtail_oa or is_oa) + t['any_jstor'] = bool(any_jstor) + t['any_ia_sim'] = bool(any_ia_sim) + else: + t['in_doi'] = in_doi + t['is_oa'] = in_doaj or in_road or is_longtail_oa or is_oa + t['any_jstor'] = any_jstor + t['any_ia_sim'] = any_ia_sim return t |