Skip to main content

Classful Ontology for Life-Events Information Extraction

Project description

infoextract-cidoc (COLLIE)

Classful Ontology for Life-Events Information Extraction

Python 3.13+ License: MIT Code style: ruff Tests Package: uv CIDOC CRM Pydantic Neo4j Compatible Memgraph Compatible

COLLIE logo

A developer-friendly toolkit for working with the CIDOC CRM v7.1.3 in modern data workflows. infoextract-cidoc provides complete Pydantic models (99 classes, 322 properties), LangStruct-powered AI extraction, Markdown renderers, and Cypher emitters that bridge the gap between conceptual rigor and developer usability.

Why infoextract-cidoc?

Cultural heritage and information extraction projects often need a CRM-compliant backbone without the overhead of RDF stacks. infoextract-cidoc:

  • Keeps the conceptual rigor of CIDOC CRM
  • Provides lean, open-world Pydantic validation
  • Outputs formats directly usable by LLMs (Markdown) and LPGs (Cypher)
  • Prioritizes ergonomics and performance for real-world extraction pipelines
  • Zero RDF/OWL/JSON-LD dependencies

Quick Start

For a comprehensive getting started guide, see QUICKSTART.md

Installation

pip install infoextract-cidoc

# With GraphForge graph database integration:
pip install infoextract-cidoc[graphforge]

# Using uv:
uv add infoextract-cidoc

AI Extraction (New Pipeline)

from infoextract_cidoc.extraction import LangStructExtractor, resolve_extraction, map_to_crm_entities
from infoextract_cidoc.io.to_markdown import to_markdown, MarkdownStyle

# Extract from text (set GOOGLE_API_KEY or LANGSTRUCT_DEFAULT_MODEL env var)
extractor = LangStructExtractor()
lite_result = extractor.extract(
    "Albert Einstein was born on March 14, 1879, in Ulm, Germany. "
    "He won the Nobel Prize in Physics in 1921."
)

# Resolve to stable UUIDs
extraction_result = resolve_extraction(lite_result)

# Map to CIDOC CRM entities
crm_entities, crm_relations = map_to_crm_entities(extraction_result)

# Render to Markdown
for entity in crm_entities:
    print(to_markdown(entity, MarkdownStyle.CARD))

CRM Models (No AI Needed)

from infoextract_cidoc.models.generated.e_classes import EE22_HumanMadeObject
from infoextract_cidoc.io.to_markdown import to_markdown, MarkdownStyle
from infoextract_cidoc.io.to_cypher import generate_cypher_script

# Create a CRM entity (string IDs are automatically converted to UUIDs)
vase = EE22_HumanMadeObject(
    id="obj_001",
    label="Ancient Greek Vase",
    type=["E55:Vessel", "E55:Ceramic"]
)

# Render as Markdown
markdown = to_markdown(vase, MarkdownStyle.CARD)

# Generate Cypher for Neo4j/Memgraph
cypher = generate_cypher_script([vase])

CLI

# Extract entities from text
infoextract-cidoc extract --text "Marie Curie was born in Warsaw in 1867."

# Extract from file
infoextract-cidoc extract --file biography.txt --output ./output/

# Run complete workflow
infoextract-cidoc workflow --file biography.txt --all --output results/

# Run Einstein demo
infoextract-cidoc demo --einstein

Core Features

AI-Powered Information Extraction

  • LangStruct pipeline for single-pass entity and relationship extraction
  • Entity Resolution with stable UUID5 identifiers and deduplication
  • Relationship Resolution with broken link detection and logging
  • CRM Mapping to E21 Person, E5 Event, E53 Place, E22 Object, E52 Time-Span
  • DSPy optimization support for fine-tuning extraction quality
  • Works with any LiteLLM-compatible model (Gemini, OpenAI, Anthropic, etc.)

Pydantic Models

  • Complete CIDOC CRM v7.1.3 coverage (99 E-classes, 322 P-properties)
  • Flexible UUID handling with automatic string-to-UUID conversion
  • Canonical JSON schema with stable IDs and explicit cross-references
  • Auto-generated from curated YAML specifications

Class Naming Convention

  • Official CIDOC CRM: E1, E22, E96 (class codes)
  • Python Classes: EE1_CRMEntity, EE22_HumanMadeObject, EE96_Purchase
  • Pattern: E{code}_{label_without_spaces}

Markdown Renderers

  • Entity Cards: Concise summaries optimized for LLM prompts
  • Detailed Narratives: Rich descriptions with full context
  • Tabular Summaries: Structured data presentation

