mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-26 00:46:22 +02:00
Fix/extraction prov (#662)
Quoted triple fixes, including...
1. Updated triple_provenance_triples() in triples.py:
- Now accepts a Triple object directly
- Creates the reification triple using TRIPLE term type: stmt_uri tg:reifies
<<extracted_triple>>
- Includes it in the returned provenance triples
2. Updated definitions extractor:
- Added imports for provenance functions and component version
- Added ParameterSpec for optional llm-model and ontology flow parameters
- For each definition triple, generates provenance with reification
3. Updated relationships extractor:
- Same changes as definitions extractor
This commit is contained in:
parent
cd5580be59
commit
2b9232917c
19 changed files with 361 additions and 72 deletions
|
|
@ -9,26 +9,45 @@ including LLM operations, RAG queries, knowledge graph management, and more.
|
|||
import json
|
||||
import base64
|
||||
|
||||
from .. knowledge import hash, Uri, Literal
|
||||
from .. schema import IRI, LITERAL
|
||||
from .. knowledge import hash, Uri, Literal, QuotedTriple
|
||||
from .. schema import IRI, LITERAL, TRIPLE
|
||||
from . types import Triple
|
||||
from . exceptions import ProtocolException
|
||||
|
||||
|
||||
def to_value(x):
|
||||
"""Convert wire format to Uri or Literal."""
|
||||
"""Convert wire format to Uri, Literal, or QuotedTriple."""
|
||||
if x.get("t") == IRI:
|
||||
return Uri(x.get("i", ""))
|
||||
elif x.get("t") == LITERAL:
|
||||
return Literal(x.get("v", ""))
|
||||
elif x.get("t") == TRIPLE:
|
||||
# Wire format uses "tr" key for nested triple dict
|
||||
triple_data = x.get("tr")
|
||||
if triple_data:
|
||||
return QuotedTriple(
|
||||
s=to_value(triple_data.get("s", {})),
|
||||
p=to_value(triple_data.get("p", {})),
|
||||
o=to_value(triple_data.get("o", {})),
|
||||
)
|
||||
return Literal("")
|
||||
# Fallback for any other type
|
||||
return Literal(x.get("v", x.get("i", "")))
|
||||
|
||||
|
||||
def from_value(v):
|
||||
"""Convert Uri or Literal to wire format."""
|
||||
"""Convert Uri, Literal, or QuotedTriple to wire format."""
|
||||
if isinstance(v, Uri):
|
||||
return {"t": IRI, "i": str(v)}
|
||||
elif isinstance(v, QuotedTriple):
|
||||
return {
|
||||
"t": TRIPLE,
|
||||
"tr": {
|
||||
"s": from_value(v.s),
|
||||
"p": from_value(v.p),
|
||||
"o": from_value(v.o),
|
||||
}
|
||||
}
|
||||
else:
|
||||
return {"t": LITERAL, "v": str(v)}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,17 +9,27 @@ into flows for use in queries and RAG operations.
|
|||
import json
|
||||
import base64
|
||||
|
||||
from .. knowledge import hash, Uri, Literal
|
||||
from .. schema import IRI, LITERAL
|
||||
from .. knowledge import hash, Uri, Literal, QuotedTriple
|
||||
from .. schema import IRI, LITERAL, TRIPLE
|
||||
from . types import Triple
|
||||
|
||||
|
||||
def to_value(x):
|
||||
"""Convert wire format to Uri or Literal."""
|
||||
"""Convert wire format to Uri, Literal, or QuotedTriple."""
|
||||
if x.get("t") == IRI:
|
||||
return Uri(x.get("i", ""))
|
||||
elif x.get("t") == LITERAL:
|
||||
return Literal(x.get("v", ""))
|
||||
elif x.get("t") == TRIPLE:
|
||||
# Wire format uses "tr" key for nested triple dict
|
||||
triple_data = x.get("tr")
|
||||
if triple_data:
|
||||
return QuotedTriple(
|
||||
s=to_value(triple_data.get("s", {})),
|
||||
p=to_value(triple_data.get("p", {})),
|
||||
o=to_value(triple_data.get("o", {})),
|
||||
)
|
||||
return Literal("")
|
||||
# Fallback for any other type
|
||||
return Literal(x.get("v", x.get("i", "")))
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ import base64
|
|||
import logging
|
||||
|
||||
from . types import DocumentMetadata, ProcessingMetadata, Triple
|
||||
from .. knowledge import hash, Uri, Literal
|
||||
from .. schema import IRI, LITERAL
|
||||
from .. knowledge import hash, Uri, Literal, QuotedTriple
|
||||
from .. schema import IRI, LITERAL, TRIPLE
|
||||
from . exceptions import *
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -27,19 +27,38 @@ DEFAULT_CHUNK_SIZE = 5 * 1024 * 1024
|
|||
|
||||
|
||||
def to_value(x):
|
||||
"""Convert wire format to Uri or Literal."""
|
||||
"""Convert wire format to Uri, Literal, or QuotedTriple."""
|
||||
if x.get("t") == IRI:
|
||||
return Uri(x.get("i", ""))
|
||||
elif x.get("t") == LITERAL:
|
||||
return Literal(x.get("v", ""))
|
||||
elif x.get("t") == TRIPLE:
|
||||
# Wire format uses "tr" key for nested triple dict
|
||||
triple_data = x.get("tr")
|
||||
if triple_data:
|
||||
return QuotedTriple(
|
||||
s=to_value(triple_data.get("s", {})),
|
||||
p=to_value(triple_data.get("p", {})),
|
||||
o=to_value(triple_data.get("o", {})),
|
||||
)
|
||||
return Literal("")
|
||||
# Fallback for any other type
|
||||
return Literal(x.get("v", x.get("i", "")))
|
||||
|
||||
|
||||
def from_value(v):
|
||||
"""Convert Uri or Literal to wire format."""
|
||||
"""Convert Uri, Literal, or QuotedTriple to wire format."""
|
||||
if isinstance(v, Uri):
|
||||
return {"t": IRI, "i": str(v)}
|
||||
elif isinstance(v, QuotedTriple):
|
||||
return {
|
||||
"t": TRIPLE,
|
||||
"tr": {
|
||||
"s": from_value(v.s),
|
||||
"p": from_value(v.p),
|
||||
"o": from_value(v.o),
|
||||
}
|
||||
}
|
||||
else:
|
||||
return {"t": LITERAL, "v": str(v)}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue