es-aces 0.2.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.
aces/__init__.py ADDED
File without changes
aces/__main__.py ADDED
@@ -0,0 +1,76 @@
1
+ """Main script for end-to-end task querying."""
2
+
3
+ import os
4
+ from pathlib import Path
5
+
6
+ import hydra
7
+ import polars as pl
8
+ from loguru import logger
9
+ from omegaconf import DictConfig
10
+
11
+ from . import config, predicates, query
12
+
13
+
14
+ def load_using_directory(cfg: config.TaskExtractorConfig, path: str | Path) -> pl.DataFrame:
15
+ # currently only supports ESGPT dataset when loading from directory
16
+ return predicates.generate_predicates_df(cfg, path, standard="ESGPT")
17
+
18
+
19
+ def load_using_file(cfg: config.TaskExtractorConfig, path: str | Path) -> pl.DataFrame:
20
+ # .csv file
21
+ if path.suffix.lower() == ".csv":
22
+ return predicates.generate_predicates_df(cfg, path, standard="CSV")
23
+ # .parquet file (for MEDS)
24
+ elif path.suffix.lower() == ".parquet":
25
+ return predicates.generate_predicates_df(cfg, path, standard="MEDS")
26
+ else:
27
+ logger.error(f"Unsupported file type: {path.suffix}")
28
+ return
29
+
30
+
31
+ @hydra.main(version_base=None, config_path="", config_name="")
32
+ def main(cfg: DictConfig) -> None:
33
+ cfg = hydra.utils.instantiate(cfg, _convert_="all")
34
+
35
+ # Set output path
36
+ if "output_path" not in cfg or not cfg["output_path"]:
37
+ output_path = Path.cwd()
38
+ else:
39
+ output_path = Path(cfg["output_path"])
40
+
41
+ # load configuration
42
+ logger.info("Loading config...")
43
+ task_cfg_path = Path(cfg["config_path"])
44
+ task_cfg = config.TaskExtractorConfig.load(task_cfg_path)
45
+
46
+ # get predicates_df
47
+ logger.info("Loading data...")
48
+ data_path = Path(cfg["data_path"])
49
+ if not data_path.exists():
50
+ logger.error(f"{data_path} does not exist.")
51
+ return
52
+
53
+ if data_path.is_dir():
54
+ # load directory
55
+ logger.info("Directory provided, checking directory...")
56
+ predicates_df = load_using_directory(task_cfg, data_path)
57
+ else:
58
+ # load file
59
+ logger.info("File path provided, checking file...")
60
+ predicates_df = load_using_file(task_cfg, data_path)
61
+
62
+ # query results
63
+ result = query.query(task_cfg, predicates_df)
64
+
65
+ # save results
66
+ result = result.with_columns(
67
+ *[pl.col(col).struct.json_encode() for col in result.columns if "summary" in col]
68
+ ).write_csv(
69
+ os.path.join(output_path, "result.csv"),
70
+ include_header=True,
71
+ date_format="%m/%d/%Y %H:%M",
72
+ )
73
+
74
+
75
+ if __name__ == "__main__":
76
+ main()