NetworkX Integration

  • Direct conversion from CRM entities to NetworkX graphs
  • Built-in social network analysis (centrality, communities)
  • Temporal network analysis for historical data

Output Formats

  • Markdown (4 styles): entity cards, detailed, tabular, narrative
  • Cypher: idempotent MERGE/UNWIND scripts for Neo4j/Memgraph
  • NetworkX: graph objects for programmatic analysis
  • GraphForge (optional): pip install infoextract-cidoc[graphforge]

Validation Framework

  • Cardinality enforcement (configurable from warnings to strict)
  • Type alignment validation
  • Extensible validation profiles

Complete Workflow

from infoextract_cidoc.extraction import LangStructExtractor, resolve_extraction, map_to_crm_entities
from infoextract_cidoc.io.to_networkx import to_networkx_graph
from infoextract_cidoc.io.to_cypher import generate_cypher_script
from infoextract_cidoc.visualization import plot_network_graph

# 1. Extract entities via LangStruct
extractor = LangStructExtractor()
lite_result = await extractor.extract_async("""
Albert Einstein was born on March 14, 1879, in Ulm, Germany.
He developed the theory of relativity and won the Nobel Prize in 1921.
""")

# 2. Resolve and map to CRM
extraction_result = resolve_extraction(lite_result)
crm_entities, crm_relations = map_to_crm_entities(extraction_result)

# 3. Serialize as canonical JSON
json_data = [entity.model_dump(mode='json') for entity in crm_entities]

# 4. Convert to NetworkX graph for social network analysis
graph = to_networkx_graph(crm_entities)

# 5. Visualize the network
plot_network_graph(graph, title="Einstein's Life Network")

# 6. Export to Cypher for graph database persistence
cypher_script = generate_cypher_script(crm_entities)

Project Structure

src/infoextract_cidoc/
├── extraction/           # AI extraction pipeline
│   ├── lite_schema.py   # LangStruct output schema
│   ├── resolution.py    # Entity/relationship resolution
│   ├── crm_mapper.py    # CRM mapping layer
│   └── langstruct_extractor.py  # LangStructExtractor
├── models/               # Pydantic CRM models
│   ├── base.py          # CRMEntity, CRMRelation
│   └── generated/       # Auto-generated E-classes (99)
├── io/                   # Output modules
│   ├── to_markdown.py   # Markdown renderers
│   ├── to_cypher.py     # Cypher emitters
│   ├── to_networkx/     # NetworkX conversion
│   └── to_graphforge.py # GraphForge (optional)
├── validators/           # Validation framework
├── visualization/        # matplotlib/plotly plots
├── codegen/              # YAML -> Pydantic generation
└── tests/                # Test suite (77 tests)

Testing

make test           # Run all tests
make test-unit      # Unit tests only
make coverage       # With coverage report
make pre-push       # Full CI: lint + type-check + security + coverage

Documentation

Project Status

  • Phase 1: Complete - Core CIDOC CRM implementation
  • Phase 2: Complete - LangStruct extraction pipeline, validation, full CRM coverage
  • Phase 3: Planned - Profile packs and additional analysis tools

Current Coverage: 99 E-classes, 322 P-properties (complete CRM 7.1.3) Test Status: 77 tests passing (100% success rate) CI/CD: GitHub Actions with uv, ruff, mypy, bandit, codecov

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • CIDOC CRM Working Group for the foundational ontology
  • Pydantic team for the excellent validation framework
  • Neo4j community for Cypher language inspiration

Made with care for the cultural heritage and information extraction community

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

infoextract_cidoc-0.1.0.tar.gz (6.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

infoextract_cidoc-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file infoextract_cidoc-0.1.0.tar.gz.

File metadata

  • Download URL: infoextract_cidoc-0.1.0.tar.gz
  • Upload date:
  • Size: 6.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for infoextract_cidoc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6f4396c42837e0ccafb9a798401b7f270555b71c97652d5ef85363641f8d3d37
MD5 7196d2e14e0ea3dd6558b56940ceb059
BLAKE2b-256 736b2da77a35ad69ad68431d7fc0c945ffe7720a42e8c212e0a0e6e0dd18a8bc

See more details on using hashes here.

File details

Details for the file infoextract_cidoc-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: infoextract_cidoc-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for infoextract_cidoc-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7dad38c4f52a7ac51964aa963f8ba5bb9a2d7e1faeda45653d5261f91c7c5e6d
MD5 ec8f26baf4d0b9ff09d0c6acf1aa7ec2
BLAKE2b-256 8e4a03b8921e17757008f8c9b3f6f0b6c39c3b0692be8be0278a910370f8ae96

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page