closurizer 0.6.0__py3-none-any.whl → 0.7.0__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/cli.py CHANGED
@@ -11,6 +11,7 @@ from closurizer.closurizer import add_closure
11
11
  @click.option('--additional-node-constraints', required=False,
12
12
  help='additional where clause constraints to apply to the generation of the denormalized nodes output')
13
13
  @click.option('--edge-fields', multiple=True, help='edge fields to expand with closure IDs, labels, etc')
14
+ @click.option('--edge-fields-to-label', multiple=True, help='edge fields to with category, label, etc but not full closure exansion')
14
15
  @click.option('--node-fields', multiple=True, help='node fields to expand with closure IDs, labels, etc')
15
16
  @click.option('--grouping-fields', multiple=True, help='fields to populate a single value grouping_key field')
16
17
  @click.option('--dry-run', is_flag=True, help='A dry run will not write the output file, but will print the SQL query')
@@ -21,11 +22,13 @@ def main(kg: str,
21
22
  additional_node_constraints: str = None,
22
23
  dry_run: bool = False,
23
24
  edge_fields: List[str] = None,
25
+ edge_fields_to_label: List[str] = None,
24
26
  node_fields: List[str] = None,
25
27
  grouping_fields: List[str] = None):
26
28
  add_closure(kg_archive=kg,
27
29
  closure_file=closure,
28
30
  edge_fields=edge_fields,
31
+ edge_fields_to_label=edge_fields_to_label,
29
32
  node_fields=node_fields,
30
33
  edges_output_file=edges_output,
31
34
  nodes_output_file=nodes_output,
closurizer/closurizer.py CHANGED
@@ -1,10 +1,10 @@
1
- from typing import List
1
+ from typing import List, Optional
2
2
 
3
3
  import os
4
4
  import tarfile
5
5
  import duckdb
6
6
 
7
- def edge_columns(field):
7
+ def edge_columns(field: str, include_closure_fields: bool =True):
8
8
  column_text = f"""
9
9
  {field}.name as {field}_label,
10
10
  {field}.category as {field}_category,
@@ -19,14 +19,14 @@ def edge_columns(field):
19
19
  """
20
20
  return column_text
21
21
 
22
- def edge_joins(field):
22
+ def edge_joins(field: str, include_closure_joins: bool =True):
23
23
  return f"""
24
24
  left outer join nodes as {field} on edges.{field} = {field}.id
25
25
  left outer join closure_id as {field}_closure on {field}.id = {field}_closure.id
26
26
  left outer join closure_label as {field}_closure_label on {field}.id = {field}_closure_label.id
27
27
  """
28
28
 
29
- def evidence_sum(evidence_fields):
29
+ def evidence_sum(evidence_fields: List[str]):
30
30
  """ Sum together the length of each field after splitting on | """
31
31
  evidence_count_sum = "+".join([f"ifnull(len(split({field}, '|')),0)" for field in evidence_fields])
32
32
  return f"{evidence_count_sum} as evidence_count,"
@@ -73,12 +73,13 @@ def add_closure(kg_archive: str,
73
73
  closure_file: str,
74
74
  nodes_output_file: str,
75
75
  edges_output_file: str,
76
- node_fields: List[str] = None,
76
+ node_fields: List[str] = [],
77
77
  edge_fields: List[str] = ['subject', 'object'],
78
- additional_node_constraints: str = None,
78
+ edge_fields_to_label: List[str] = [],
79
+ additional_node_constraints: Optional[str] = None,
79
80
  dry_run: bool = False,
80
- evidence_fields: List[str] = None,
81
- grouping_fields: List[str] = None
81
+ evidence_fields: List[str] = ['has_evidence', 'publications'],
82
+ grouping_fields: List[str] = ['subject', 'negated', 'predicate', 'object']
82
83
  ):
83
84
  print("Generating closure KG...")
84
85
  print(f"kg_archive: {kg_archive}")
@@ -86,16 +87,6 @@ def add_closure(kg_archive: str,
86
87
 
87
88
  db = duckdb.connect(database='monarch-kg.duckdb')
88
89
 
89
- if edge_fields is None or len(edge_fields) == 0:
90
- edge_fields = ['subject', 'object']
91
-
92
- if evidence_fields is None or len(evidence_fields) == 0:
93
- evidence_fields = ['has_evidence', 'publications']
94
-
95
- if grouping_fields is None or len(grouping_fields) == 0:
96
- grouping_fields = ['subject', 'negated', 'predicate', 'object']
97
-
98
-
99
90
  if not dry_run:
100
91
  print(f"fields: {','.join(edge_fields)}")
101
92
  print(f"output_file: {edges_output_file}")
@@ -139,10 +130,12 @@ def add_closure(kg_archive: str,
139
130
  create or replace table denormalized_edges as
140
131
  select edges.*,
141
132
  {"".join([edge_columns(field) for field in edge_fields])}
133
+ {"".join([edge_columns(field, include_closure_fields=False) for field in edge_fields_to_label])}
142
134
  {evidence_sum(evidence_fields)}
143
135
  {grouping_key(grouping_fields)}
144
136
  from edges
145
137
  {"".join([edge_joins(field) for field in edge_fields])}
138
+ {"".join([edge_joins(field, include_closure_joins=False) for field in edge_fields_to_label])}
146
139
  """
147
140
 
148
141
  print(edges_query)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: closurizer
3
- Version: 0.6.0
3
+ Version: 0.7.0
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
@@ -11,6 +11,7 @@ Classifier: Programming Language :: Python :: 3.9
11
11
  Classifier: Programming Language :: Python :: 3.10
12
12
  Classifier: Programming Language :: Python :: 3.11
13
13
  Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
14
15
  Requires-Dist: SQLAlchemy (>=1.4.37,<2.0.0)
15
16
  Requires-Dist: click (>=8,<9)
16
- Requires-Dist: duckdb (>=0.10.2,<0.11.0)
17
+ Requires-Dist: duckdb
@@ -0,0 +1,6 @@
1
+ closurizer/cli.py,sha256=xTFscsxGDnaKoTNhn1FefRPPeldI5tZvvp3DygNai7Y,2069
2
+ closurizer/closurizer.py,sha256=iDYNDPE4VI34pqE2OVwlbqWXspYTj8-fyxWTqQeyW1Y,6992
3
+ closurizer-0.7.0.dist-info/METADATA,sha256=PbhHYiVy2mzN1uEgN-L1UvYw1C5uMuJw68OL-EpR3Tg,661
4
+ closurizer-0.7.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
5
+ closurizer-0.7.0.dist-info/entry_points.txt,sha256=MnAVu1lgP6DqDb3BZGNzVs2AnDMsp4sThi3ccWbONFo,50
6
+ closurizer-0.7.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.9.0
2
+ Generator: poetry-core 1.9.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,6 +0,0 @@
1
- closurizer/cli.py,sha256=AfK0Dy0lSmngUfzxKsT6VuH_YqjUVA1yU1Ko41Yil1w,1827
2
- closurizer/closurizer.py,sha256=MMFeYqmgKB6Pr9Eh2jWeZt4mnDS635oGg8rl0ywJRvE,6902
3
- closurizer-0.6.0.dist-info/METADATA,sha256=IALfF2731qv6hyIPRPiwYESfFNPshLmMnQ3PPEVo9eQ,629
4
- closurizer-0.6.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
5
- closurizer-0.6.0.dist-info/entry_points.txt,sha256=MnAVu1lgP6DqDb3BZGNzVs2AnDMsp4sThi3ccWbONFo,50
6
- closurizer-0.6.0.dist-info/RECORD,,