closurizer 0.1.7__py3-none-any.whl → 0.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
closurizer/closurizer.py CHANGED
@@ -15,11 +15,24 @@ def _cut_left_join(ltable, rtable, field, attribute):
15
15
  lkey=field,
16
16
  rkey="id")
17
17
 
18
+ def _length(value):
19
+ if value is None:
20
+ return 0
21
+ else:
22
+ return len(value.split("|"))
23
+
24
+ def _length_of_field_values(rec, fields):
25
+ value = 0
26
+ for field in fields:
27
+ if (field_value := rec[field]) is not None:
28
+ value += _length(field_value)
29
+ return value
18
30
 
19
31
  def add_closure(kg_archive: str,
20
32
  closure_file: str,
21
33
  output_file: str,
22
- fields: List[str] = None
34
+ fields: List[str] = ['subject', 'object'],
35
+ evidence_fields: List[str] = ['has_evidence', 'publications', 'primary_knowledge_source']
23
36
  ):
24
37
  print("Generating closure KG...")
25
38
  print(f"kg_archive: {kg_archive}")
@@ -28,6 +41,9 @@ def add_closure(kg_archive: str,
28
41
  if fields is None or len(fields) == 0:
29
42
  fields = ['subject', 'object']
30
43
 
44
+ if evidence_fields is None or len(evidence_fields) == 0:
45
+ evidence_fields = ['has_evidence', 'publications', 'primary_knowledge_source', 'provided_by']
46
+
31
47
  print(f"fields: {','.join(fields)}")
32
48
  print(f"output_file: {output_file}")
33
49
 
@@ -79,6 +95,11 @@ def add_closure(kg_archive: str,
79
95
  edges = etl.leftjoin(edges, (etl.cut(nodes, ["id", "name"]).rename("name", f"{field}_label")), lkey=field,
80
96
  rkey="id")
81
97
 
98
+ print("Adding evidence counts...")
99
+
100
+ edges = etl.addfield(edges, 'evidence_count',
101
+ lambda rec: _length_of_field_values(rec, evidence_fields))
102
+
82
103
  print("Denormalizing...")
83
104
  etl.totsv(edges, f"{output_file}")
84
105
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: closurizer
3
- Version: 0.1.7
3
+ Version: 0.2.1
4
4
  Summary: Add closure expansion fields to kgx files following the Golr pattern
5
5
  Author: Kevin Schaper
6
6
  Author-email: kevin@tislab.org
@@ -0,0 +1,6 @@
1
+ closurizer/cli.py,sha256=2SsVXscVJFgwelfZvHKQQQtTU-9pGaA2RJnK2BaNVc8,641
2
+ closurizer/closurizer.py,sha256=UAZJ2XCwSqXhp5AgBfUu6s_H72CtZK2H3Jc-746cVrw,4352
3
+ closurizer-0.2.1.dist-info/METADATA,sha256=sRqV2_sM2-iB_hzHafpjnm8X7IXuN2oYOLgjDR1AWfg,575
4
+ closurizer-0.2.1.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
5
+ closurizer-0.2.1.dist-info/entry_points.txt,sha256=MnAVu1lgP6DqDb3BZGNzVs2AnDMsp4sThi3ccWbONFo,50
6
+ closurizer-0.2.1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.3.2
2
+ Generator: poetry-core 1.6.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,6 +0,0 @@
1
- closurizer/cli.py,sha256=2SsVXscVJFgwelfZvHKQQQtTU-9pGaA2RJnK2BaNVc8,641
2
- closurizer/closurizer.py,sha256=rmrOJFh83eGR-hfVMytDNc6zd3np30qSIobmHOZYsEk,3590
3
- closurizer-0.1.7.dist-info/entry_points.txt,sha256=MnAVu1lgP6DqDb3BZGNzVs2AnDMsp4sThi3ccWbONFo,50
4
- closurizer-0.1.7.dist-info/WHEEL,sha256=vxFmldFsRN_Hx10GDvsdv1wroKq8r5Lzvjp6GZ4OO8c,88
5
- closurizer-0.1.7.dist-info/METADATA,sha256=9yYJxRgs8D9NVUQtgW94NEIiaMFj1qiE4ci0T3e4v80,575
6
- closurizer-0.1.7.dist-info/RECORD,,