colsemantics 0.1.0__tar.gz → 0.4.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.
- colsemantics-0.4.1/PKG-INFO +231 -0
- colsemantics-0.4.1/README.md +198 -0
- {colsemantics-0.1.0 → colsemantics-0.4.1}/pyproject.toml +29 -11
- colsemantics-0.4.1/src/colsemantics/__init__.py +281 -0
- colsemantics-0.4.1/src/colsemantics/_data.py +13 -0
- colsemantics-0.4.1/src/colsemantics/_taxonomy.py +776 -0
- colsemantics-0.4.1/src/colsemantics/benchmark.py +160 -0
- colsemantics-0.4.1/src/colsemantics/calibration.json +17 -0
- colsemantics-0.4.1/src/colsemantics/calibration.py +43 -0
- colsemantics-0.4.1/src/colsemantics/cli.py +84 -0
- colsemantics-0.4.1/src/colsemantics/context.py +73 -0
- colsemantics-0.4.1/src/colsemantics/csv_inference.py +155 -0
- colsemantics-0.4.1/src/colsemantics/data/SOURCES.md +18 -0
- colsemantics-0.4.1/src/colsemantics/data/br_first_names.txt +370 -0
- colsemantics-0.4.1/src/colsemantics/data/br_municipalities.txt +5290 -0
- colsemantics-0.4.1/src/colsemantics/data/countries.txt +373 -0
- colsemantics-0.4.1/src/colsemantics/data/modifiers.txt +763 -0
- colsemantics-0.4.1/src/colsemantics/data/us_cities.txt +2947 -0
- colsemantics-0.4.1/src/colsemantics/data/us_first_names.txt +1500 -0
- colsemantics-0.4.1/src/colsemantics/detectors.py +391 -0
- colsemantics-0.4.1/src/colsemantics/evidence.py +54 -0
- colsemantics-0.4.1/src/colsemantics/patterns.py +430 -0
- colsemantics-0.4.1/src/colsemantics/profiles.py +34 -0
- colsemantics-0.4.1/src/colsemantics/profiling.py +126 -0
- colsemantics-0.4.1/src/colsemantics/results.py +69 -0
- colsemantics-0.4.1/src/colsemantics/sensitivity.py +44 -0
- colsemantics-0.4.1/src/colsemantics/tokens.py +125 -0
- colsemantics-0.4.1/src/colsemantics/vocabularies.py +89 -0
- colsemantics-0.4.1/src/colsemantics/vocabulary.py +550 -0
- colsemantics-0.4.1/src/colsemantics.egg-info/PKG-INFO +231 -0
- colsemantics-0.4.1/src/colsemantics.egg-info/SOURCES.txt +50 -0
- colsemantics-0.4.1/src/colsemantics.egg-info/entry_points.txt +2 -0
- colsemantics-0.4.1/src/colsemantics.egg-info/requires.txt +9 -0
- colsemantics-0.4.1/tests/test_benchmark.py +70 -0
- colsemantics-0.4.1/tests/test_calibration.py +29 -0
- colsemantics-0.4.1/tests/test_cli.py +39 -0
- colsemantics-0.4.1/tests/test_colsemantics.py +208 -0
- colsemantics-0.4.1/tests/test_csv_inference.py +209 -0
- colsemantics-0.4.1/tests/test_english_core.py +10 -0
- colsemantics-0.4.1/tests/test_pattern_results.py +135 -0
- colsemantics-0.4.1/tests/test_patterns.py +217 -0
- colsemantics-0.4.1/tests/test_profiles.py +24 -0
- colsemantics-0.4.1/tests/test_profiling.py +87 -0
- colsemantics-0.4.1/tests/test_public_vocabulary.py +113 -0
- colsemantics-0.4.1/tests/test_sensitivity.py +42 -0
- colsemantics-0.4.1/tests/test_validation_corpus.py +80 -0
- colsemantics-0.4.1/tests/test_vocabularies.py +110 -0
- colsemantics-0.1.0/PKG-INFO +0 -162
- colsemantics-0.1.0/README.md +0 -135
- colsemantics-0.1.0/src/colsemantics/__init__.py +0 -248
- colsemantics-0.1.0/src/colsemantics/_taxonomy.py +0 -177
- colsemantics-0.1.0/src/colsemantics/detectors.py +0 -362
- colsemantics-0.1.0/src/colsemantics/evidence.py +0 -82
- colsemantics-0.1.0/src/colsemantics/tokens.py +0 -131
- colsemantics-0.1.0/src/colsemantics/vocabulary.py +0 -171
- colsemantics-0.1.0/src/colsemantics.egg-info/PKG-INFO +0 -162
- colsemantics-0.1.0/src/colsemantics.egg-info/SOURCES.txt +0 -16
- colsemantics-0.1.0/src/colsemantics.egg-info/requires.txt +0 -7
- colsemantics-0.1.0/tests/test_colsemantics.py +0 -384
- {colsemantics-0.1.0 → colsemantics-0.4.1}/LICENSE +0 -0
- {colsemantics-0.1.0 → colsemantics-0.4.1}/setup.cfg +0 -0
- {colsemantics-0.1.0 → colsemantics-0.4.1}/src/colsemantics/py.typed +0 -0
- {colsemantics-0.1.0 → colsemantics-0.4.1}/src/colsemantics.egg-info/dependency_links.txt +0 -0
- {colsemantics-0.1.0 → colsemantics-0.4.1}/src/colsemantics.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: colsemantics
|
|
3
|
+
Version: 0.4.1
|
|
4
|
+
Summary: Infer semantic roles and domains for tabular columns from names, values, and table context.
|
|
5
|
+
Author: Caio
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Caio-Analytics/colsemantics
|
|
8
|
+
Project-URL: Repository, https://github.com/Caio-Analytics/colsemantics
|
|
9
|
+
Project-URL: Issues, https://github.com/Caio-Analytics/colsemantics/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/Caio-Analytics/colsemantics/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: semantic-inference,data-profiling,schema-inference,column-classification,pii,etl
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: rapidfuzz>=3.14.6
|
|
25
|
+
Requires-Dist: unidecode>=1.4.0
|
|
26
|
+
Requires-Dist: PyYAML>=6.0.3
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest>=9.2.0; extra == "dev"
|
|
29
|
+
Requires-Dist: pytest-cov>=7.1.0; extra == "dev"
|
|
30
|
+
Requires-Dist: mypy>=2.4.1; extra == "dev"
|
|
31
|
+
Requires-Dist: ruff>=0.17.4; extra == "dev"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# colsemantics
|
|
35
|
+
|
|
36
|
+
[](https://pypi.org/project/colsemantics/)
|
|
37
|
+
[](https://pypi.org/project/colsemantics/)
|
|
38
|
+
[](https://github.com/Caio-Analytics/colsemantics/actions/workflows/ci.yml)
|
|
39
|
+
[](LICENSE)
|
|
40
|
+
[](https://pypi.org/project/colsemantics/)
|
|
41
|
+
|
|
42
|
+
`colsemantics` infers the structural role and business domain of tabular columns from column names, sampled values, and neighboring columns.
|
|
43
|
+
|
|
44
|
+
It is useful when a dataset has unclear headers such as `cd_dpto_lot`, `f27`, or `SUPPLIER_CONTACT_CODE`.
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install colsemantics
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Quick start
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from colsemantics import infer_column
|
|
56
|
+
|
|
57
|
+
result = infer_column("SUPPLIER_CONTACT_CODE")
|
|
58
|
+
print(result["role"])
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The English API returns English field names and category labels.
|
|
62
|
+
|
|
63
|
+
## Analyze a CSV file
|
|
64
|
+
|
|
65
|
+
Install the command-line interface with the package, then create a JSON report from a bounded CSV sample:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
colsemantics infer employees.csv --profile pt-BR --sample 10000 --output report.json
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
CSV is the supported file format in this release. The report records its source, profile, sample size, inferred columns, and a semantic summary.
|
|
72
|
+
|
|
73
|
+
## Use sampled values
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from colsemantics import ContentProfile, infer_column
|
|
77
|
+
|
|
78
|
+
profile = ContentProfile(
|
|
79
|
+
data_type="Text",
|
|
80
|
+
distinct_values=["SP", "RJ", "MG", "BA"],
|
|
81
|
+
distinct_count=4,
|
|
82
|
+
uniqueness_ratio=0.1,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
result = infer_column("f27", profile=profile)
|
|
86
|
+
print(result["domain"])
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Analyze a table
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from colsemantics import infer_table
|
|
93
|
+
|
|
94
|
+
results = infer_table(
|
|
95
|
+
[
|
|
96
|
+
{"column_name": "employee_id"},
|
|
97
|
+
{"column_name": "department_name"},
|
|
98
|
+
{"column_name": "start_date"},
|
|
99
|
+
]
|
|
100
|
+
)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`infer_table` uses high-confidence classifications as table context when it evaluates ambiguous columns.
|
|
104
|
+
|
|
105
|
+
## Vocabulary profiles and extensions
|
|
106
|
+
|
|
107
|
+
`pt-BR` is the embedded (and default) profile. A profile controls the column-name vocabulary only; value patterns such as e-mail, phone, and postal code are detected independently of it. Use `available_profiles()` to list embedded profiles and `load_profile()` when an application needs an explicit context.
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from colsemantics import infer_column, temporary_profile
|
|
111
|
+
|
|
112
|
+
with temporary_profile("pt-BR", "company-vocabulary.yaml"):
|
|
113
|
+
result = infer_column("cost_bucket")
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
YAML extensions use the English schema and apply only within the selected context:
|
|
117
|
+
|
|
118
|
+
Provide one or more comma-separated YAML files to `load_vocabularies`, then use the returned context for the current operation.
|
|
119
|
+
|
|
120
|
+
```yaml
|
|
121
|
+
strong_categories:
|
|
122
|
+
Project domain:
|
|
123
|
+
- workstream
|
|
124
|
+
column_overrides:
|
|
125
|
+
cost_bucket: Finance / Cost
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Custom vocabularies are scoped with `ContextVar`, so separate concurrent analyses do not share vocabulary changes.
|
|
129
|
+
|
|
130
|
+
## Benchmark inference quality
|
|
131
|
+
|
|
132
|
+
Run the synthetic benchmark fixture included with the repository:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
colsemantics benchmark benchmarks/synthetic.json --output benchmark-report.json
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
The report includes semantic, role, and domain accuracy, coverage, per-profile metrics, a confusion matrix, and calibration buckets with expected calibration error. Public corpus definitions are stored as source manifests; they are not bundled or downloaded automatically.
|
|
139
|
+
|
|
140
|
+
## Confidence and review decisions
|
|
141
|
+
|
|
142
|
+
`raw_confidence` is the direct score assembled from independent evidence. `confidence` is the profile calibration for that score bucket, derived from the versioned calibration fixture. A result sets `review_required` when calibrated confidence is below `0.80`.
|
|
143
|
+
|
|
144
|
+
See `benchmarks/README.md` for the held-out validation set; its first measurement was 71% semantic accuracy on 52 hand-written cases (Brazilian and US column names), which shows the engine is not yet production-grade for English column names.
|
|
145
|
+
|
|
146
|
+
The embedded calibration is provisional: it is a controlled regression fixture, not evidence of production-grade accuracy. A held-out, versioned corpus is required before treating its precision as a production measurement.
|
|
147
|
+
|
|
148
|
+
## Vocabulary and data sources
|
|
149
|
+
|
|
150
|
+
Beyond the hand-written terms, the vocabulary was extended from public data: column names of about 4,500 US open datasets (Socrata catalog) and 500 Brazilian CKAN resources, and word lists from IBGE (municipalities, countries, first names), the US SSA (first names), and `datasets/world-cities`. Only derived word lists are shipped. Sources, licenses, and the scripts that rebuild them are in `src/colsemantics/data/SOURCES.md` and `scripts/`.
|
|
151
|
+
|
|
152
|
+
With sampled values, columns of municipalities, US cities, countries, and first names (Brazilian or US) are recognized even when the column name says nothing. These lists are matched by exact (accent-insensitive) value, so misspelled or abbreviated values do not match.
|
|
153
|
+
|
|
154
|
+
## Value patterns and locales
|
|
155
|
+
|
|
156
|
+
When a column has sampled values, colsemantics also looks at how the values are written. Detection uses values only, so it works the same for Brazilian and US data and does not depend on the vocabulary profile.
|
|
157
|
+
|
|
158
|
+
| Type | Brazil (BR) | United States (US) |
|
|
159
|
+
|---|---|---|
|
|
160
|
+
| `phone` | `(11) 91234-5678`, `11 91234-5678`, `+55 11 91234-5678`, `(21) 3456-7890`, `0800 123 4567`; the area code (DDD) must exist, mobiles start with 9, landlines with 2-5 | `(415) 555-2671`, `415-555-2671`, `415.555.2671`, `+1 415 555 2671`; area code and exchange start with 2-9 and are not N11 |
|
|
161
|
+
| `postal_code` | CEP `01310-100` | `94105-1234` (ZIP+4) |
|
|
162
|
+
| `address` | `Rua das Flores, 123`, `Av. Paulista, 1578`, `Rodovia BR-101 km 5` | `123 Main St`, `500 N. Michigan Ave., Suite 300`, `PO Box 1234` |
|
|
163
|
+
| national id | `cpf`, `cnpj` (check digits verified) | `ssn` (area/group/serial ranges verified), `ein` (format only) |
|
|
164
|
+
| any | `email`, `uuid` | |
|
|
165
|
+
|
|
166
|
+
Bare digit strings such as `4155552671` or `11912345678`, and plain five-digit ZIP codes, are not reported as phones or postal codes because they are indistinguishable from ids and amounts. Addresses are matched heuristically and are never marked `validated`.
|
|
167
|
+
|
|
168
|
+
The result carries a `pattern` that says what was found and where it looks like it comes from:
|
|
169
|
+
|
|
170
|
+
```python
|
|
171
|
+
result = infer_column("f6", profile=profile_values(["(11) 91234-5678", "(21) 99876-5432"]))
|
|
172
|
+
result["pattern"]
|
|
173
|
+
# {"type": "phone", "locale": "BR", "variant": "mobile", "format": "(DD) 9NNNN-NNNN",
|
|
174
|
+
# "coverage": 1.0, "validated": True,
|
|
175
|
+
# "message": "100% of sampled values look like a Brazilian mobile phone number (e.g. (DD) 9NNNN-NNNN)"}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
`pattern` is `None` when no format reaches its coverage threshold (80% of the sampled values, 60% for addresses). The same text is used as the `evidence` of the classification. You can still pass `detected_pattern="phone"` to `infer_column`; legacy names (`CPF`, `E-mail`, `Telefone`, `CEP`) keep working.
|
|
179
|
+
|
|
180
|
+
`infer_csv` reads each file with type detection (numbers, dates, booleans in Brazilian and US formats), picks the `,`, `;`, tab, or `|` delimiter from the header, samples rows uniformly with a seed, and reports duplicate headers and malformed rows in `warnings`.
|
|
181
|
+
|
|
182
|
+
## Sensitive-data recommendations
|
|
183
|
+
|
|
184
|
+
Each result includes a descriptive `sensitivity` recommendation. It does not modify input data.
|
|
185
|
+
|
|
186
|
+
- Validated CPF or SSN patterns: `high` / `mask`
|
|
187
|
+
- Detected street addresses: `high` / `mask`
|
|
188
|
+
- Person identity semantics: `high` / `restrict`
|
|
189
|
+
- Contact semantics (e-mail, phone): `high` / `mask`
|
|
190
|
+
- CNPJ, EIN, postal codes, other identifiers: `medium` / `review`
|
|
191
|
+
- Everything else: `none` / `allow`
|
|
192
|
+
|
|
193
|
+
## Result shape
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
{
|
|
197
|
+
"semantic": str,
|
|
198
|
+
"role": str | None,
|
|
199
|
+
"domain": str | None,
|
|
200
|
+
"raw_confidence": float,
|
|
201
|
+
"confidence": float,
|
|
202
|
+
"evidence": str,
|
|
203
|
+
"conclusive": bool,
|
|
204
|
+
"review_required": bool,
|
|
205
|
+
"sensitivity": {"level": str, "action": str, "reason": str},
|
|
206
|
+
"pattern": dict | None, # see "Value patterns and locales"
|
|
207
|
+
"hypotheses": list[dict],
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Migrating from 0.2
|
|
212
|
+
|
|
213
|
+
`normalizar` and `tokenizar` were renamed to `normalize` and `tokenize`. The old names still work but emit a `DeprecationWarning` and will be removed in 1.0. `infer_table`, `assess_sensitivity`, `calibrate`, and `requires_review` are now listed in `__all__`.
|
|
214
|
+
|
|
215
|
+
Python 3.10 is no longer supported (it reached end of life, and current `rapidfuzz` requires 3.11).
|
|
216
|
+
|
|
217
|
+
## Contributing
|
|
218
|
+
|
|
219
|
+
Contributions are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for setup, checks, and the release process, and [CHANGELOG.md](CHANGELOG.md) for version history.
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
python -m pip install -e '.[dev]'
|
|
223
|
+
pytest --cov
|
|
224
|
+
ruff check .
|
|
225
|
+
ruff format --check .
|
|
226
|
+
mypy
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## License
|
|
230
|
+
|
|
231
|
+
MIT.
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# colsemantics
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/colsemantics/)
|
|
4
|
+
[](https://pypi.org/project/colsemantics/)
|
|
5
|
+
[](https://github.com/Caio-Analytics/colsemantics/actions/workflows/ci.yml)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](https://pypi.org/project/colsemantics/)
|
|
8
|
+
|
|
9
|
+
`colsemantics` infers the structural role and business domain of tabular columns from column names, sampled values, and neighboring columns.
|
|
10
|
+
|
|
11
|
+
It is useful when a dataset has unclear headers such as `cd_dpto_lot`, `f27`, or `SUPPLIER_CONTACT_CODE`.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install colsemantics
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick start
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from colsemantics import infer_column
|
|
23
|
+
|
|
24
|
+
result = infer_column("SUPPLIER_CONTACT_CODE")
|
|
25
|
+
print(result["role"])
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The English API returns English field names and category labels.
|
|
29
|
+
|
|
30
|
+
## Analyze a CSV file
|
|
31
|
+
|
|
32
|
+
Install the command-line interface with the package, then create a JSON report from a bounded CSV sample:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
colsemantics infer employees.csv --profile pt-BR --sample 10000 --output report.json
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
CSV is the supported file format in this release. The report records its source, profile, sample size, inferred columns, and a semantic summary.
|
|
39
|
+
|
|
40
|
+
## Use sampled values
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from colsemantics import ContentProfile, infer_column
|
|
44
|
+
|
|
45
|
+
profile = ContentProfile(
|
|
46
|
+
data_type="Text",
|
|
47
|
+
distinct_values=["SP", "RJ", "MG", "BA"],
|
|
48
|
+
distinct_count=4,
|
|
49
|
+
uniqueness_ratio=0.1,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
result = infer_column("f27", profile=profile)
|
|
53
|
+
print(result["domain"])
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Analyze a table
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from colsemantics import infer_table
|
|
60
|
+
|
|
61
|
+
results = infer_table(
|
|
62
|
+
[
|
|
63
|
+
{"column_name": "employee_id"},
|
|
64
|
+
{"column_name": "department_name"},
|
|
65
|
+
{"column_name": "start_date"},
|
|
66
|
+
]
|
|
67
|
+
)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`infer_table` uses high-confidence classifications as table context when it evaluates ambiguous columns.
|
|
71
|
+
|
|
72
|
+
## Vocabulary profiles and extensions
|
|
73
|
+
|
|
74
|
+
`pt-BR` is the embedded (and default) profile. A profile controls the column-name vocabulary only; value patterns such as e-mail, phone, and postal code are detected independently of it. Use `available_profiles()` to list embedded profiles and `load_profile()` when an application needs an explicit context.
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from colsemantics import infer_column, temporary_profile
|
|
78
|
+
|
|
79
|
+
with temporary_profile("pt-BR", "company-vocabulary.yaml"):
|
|
80
|
+
result = infer_column("cost_bucket")
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
YAML extensions use the English schema and apply only within the selected context:
|
|
84
|
+
|
|
85
|
+
Provide one or more comma-separated YAML files to `load_vocabularies`, then use the returned context for the current operation.
|
|
86
|
+
|
|
87
|
+
```yaml
|
|
88
|
+
strong_categories:
|
|
89
|
+
Project domain:
|
|
90
|
+
- workstream
|
|
91
|
+
column_overrides:
|
|
92
|
+
cost_bucket: Finance / Cost
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Custom vocabularies are scoped with `ContextVar`, so separate concurrent analyses do not share vocabulary changes.
|
|
96
|
+
|
|
97
|
+
## Benchmark inference quality
|
|
98
|
+
|
|
99
|
+
Run the synthetic benchmark fixture included with the repository:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
colsemantics benchmark benchmarks/synthetic.json --output benchmark-report.json
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
The report includes semantic, role, and domain accuracy, coverage, per-profile metrics, a confusion matrix, and calibration buckets with expected calibration error. Public corpus definitions are stored as source manifests; they are not bundled or downloaded automatically.
|
|
106
|
+
|
|
107
|
+
## Confidence and review decisions
|
|
108
|
+
|
|
109
|
+
`raw_confidence` is the direct score assembled from independent evidence. `confidence` is the profile calibration for that score bucket, derived from the versioned calibration fixture. A result sets `review_required` when calibrated confidence is below `0.80`.
|
|
110
|
+
|
|
111
|
+
See `benchmarks/README.md` for the held-out validation set; its first measurement was 71% semantic accuracy on 52 hand-written cases (Brazilian and US column names), which shows the engine is not yet production-grade for English column names.
|
|
112
|
+
|
|
113
|
+
The embedded calibration is provisional: it is a controlled regression fixture, not evidence of production-grade accuracy. A held-out, versioned corpus is required before treating its precision as a production measurement.
|
|
114
|
+
|
|
115
|
+
## Vocabulary and data sources
|
|
116
|
+
|
|
117
|
+
Beyond the hand-written terms, the vocabulary was extended from public data: column names of about 4,500 US open datasets (Socrata catalog) and 500 Brazilian CKAN resources, and word lists from IBGE (municipalities, countries, first names), the US SSA (first names), and `datasets/world-cities`. Only derived word lists are shipped. Sources, licenses, and the scripts that rebuild them are in `src/colsemantics/data/SOURCES.md` and `scripts/`.
|
|
118
|
+
|
|
119
|
+
With sampled values, columns of municipalities, US cities, countries, and first names (Brazilian or US) are recognized even when the column name says nothing. These lists are matched by exact (accent-insensitive) value, so misspelled or abbreviated values do not match.
|
|
120
|
+
|
|
121
|
+
## Value patterns and locales
|
|
122
|
+
|
|
123
|
+
When a column has sampled values, colsemantics also looks at how the values are written. Detection uses values only, so it works the same for Brazilian and US data and does not depend on the vocabulary profile.
|
|
124
|
+
|
|
125
|
+
| Type | Brazil (BR) | United States (US) |
|
|
126
|
+
|---|---|---|
|
|
127
|
+
| `phone` | `(11) 91234-5678`, `11 91234-5678`, `+55 11 91234-5678`, `(21) 3456-7890`, `0800 123 4567`; the area code (DDD) must exist, mobiles start with 9, landlines with 2-5 | `(415) 555-2671`, `415-555-2671`, `415.555.2671`, `+1 415 555 2671`; area code and exchange start with 2-9 and are not N11 |
|
|
128
|
+
| `postal_code` | CEP `01310-100` | `94105-1234` (ZIP+4) |
|
|
129
|
+
| `address` | `Rua das Flores, 123`, `Av. Paulista, 1578`, `Rodovia BR-101 km 5` | `123 Main St`, `500 N. Michigan Ave., Suite 300`, `PO Box 1234` |
|
|
130
|
+
| national id | `cpf`, `cnpj` (check digits verified) | `ssn` (area/group/serial ranges verified), `ein` (format only) |
|
|
131
|
+
| any | `email`, `uuid` | |
|
|
132
|
+
|
|
133
|
+
Bare digit strings such as `4155552671` or `11912345678`, and plain five-digit ZIP codes, are not reported as phones or postal codes because they are indistinguishable from ids and amounts. Addresses are matched heuristically and are never marked `validated`.
|
|
134
|
+
|
|
135
|
+
The result carries a `pattern` that says what was found and where it looks like it comes from:
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
result = infer_column("f6", profile=profile_values(["(11) 91234-5678", "(21) 99876-5432"]))
|
|
139
|
+
result["pattern"]
|
|
140
|
+
# {"type": "phone", "locale": "BR", "variant": "mobile", "format": "(DD) 9NNNN-NNNN",
|
|
141
|
+
# "coverage": 1.0, "validated": True,
|
|
142
|
+
# "message": "100% of sampled values look like a Brazilian mobile phone number (e.g. (DD) 9NNNN-NNNN)"}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
`pattern` is `None` when no format reaches its coverage threshold (80% of the sampled values, 60% for addresses). The same text is used as the `evidence` of the classification. You can still pass `detected_pattern="phone"` to `infer_column`; legacy names (`CPF`, `E-mail`, `Telefone`, `CEP`) keep working.
|
|
146
|
+
|
|
147
|
+
`infer_csv` reads each file with type detection (numbers, dates, booleans in Brazilian and US formats), picks the `,`, `;`, tab, or `|` delimiter from the header, samples rows uniformly with a seed, and reports duplicate headers and malformed rows in `warnings`.
|
|
148
|
+
|
|
149
|
+
## Sensitive-data recommendations
|
|
150
|
+
|
|
151
|
+
Each result includes a descriptive `sensitivity` recommendation. It does not modify input data.
|
|
152
|
+
|
|
153
|
+
- Validated CPF or SSN patterns: `high` / `mask`
|
|
154
|
+
- Detected street addresses: `high` / `mask`
|
|
155
|
+
- Person identity semantics: `high` / `restrict`
|
|
156
|
+
- Contact semantics (e-mail, phone): `high` / `mask`
|
|
157
|
+
- CNPJ, EIN, postal codes, other identifiers: `medium` / `review`
|
|
158
|
+
- Everything else: `none` / `allow`
|
|
159
|
+
|
|
160
|
+
## Result shape
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
{
|
|
164
|
+
"semantic": str,
|
|
165
|
+
"role": str | None,
|
|
166
|
+
"domain": str | None,
|
|
167
|
+
"raw_confidence": float,
|
|
168
|
+
"confidence": float,
|
|
169
|
+
"evidence": str,
|
|
170
|
+
"conclusive": bool,
|
|
171
|
+
"review_required": bool,
|
|
172
|
+
"sensitivity": {"level": str, "action": str, "reason": str},
|
|
173
|
+
"pattern": dict | None, # see "Value patterns and locales"
|
|
174
|
+
"hypotheses": list[dict],
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Migrating from 0.2
|
|
179
|
+
|
|
180
|
+
`normalizar` and `tokenizar` were renamed to `normalize` and `tokenize`. The old names still work but emit a `DeprecationWarning` and will be removed in 1.0. `infer_table`, `assess_sensitivity`, `calibrate`, and `requires_review` are now listed in `__all__`.
|
|
181
|
+
|
|
182
|
+
Python 3.10 is no longer supported (it reached end of life, and current `rapidfuzz` requires 3.11).
|
|
183
|
+
|
|
184
|
+
## Contributing
|
|
185
|
+
|
|
186
|
+
Contributions are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for setup, checks, and the release process, and [CHANGELOG.md](CHANGELOG.md) for version history.
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
python -m pip install -e '.[dev]'
|
|
190
|
+
pytest --cov
|
|
191
|
+
ruff check .
|
|
192
|
+
ruff format --check .
|
|
193
|
+
mypy
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## License
|
|
197
|
+
|
|
198
|
+
MIT.
|
|
@@ -1,42 +1,50 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "colsemantics"
|
|
3
|
-
version = "0.1
|
|
4
|
-
description = "
|
|
3
|
+
version = "0.4.1"
|
|
4
|
+
description = "Infer semantic roles and domains for tabular columns from names, values, and table context."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
7
7
|
authors = [{ name = "Caio" }]
|
|
8
|
-
requires-python = ">=3.
|
|
9
|
-
keywords = ["semantic", "data-profiling", "
|
|
8
|
+
requires-python = ">=3.11"
|
|
9
|
+
keywords = ["semantic-inference", "data-profiling", "schema-inference", "column-classification", "pii", "etl"]
|
|
10
10
|
classifiers = [
|
|
11
11
|
"Development Status :: 3 - Alpha",
|
|
12
12
|
"Intended Audience :: Developers",
|
|
13
13
|
"Programming Language :: Python :: 3",
|
|
14
|
-
"Programming Language :: Python :: 3.10",
|
|
15
14
|
"Programming Language :: Python :: 3.11",
|
|
16
15
|
"Programming Language :: Python :: 3.12",
|
|
16
|
+
"Programming Language :: Python :: 3.13",
|
|
17
|
+
"Programming Language :: Python :: 3.14",
|
|
17
18
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
18
19
|
"Typing :: Typed",
|
|
19
20
|
]
|
|
20
21
|
dependencies = [
|
|
21
|
-
"rapidfuzz>=3.
|
|
22
|
-
"unidecode>=1.
|
|
22
|
+
"rapidfuzz>=3.14.6",
|
|
23
|
+
"unidecode>=1.4.0",
|
|
24
|
+
"PyYAML>=6.0.3",
|
|
23
25
|
]
|
|
24
26
|
|
|
25
27
|
[project.urls]
|
|
26
28
|
Homepage = "https://github.com/Caio-Analytics/colsemantics"
|
|
29
|
+
Repository = "https://github.com/Caio-Analytics/colsemantics"
|
|
30
|
+
Issues = "https://github.com/Caio-Analytics/colsemantics/issues"
|
|
31
|
+
Changelog = "https://github.com/Caio-Analytics/colsemantics/blob/main/CHANGELOG.md"
|
|
32
|
+
|
|
33
|
+
[project.scripts]
|
|
34
|
+
colsemantics = "colsemantics.cli:main"
|
|
27
35
|
|
|
28
36
|
[project.optional-dependencies]
|
|
29
|
-
dev = ["pytest>=
|
|
37
|
+
dev = ["pytest>=9.2.0", "pytest-cov>=7.1.0", "mypy>=2.4.1", "ruff>=0.17.4"]
|
|
30
38
|
|
|
31
39
|
[build-system]
|
|
32
|
-
requires = ["setuptools>=
|
|
40
|
+
requires = ["setuptools>=84.2.1"]
|
|
33
41
|
build-backend = "setuptools.build_meta"
|
|
34
42
|
|
|
35
43
|
[tool.setuptools.packages.find]
|
|
36
44
|
where = ["src"]
|
|
37
45
|
|
|
38
46
|
[tool.setuptools.package-data]
|
|
39
|
-
colsemantics = ["py.typed"]
|
|
47
|
+
colsemantics = ["py.typed", "calibration.json", "data/*.txt", "data/*.md"]
|
|
40
48
|
|
|
41
49
|
[tool.pytest.ini_options]
|
|
42
50
|
testpaths = ["tests"]
|
|
@@ -55,7 +63,17 @@ ignore = [
|
|
|
55
63
|
]
|
|
56
64
|
|
|
57
65
|
[tool.mypy]
|
|
58
|
-
python_version = "3.
|
|
66
|
+
python_version = "3.11"
|
|
59
67
|
files = ["src/colsemantics"]
|
|
60
68
|
ignore_missing_imports = true
|
|
61
69
|
warn_unused_ignores = true
|
|
70
|
+
strict = true
|
|
71
|
+
|
|
72
|
+
[tool.coverage.run]
|
|
73
|
+
source = ["colsemantics"]
|
|
74
|
+
branch = true
|
|
75
|
+
|
|
76
|
+
[tool.coverage.report]
|
|
77
|
+
fail_under = 90
|
|
78
|
+
show_missing = true
|
|
79
|
+
skip_covered = true
|