summaryrefslogtreecommitdiffstats
path: root/python/fatcat_tools
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-01-31 16:51:00 -0800
committerBryan Newbold <bnewbold@robocracy.org>2019-02-01 11:46:24 -0800
commitb90828d7d16b38052bd45f6df1f3d093799e7cee (patch)
tree0b58fb46c212eb474f57eca05542a8e6243ad978 /python/fatcat_tools
parent0103d56d0eee61b7280c2a98417aef6f4350c273 (diff)
downloadfatcat-b90828d7d16b38052bd45f6df1f3d093799e7cee.tar.gz
fatcat-b90828d7d16b38052bd45f6df1f3d093799e7cee.zip
flag to control boolean cast in elastic transforms
So these functions can be re-used in simplified webface rendering.
Diffstat (limited to 'python/fatcat_tools')
-rw-r--r--python/fatcat_tools/transforms.py42
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