mirror of
https://github.com/semantica-agi/semantica.git
synced 2026-08-29 04:26:20 +00:00
* docs(cookbook): add Seed Data module notebook Add cookbook/introduction/25_Seed_Data.ipynb covering the seed module with verified, executable examples: - SeedDataManager.register_source with a CSV source - load_source record enrichment (entity_type/source provenance) - create_foundation_graph entity/relationship/metadata structure - validate_quality gating The seed module ships seed_usage.md but has no cookbook coverage. All API calls and outputs were executed against semantica/seed/seed_manager.py. Signed-off-by: LeonSGP43 <LeonSGP43@users.noreply.github.com> * docs(cookbook): isolate seed CSV in a temp dir and execute notebook in Jupyter - Write companies.csv into a session-scoped tempfile.mkdtemp() directory instead of the working directory, so a user's existing companies.csv can never be silently clobbered (review finding) - Run the notebook through a fresh Jupyter kernel (restart + run all + save): real execution counts, print() cells saved as stream outputs Signed-off-by: LeonSGP43 <cine.dreamer.one@gmail.com> --------- Signed-off-by: LeonSGP43 <LeonSGP43@users.noreply.github.com> Signed-off-by: LeonSGP43 <cine.dreamer.one@gmail.com> Co-authored-by: LeonSGP43 <LeonSGP43@users.noreply.github.com>
9.3 KiB
9.3 KiB
In [1]:
!pip install -q semanticaIn [2]:
import csv
import tempfile
from pathlib import Path
from semantica.seed import SeedDataManager
# Write the sample CSV into a session-scoped temp directory so we never
# clobber a companies.csv that might exist in the user's working directory.
seed_csv = Path(tempfile.mkdtemp(prefix="semantica-seed-")) / "companies.csv"
with open(seed_csv, "w", newline="") as f:
writer = csv.DictWriter(f, fieldnames=["id", "name", "type", "industry"])
writer.writeheader()
writer.writerow({"id": "c1", "name": "Acme", "type": "Company", "industry": "robotics"})
writer.writerow({"id": "c2", "name": "Globex", "type": "Company", "industry": "energy"})
manager = SeedDataManager()
manager.register_source("companies", format="csv", location=str(seed_csv), entity_type="Company")
Out [2]:
True
In [3]:
records = manager.load_source("companies")
print(f"loaded {len(records)} records")
records[0]Out [3]:
🧠 Semantica - 📊 Current Progress
| Status | Action | Module | Submodule | Progress | ETA | Rate | Time | Extracted |
|---|---|---|---|---|---|---|---|---|
| ✅ | Semantica is seeding | 🌱 seed | SeedDataManager | 100.0% | - | - | 0.00s | - |
🔄 Semantica is seeding: Loading seed data from CSV: /var/folders/7s/bvvstgs10y963tz6_4bbnklr0000gn/T/semantica-seed-eu9__ep1/companies.csv 🌱 seed SeedDataManager |░░░░░░░░░░░░░░░| 0.0% ETA: - Rate: - Time: 0.00s Extracted: -
loaded 2 records
{'id': 'c1',
'name': 'Acme',
'type': 'Company',
'industry': 'robotics',
'entity_type': 'Company',
'source': 'companies'}In [4]:
foundation = manager.create_foundation_graph()
sorted(foundation.keys())Out [4]:
['entities', 'metadata', 'relationships']
In [5]:
foundation["entities"][0]Out [5]:
{'id': 'c1',
'text': 'Acme',
'type': 'Company',
'confidence': 1.0,
'metadata': {'industry': 'robotics', 'source': 'companies'}}In [6]:
quality = manager.validate_quality(foundation)
quality["valid"]Out [6]:
True