data-atlas 0.0.1__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Raffaele Giancotti
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,139 @@
1
+ Metadata-Version: 2.4
2
+ Name: data-atlas
3
+ Version: 0.0.1
4
+ Summary: Generate clinical data dictionaries using language models
5
+ Author-email: Raffaele Giancotti <raffaele.giancotti@unical.it>
6
+ License: MIT
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: click>=8.0.0
11
+ Requires-Dist: pandas>=2.0.0
12
+ Requires-Dist: numpy>=1.20.0
13
+ Requires-Dist: requests>=2.25.0
14
+ Requires-Dist: ollama>=0.1.0
15
+ Requires-Dist: torch>=2.0.0
16
+ Requires-Dist: transformers>=4.20.0
17
+ Requires-Dist: sentence-transformers>=2.0.0
18
+ Requires-Dist: scikit-learn>=1.0.0
19
+ Requires-Dist: reportlab>=3.6.0
20
+ Requires-Dist: tqdm>=4.60.0
21
+ Provides-Extra: dev
22
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
23
+ Dynamic: license-file
24
+
25
+ # Data Dictionary Generator
26
+
27
+ A Python package to automatically generate data dictionaries for clinical datasets using a large language model (LLM) via Ollama. This tool takes in dataset files (CSV format), processes them, and generates descriptions for each column in the dataset, as well as other metadata like data types, sample data, table descriptions and some quality information such as missing values, outliers and redundant values. It is also able to find relationships between tables and columns.
28
+
29
+ ## Features
30
+ ### Metadata Generation
31
+ - **Column Descriptions**: AI-generated clinical context for each field
32
+ - **Table Summaries**: Dataset-level documentation
33
+ - **Smart Sampling**: Automatic data type detection with sample values
34
+
35
+ ### Quality Analysis
36
+ - Missing value statistics
37
+ - Outlier detection (numeric fields)
38
+ - Duplicate row/column identification
39
+
40
+ ### Advanced Capabilities
41
+ - **Semantic Relationship Detection**: Finds connected columns across tables
42
+ - **Multi-Format Outputs**: JSON, Markdown
43
+ - **Custom LLM Integration**: Supports any Ollama, OpenAI and Google Gemini models
44
+
45
+ ## Requirements
46
+
47
+ Make sure you have Python 3.8+ installed. All dependencies are automatically installed when you install the package.
48
+
49
+ ## Installation
50
+
51
+ Clone the repository:
52
+
53
+ ```bash
54
+ git clone https://github.com/rafgia/data-dictionary-generator.git
55
+ cd code
56
+ ```
57
+
58
+ Install the package:
59
+
60
+ ```bash
61
+ pip install -e .
62
+ ```
63
+
64
+ ## Usage
65
+
66
+ ### Command-line Interface
67
+
68
+ Once the package is installed, you can use the command line to generate metadata for your dataset(s).
69
+
70
+ To run the tool, use the following command:
71
+
72
+ ```bash
73
+ python generate_dictionary.py <folder_path> --output-dir <output_dir> --model llama3.1
74
+ ```
75
+
76
+ #### Parameters:
77
+ - `<folder_path>`: The path to the folder containing your CSV files.
78
+ - `<output-dir>`: The name of the path where the metadata will be saved.
79
+ - `--model`: Specify the Ollama or OpenAI model to use for generating metadata.
80
+
81
+ ### Example
82
+
83
+ 1. **Prepare your data files**:
84
+ Place all your CSV files (representing tables in your dataset) in a folder, e.g., `data/MIMIC`.
85
+
86
+ 2. **Run the generator**:
87
+
88
+ ```bash
89
+ python -m generate_dictionary.py data/MIMIC --output-dir output --model gpt-4o-mini
90
+ ```
91
+
92
+ This will generate metadata for each column in the dataset and save it to a JSON file and a Markdown summary for the dictionary, and a .png plot and a markdown summary for the detected relationships.
93
+
94
+ ### Sample Output
95
+
96
+ For each **table** in your dataset, the following metadata will be generated:
97
+ - **Table Name**: The name of the table (CSV filename).
98
+ - **Number of Rows**: The total number of rows in the table.
99
+ - **Number of Columns**: The total number of columns in the table.
100
+ - **Table Description**: A generated description of what the table contains.
101
+
102
+ For each **column** in your dataset:
103
+ - **Column Name**: The name of the column.
104
+ - **Sample Data**: A sample of 5 data points from the column.
105
+ - **Data Type**: The inferred data type (e.g., integer, float, string).
106
+ - **Column Description**: A description generated by the model for the column.
107
+
108
+ ### Example of generated metadata:
109
+
110
+
111
+ ## Troubleshooting
112
+
113
+ ### 1. If you encounter an error such as `model not found`, make sure you have set up Ollama correctly and the model is available.
114
+ - Ensure that you can manually run the model using `ollama run llama3.1` from the command line before using it in the Python script.
115
+
116
+ ### 2. If the dependencies are not installing, make sure you're using the correct Python version and have all required libraries listed in `pyproject.toml`.
117
+
118
+ ### 3. If the dataset is very large, consider breaking it down into smaller CSV files for more efficient processing.
119
+
120
+ ## Contributing
121
+
122
+ If you would like to contribute to this project, feel free to fork the repository and submit a pull request. Make sure to add tests and document any new features.
123
+
124
+ ### To contribute:
125
+ 1. Fork the repository.
126
+ 2. Create a new branch (`git checkout -b feature-name`).
127
+ 3. Make your changes and commit them (`git commit -am 'Add new feature'`).
128
+ 4. Push to the branch (`git push origin feature-name`).
129
+ 5. Open a pull request.
130
+
131
+ ## License
132
+
133
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
134
+
135
+ ---
136
+
137
+ ## Author
138
+
139
+ Raffaele Giancotti
@@ -0,0 +1,115 @@
1
+ # Data Dictionary Generator
2
+
3
+ A Python package to automatically generate data dictionaries for clinical datasets using a large language model (LLM) via Ollama. This tool takes in dataset files (CSV format), processes them, and generates descriptions for each column in the dataset, as well as other metadata like data types, sample data, table descriptions and some quality information such as missing values, outliers and redundant values. It is also able to find relationships between tables and columns.
4
+
5
+ ## Features
6
+ ### Metadata Generation
7
+ - **Column Descriptions**: AI-generated clinical context for each field
8
+ - **Table Summaries**: Dataset-level documentation
9
+ - **Smart Sampling**: Automatic data type detection with sample values
10
+
11
+ ### Quality Analysis
12
+ - Missing value statistics
13
+ - Outlier detection (numeric fields)
14
+ - Duplicate row/column identification
15
+
16
+ ### Advanced Capabilities
17
+ - **Semantic Relationship Detection**: Finds connected columns across tables
18
+ - **Multi-Format Outputs**: JSON, Markdown
19
+ - **Custom LLM Integration**: Supports any Ollama, OpenAI and Google Gemini models
20
+
21
+ ## Requirements
22
+
23
+ Make sure you have Python 3.8+ installed. All dependencies are automatically installed when you install the package.
24
+
25
+ ## Installation
26
+
27
+ Clone the repository:
28
+
29
+ ```bash
30
+ git clone https://github.com/rafgia/data-dictionary-generator.git
31
+ cd code
32
+ ```
33
+
34
+ Install the package:
35
+
36
+ ```bash
37
+ pip install -e .
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ ### Command-line Interface
43
+
44
+ Once the package is installed, you can use the command line to generate metadata for your dataset(s).
45
+
46
+ To run the tool, use the following command:
47
+
48
+ ```bash
49
+ python generate_dictionary.py <folder_path> --output-dir <output_dir> --model llama3.1
50
+ ```
51
+
52
+ #### Parameters:
53
+ - `<folder_path>`: The path to the folder containing your CSV files.
54
+ - `<output-dir>`: The name of the path where the metadata will be saved.
55
+ - `--model`: Specify the Ollama or OpenAI model to use for generating metadata.
56
+
57
+ ### Example
58
+
59
+ 1. **Prepare your data files**:
60
+ Place all your CSV files (representing tables in your dataset) in a folder, e.g., `data/MIMIC`.
61
+
62
+ 2. **Run the generator**:
63
+
64
+ ```bash
65
+ python -m generate_dictionary.py data/MIMIC --output-dir output --model gpt-4o-mini
66
+ ```
67
+
68
+ This will generate metadata for each column in the dataset and save it to a JSON file and a Markdown summary for the dictionary, and a .png plot and a markdown summary for the detected relationships.
69
+
70
+ ### Sample Output
71
+
72
+ For each **table** in your dataset, the following metadata will be generated:
73
+ - **Table Name**: The name of the table (CSV filename).
74
+ - **Number of Rows**: The total number of rows in the table.
75
+ - **Number of Columns**: The total number of columns in the table.
76
+ - **Table Description**: A generated description of what the table contains.
77
+
78
+ For each **column** in your dataset:
79
+ - **Column Name**: The name of the column.
80
+ - **Sample Data**: A sample of 5 data points from the column.
81
+ - **Data Type**: The inferred data type (e.g., integer, float, string).
82
+ - **Column Description**: A description generated by the model for the column.
83
+
84
+ ### Example of generated metadata:
85
+
86
+
87
+ ## Troubleshooting
88
+
89
+ ### 1. If you encounter an error such as `model not found`, make sure you have set up Ollama correctly and the model is available.
90
+ - Ensure that you can manually run the model using `ollama run llama3.1` from the command line before using it in the Python script.
91
+
92
+ ### 2. If the dependencies are not installing, make sure you're using the correct Python version and have all required libraries listed in `pyproject.toml`.
93
+
94
+ ### 3. If the dataset is very large, consider breaking it down into smaller CSV files for more efficient processing.
95
+
96
+ ## Contributing
97
+
98
+ If you would like to contribute to this project, feel free to fork the repository and submit a pull request. Make sure to add tests and document any new features.
99
+
100
+ ### To contribute:
101
+ 1. Fork the repository.
102
+ 2. Create a new branch (`git checkout -b feature-name`).
103
+ 3. Make your changes and commit them (`git commit -am 'Add new feature'`).
104
+ 4. Push to the branch (`git push origin feature-name`).
105
+ 5. Open a pull request.
106
+
107
+ ## License
108
+
109
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
110
+
111
+ ---
112
+
113
+ ## Author
114
+
115
+ Raffaele Giancotti
@@ -0,0 +1,139 @@
1
+ Metadata-Version: 2.4
2
+ Name: data-atlas
3
+ Version: 0.0.1
4
+ Summary: Generate clinical data dictionaries using language models
5
+ Author-email: Raffaele Giancotti <raffaele.giancotti@unical.it>
6
+ License: MIT
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: click>=8.0.0
11
+ Requires-Dist: pandas>=2.0.0
12
+ Requires-Dist: numpy>=1.20.0
13
+ Requires-Dist: requests>=2.25.0
14
+ Requires-Dist: ollama>=0.1.0
15
+ Requires-Dist: torch>=2.0.0
16
+ Requires-Dist: transformers>=4.20.0
17
+ Requires-Dist: sentence-transformers>=2.0.0
18
+ Requires-Dist: scikit-learn>=1.0.0
19
+ Requires-Dist: reportlab>=3.6.0
20
+ Requires-Dist: tqdm>=4.60.0
21
+ Provides-Extra: dev
22
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
23
+ Dynamic: license-file
24
+
25
+ # Data Dictionary Generator
26
+
27
+ A Python package to automatically generate data dictionaries for clinical datasets using a large language model (LLM) via Ollama. This tool takes in dataset files (CSV format), processes them, and generates descriptions for each column in the dataset, as well as other metadata like data types, sample data, table descriptions and some quality information such as missing values, outliers and redundant values. It is also able to find relationships between tables and columns.
28
+
29
+ ## Features
30
+ ### Metadata Generation
31
+ - **Column Descriptions**: AI-generated clinical context for each field
32
+ - **Table Summaries**: Dataset-level documentation
33
+ - **Smart Sampling**: Automatic data type detection with sample values
34
+
35
+ ### Quality Analysis
36
+ - Missing value statistics
37
+ - Outlier detection (numeric fields)
38
+ - Duplicate row/column identification
39
+
40
+ ### Advanced Capabilities
41
+ - **Semantic Relationship Detection**: Finds connected columns across tables
42
+ - **Multi-Format Outputs**: JSON, Markdown
43
+ - **Custom LLM Integration**: Supports any Ollama, OpenAI and Google Gemini models
44
+
45
+ ## Requirements
46
+
47
+ Make sure you have Python 3.8+ installed. All dependencies are automatically installed when you install the package.
48
+
49
+ ## Installation
50
+
51
+ Clone the repository:
52
+
53
+ ```bash
54
+ git clone https://github.com/rafgia/data-dictionary-generator.git
55
+ cd code
56
+ ```
57
+
58
+ Install the package:
59
+
60
+ ```bash
61
+ pip install -e .
62
+ ```
63
+
64
+ ## Usage
65
+
66
+ ### Command-line Interface
67
+
68
+ Once the package is installed, you can use the command line to generate metadata for your dataset(s).
69
+
70
+ To run the tool, use the following command:
71
+
72
+ ```bash
73
+ python generate_dictionary.py <folder_path> --output-dir <output_dir> --model llama3.1
74
+ ```
75
+
76
+ #### Parameters:
77
+ - `<folder_path>`: The path to the folder containing your CSV files.
78
+ - `<output-dir>`: The name of the path where the metadata will be saved.
79
+ - `--model`: Specify the Ollama or OpenAI model to use for generating metadata.
80
+
81
+ ### Example
82
+
83
+ 1. **Prepare your data files**:
84
+ Place all your CSV files (representing tables in your dataset) in a folder, e.g., `data/MIMIC`.
85
+
86
+ 2. **Run the generator**:
87
+
88
+ ```bash
89
+ python -m generate_dictionary.py data/MIMIC --output-dir output --model gpt-4o-mini
90
+ ```
91
+
92
+ This will generate metadata for each column in the dataset and save it to a JSON file and a Markdown summary for the dictionary, and a .png plot and a markdown summary for the detected relationships.
93
+
94
+ ### Sample Output
95
+
96
+ For each **table** in your dataset, the following metadata will be generated:
97
+ - **Table Name**: The name of the table (CSV filename).
98
+ - **Number of Rows**: The total number of rows in the table.
99
+ - **Number of Columns**: The total number of columns in the table.
100
+ - **Table Description**: A generated description of what the table contains.
101
+
102
+ For each **column** in your dataset:
103
+ - **Column Name**: The name of the column.
104
+ - **Sample Data**: A sample of 5 data points from the column.
105
+ - **Data Type**: The inferred data type (e.g., integer, float, string).
106
+ - **Column Description**: A description generated by the model for the column.
107
+
108
+ ### Example of generated metadata:
109
+
110
+
111
+ ## Troubleshooting
112
+
113
+ ### 1. If you encounter an error such as `model not found`, make sure you have set up Ollama correctly and the model is available.
114
+ - Ensure that you can manually run the model using `ollama run llama3.1` from the command line before using it in the Python script.
115
+
116
+ ### 2. If the dependencies are not installing, make sure you're using the correct Python version and have all required libraries listed in `pyproject.toml`.
117
+
118
+ ### 3. If the dataset is very large, consider breaking it down into smaller CSV files for more efficient processing.
119
+
120
+ ## Contributing
121
+
122
+ If you would like to contribute to this project, feel free to fork the repository and submit a pull request. Make sure to add tests and document any new features.
123
+
124
+ ### To contribute:
125
+ 1. Fork the repository.
126
+ 2. Create a new branch (`git checkout -b feature-name`).
127
+ 3. Make your changes and commit them (`git commit -am 'Add new feature'`).
128
+ 4. Push to the branch (`git push origin feature-name`).
129
+ 5. Open a pull request.
130
+
131
+ ## License
132
+
133
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
134
+
135
+ ---
136
+
137
+ ## Author
138
+
139
+ Raffaele Giancotti
@@ -0,0 +1,19 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ data_atlas.egg-info/PKG-INFO
5
+ data_atlas.egg-info/SOURCES.txt
6
+ data_atlas.egg-info/dependency_links.txt
7
+ data_atlas.egg-info/entry_points.txt
8
+ data_atlas.egg-info/requires.txt
9
+ data_atlas.egg-info/top_level.txt
10
+ data_dictionary_generator/__init__.py
11
+ data_dictionary_generator/column_stats.py
12
+ data_dictionary_generator/data_type.py
13
+ data_dictionary_generator/description_generator.py
14
+ data_dictionary_generator/generate_dictionary.py
15
+ data_dictionary_generator/load_dataset.py
16
+ data_dictionary_generator/metadata_extraction.py
17
+ data_dictionary_generator/pattern_extraction.py
18
+ data_dictionary_generator/relationships.py
19
+ tests/test_placeholder.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ generate-dictionary = data_dictionary_generator.generate_dictionary:main
@@ -0,0 +1,14 @@
1
+ click>=8.0.0
2
+ pandas>=2.0.0
3
+ numpy>=1.20.0
4
+ requests>=2.25.0
5
+ ollama>=0.1.0
6
+ torch>=2.0.0
7
+ transformers>=4.20.0
8
+ sentence-transformers>=2.0.0
9
+ scikit-learn>=1.0.0
10
+ reportlab>=3.6.0
11
+ tqdm>=4.60.0
12
+
13
+ [dev]
14
+ pytest>=7.0.0
@@ -0,0 +1 @@
1
+ data_dictionary_generator
File without changes
@@ -0,0 +1,56 @@
1
+ import pandas as pd
2
+ import numpy as np
3
+ from collections import Counter
4
+ from data_type import infer_data_type
5
+
6
+ def compute_column_stats(series: pd.Series, sample_size: int = 5000) -> dict:
7
+ """
8
+ Compute statistics for a column, based on inferred data type.
9
+ """
10
+
11
+ if series.empty:
12
+ return None
13
+
14
+ non_null_series = series.dropna()
15
+ if non_null_series.empty:
16
+ return None
17
+
18
+ if len(non_null_series) > sample_size:
19
+ non_null_series = non_null_series.sample(sample_size, random_state=42)
20
+
21
+ inferred_types = non_null_series.apply(infer_data_type)
22
+ col_type = inferred_types.value_counts().idxmax()
23
+
24
+ stats = {}
25
+
26
+ if col_type in ["integer", "float"]:
27
+ numeric = pd.to_numeric(non_null_series, errors="coerce").dropna()
28
+ if not numeric.empty:
29
+ stats = {
30
+ "min": float(numeric.min()),
31
+ "max": float(numeric.max()),
32
+ "mean": float(numeric.mean()),
33
+ "median": float(numeric.median()),
34
+ "std": float(numeric.std())
35
+ }
36
+
37
+ elif col_type == "datetime":
38
+ dates = pd.to_datetime(non_null_series, errors="coerce", format="mixed").dropna()
39
+ if not dates.empty:
40
+ stats = {
41
+ "min_date": dates.min().isoformat(),
42
+ "max_date": dates.max().isoformat()
43
+ }
44
+
45
+ elif col_type in ["string", "boolean"]:
46
+ counts = Counter(non_null_series.astype(str))
47
+ top_values = counts.most_common(10)
48
+ stats = {
49
+ "top_values": top_values,
50
+ "unique_count": len(counts)
51
+ }
52
+
53
+ else:
54
+ return None
55
+
56
+ return stats if stats else None
@@ -0,0 +1,66 @@
1
+ from dateutil.parser import parse as dateparse
2
+ import pandas as pd
3
+ import re
4
+
5
+ _date_pattern = re.compile(
6
+ r"(\d{4}[-/]\d{2}[-/]\d{2})" # 2024-01-31
7
+ r"|(\d{2}[-/]\d{2}[-/]\d{4})" # 31-01-2024
8
+ r"|(\d{4}[-/]\d{2}[-/]\d{2}T\d{2}:\d{2})" # 2024-01-31T12:00
9
+ )
10
+
11
+ def infer_data_type(value) -> str:
12
+ if pd.isna(value):
13
+ return "null"
14
+ if isinstance(value, bool):
15
+ return "boolean"
16
+ if isinstance(value, int):
17
+ return "integer"
18
+ if isinstance(value, float):
19
+ return "float"
20
+ if not isinstance(value, str):
21
+ return "string"
22
+ v = value.strip()
23
+ if v == "":
24
+ return "null"
25
+ lower = v.lower()
26
+ if lower in ("true", "false", "yes", "no", "y", "n", "t", "f"):
27
+ return "boolean"
28
+ temp_v = v.replace(",", "")
29
+ has_sign = temp_v.startswith(("+", "-"))
30
+ numeric_part = temp_v[1:] if has_sign else temp_v
31
+ if "+" in numeric_part or "-" in numeric_part:
32
+ return "string"
33
+ if numeric_part.isdigit():
34
+ return "integer"
35
+ try:
36
+ if "." in numeric_part:
37
+ if numeric_part.replace(".", "", 1).isdigit():
38
+ return "float"
39
+ float(temp_v)
40
+ return "float"
41
+ except ValueError:
42
+ pass
43
+
44
+ if _date_pattern.search(v):
45
+ try:
46
+ dateparse(v, fuzzy=False)
47
+ return "datetime"
48
+ except (ValueError, OverflowError):
49
+ pass
50
+
51
+ return "string"
52
+
53
+ def infer_column_data_type(series: pd.Series, sample_size: int = 100) -> str:
54
+ """
55
+ Infer the most likely data type of a column by sampling non-null values
56
+ and selecting the most frequent inferred type.
57
+ """
58
+ non_null_series = series.dropna()
59
+ if non_null_series.empty:
60
+ return "null"
61
+ sample = non_null_series.sample(
62
+ min(sample_size, len(non_null_series)), random_state=42
63
+ )
64
+ inferred_types = sample.apply(infer_data_type)
65
+ most_common = inferred_types.value_counts().idxmax()
66
+ return most_common