Skip to main content

Reuse-first, domain-agnostic natural language parse module producing validated semantic frames.

Project description

contlex

v1 | 2026-05-14 | contlex reuse-first domain-agnostic natural language parse module

contlex is a small, reuse-first, domain-agnostic Python package that turns natural language into a validated semantic frame. It does not decide, route, execute, mutate, or expose tools.

natural language
  → structured semantic frame
  → schema validation
  → consistency checks
  → evaluation
  → future adapters (Cont shadow, RAG_main query mock, …)

Positioning

  • Cont ve RAG_main'den beslenen, ama ikisinden bağımsız çalışan parse paketi.
  • Runtime bağımlılığı yok: Cont yürütmesi ya da KOSGEB karar grafı değişmez.
  • domain alanı yoktur. Domain-specific parser yoktur.

v1 Başarı Kriteri

Her şeyi anlamak değil — anlamadığını işaretlemek ve anlam eklememek.

Kurulum

pip install -e .
# isteğe bağlı parser back-end (v1 default'unda yok):
pip install -e ".[llm]"   # instructor tabanlı LLM yolu
pip install -e ".[local]" # outlines tabanlı local model yolu
pip install -e ".[dev]"   # pytest

Prompt ile Hızlı Test

Varsayılan komut dependency-free heuristic baseline parser kullanır. Bu üretim parser'ı değildir; offline smoke test ve regression kontrolü içindir.

python3 -m contlex "Şu raporu silme" --issues

Beklenen sonuç: JSON semantic frame basılır; modality değeri prohibition, polarity değeri negative olur ve temiz örnekte issues: [] görünür.

Kurulum sonrası aynı komut script olarak da çalışır:

contlex "Şunu kaydet" --issues

Bu örnekte eksik referans nedeniyle needs_clarification: true ve missing_referent ambiguity beklenir.

Gerçek parser yolu, contlex'in structured contract'ını bir backend'e verip dönen JSON'u doğrulamaktır:

contlex "bütün sistemdeki jpg dosyalarını listele" --print-contract
contlex "bütün sistemdeki jpg dosyalarını listele" \
  --backend-command "your-parser-command" \
  --issues

your-parser-command stdin'den contract prompt'u almalı, stdout'a yalnızca semantic-frame JSON yazmalıdır. contlex sonra parse_frame ve consistency checks çalıştırır.

JSON ile Hızlı Kullanım

from contlex import parse_frame, parse_prompt, run_consistency_checks

frame = parse_prompt("Şu raporu silme")
print(frame.model_dump())

frame = parse_frame({
    "raw_text": "şu raporu silme",
    "canonical_text": "şu raporu silme",
    "language": "tr",
    "modality": "prohibition",
    "polarity": "negative",
    "slots": [
        {"key": "action", "value": "silme",
         "source_text": "silme", "confidence": "high"},
        {"key": "object", "value": "şu rapor",
         "source_text": "şu raporu", "confidence": "medium"},
    ],
    "missing_slots": [],
    "ambiguities": [
        {"type": "missing_referent",
         "where": "şu rapor",
         "reason": "referent belirsiz"}
    ],
    "needs_clarification": True,
    "confidence": "medium",
})

issues = run_consistency_checks(frame)
assert issues == []

Paket Yapısı

contlex/
  schema.py          # Pydantic semantic frame model
  contract.py        # external parser backend prompt/schema contract
  parser.py          # dependency-free heuristic baseline
  validator.py       # parse_frame, structural validation
  consistency.py     # 7 deterministic cross-field checks
  eval.py            # fixture-based metric harness
  adapters/
    cont_shadow_mock.py  # Cont mock adapter
    rag_query_mock.py    # RAG_main mock adapter

Reuse-First Karar

Yeni bir NLU framework icat etmiyoruz. contlex v1 ilk olarak:

  • Pydantic v2 — frame modeli ve extra="forbid" ile strict validation
  • instructor (opsiyonel) — LLM structured output + Pydantic retry
  • outlines (opsiyonel) — local model için constrained generation

Rasa, spaCy Turkish, Stanza, Zemberek v1 fallback / helper aday listesindedir ama runtime bağımlılığı olarak getirilmez. Detay için docs/specs/contlex_reuse_research.md.

Non-Goals (v1)

  • Domain-specific parser yok.
  • Schema'da domain alanı yok.
  • Cont runtime değişikliği yok.
  • RAG_main / KOSGEB karar graph bağlantısı yok.
  • Tool routing yok.
  • Execution / write / delete / browser / shell davranışı yok.
  • Custom model training yok.
  • Yeni agent mimarisi yok.

Test

pytest

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

contlex-0.1.0.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

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

contlex-0.1.0-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: contlex-0.1.0.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for contlex-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4423ba2d55b0e54d5e78ee47914824c5820f6ec4f5e2bafb2047ba97b34666d5
MD5 9112d4989c016413a983d3ed57e474fd
BLAKE2b-256 480d39364c25243efdf95a91035f6e2ec4bc74017a12d3a176f2856b88860f5e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: contlex-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for contlex-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5186e5147d394d7d6c2fb63b750f36964e3ef7571cd566e05cf8c648e065fede
MD5 13af5425e9025802b65dc6a89067ec28
BLAKE2b-256 183a255786ae59c227b989f32f39874c510d62f635152a84c0bea4166e2d75aa

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