mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-23 04:01:02 +02:00
Fix doc IRIs
This commit is contained in:
parent
cd5580be59
commit
7527bd787b
1 changed files with 17 additions and 16 deletions
|
|
@ -1,11 +1,12 @@
|
||||||
"""
|
"""
|
||||||
URI generation for provenance entities.
|
URI generation for provenance entities.
|
||||||
|
|
||||||
URI patterns:
|
Document IDs are already IRIs (e.g., https://trustgraph.ai/doc/abc123).
|
||||||
- Document: https://trustgraph.ai/doc/{doc_id}
|
Child entities (pages, chunks) append path segments to the parent IRI:
|
||||||
- Page: https://trustgraph.ai/page/{doc_id}/p{page_number}
|
- Document: {doc_iri} (as provided)
|
||||||
- Chunk: https://trustgraph.ai/chunk/{doc_id}/p{page}/c{chunk} (from page)
|
- Page: {doc_iri}/p{page_number}
|
||||||
https://trustgraph.ai/chunk/{doc_id}/c{chunk} (from text doc)
|
- Chunk: {page_iri}/c{chunk_index} (from page)
|
||||||
|
{doc_iri}/c{chunk_index} (from text doc)
|
||||||
- Activity: https://trustgraph.ai/activity/{uuid}
|
- Activity: https://trustgraph.ai/activity/{uuid}
|
||||||
- Statement: https://trustgraph.ai/stmt/{uuid}
|
- Statement: https://trustgraph.ai/stmt/{uuid}
|
||||||
"""
|
"""
|
||||||
|
|
@ -13,7 +14,7 @@ URI patterns:
|
||||||
import uuid
|
import uuid
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
# Base URI prefix
|
# Base URI prefix for generated URIs (activities, statements, agents)
|
||||||
TRUSTGRAPH_BASE = "https://trustgraph.ai"
|
TRUSTGRAPH_BASE = "https://trustgraph.ai"
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -22,24 +23,24 @@ def _encode_id(id_str: str) -> str:
|
||||||
return urllib.parse.quote(str(id_str), safe='')
|
return urllib.parse.quote(str(id_str), safe='')
|
||||||
|
|
||||||
|
|
||||||
def document_uri(doc_id: str) -> str:
|
def document_uri(doc_iri: str) -> str:
|
||||||
"""Generate URI for a source document."""
|
"""Return the document IRI as-is (already a full URI)."""
|
||||||
return f"{TRUSTGRAPH_BASE}/doc/{_encode_id(doc_id)}"
|
return doc_iri
|
||||||
|
|
||||||
|
|
||||||
def page_uri(doc_id: str, page_number: int) -> str:
|
def page_uri(doc_iri: str, page_number: int) -> str:
|
||||||
"""Generate URI for a page extracted from a document."""
|
"""Generate URI for a page by appending to document IRI."""
|
||||||
return f"{TRUSTGRAPH_BASE}/page/{_encode_id(doc_id)}/p{page_number}"
|
return f"{doc_iri}/p{page_number}"
|
||||||
|
|
||||||
|
|
||||||
def chunk_uri_from_page(doc_id: str, page_number: int, chunk_index: int) -> str:
|
def chunk_uri_from_page(doc_iri: str, page_number: int, chunk_index: int) -> str:
|
||||||
"""Generate URI for a chunk extracted from a page."""
|
"""Generate URI for a chunk extracted from a page."""
|
||||||
return f"{TRUSTGRAPH_BASE}/chunk/{_encode_id(doc_id)}/p{page_number}/c{chunk_index}"
|
return f"{doc_iri}/p{page_number}/c{chunk_index}"
|
||||||
|
|
||||||
|
|
||||||
def chunk_uri_from_doc(doc_id: str, chunk_index: int) -> str:
|
def chunk_uri_from_doc(doc_iri: str, chunk_index: int) -> str:
|
||||||
"""Generate URI for a chunk extracted directly from a text document."""
|
"""Generate URI for a chunk extracted directly from a text document."""
|
||||||
return f"{TRUSTGRAPH_BASE}/chunk/{_encode_id(doc_id)}/c{chunk_index}"
|
return f"{doc_iri}/c{chunk_index}"
|
||||||
|
|
||||||
|
|
||||||
def activity_uri(activity_id: str = None) -> str:
|
def activity_uri(activity_id: str = None) -> str:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue