mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-10 05:42:12 +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
|
|
@ -18,7 +18,10 @@ from .... schema import PromptRequest, PromptResponse
|
|||
from .... rdf import TRUSTGRAPH_ENTITIES, DEFINITION, RDF_LABEL, SUBJECT_OF
|
||||
|
||||
from .... base import FlowProcessor, ConsumerSpec, ProducerSpec
|
||||
from .... base import PromptClientSpec
|
||||
from .... base import PromptClientSpec, ParameterSpec
|
||||
|
||||
from .... provenance import statement_uri, triple_provenance_triples
|
||||
from .... flow_version import __version__ as COMPONENT_VERSION
|
||||
|
||||
DEFINITION_VALUE = Term(type=IRI, iri=DEFINITION)
|
||||
RDF_LABEL_VALUE = Term(type=IRI, iri=RDF_LABEL)
|
||||
|
|
@ -75,6 +78,10 @@ class Processor(FlowProcessor):
|
|||
)
|
||||
)
|
||||
|
||||
# Optional flow parameters for provenance
|
||||
self.register_specification(ParameterSpec("llm-model"))
|
||||
self.register_specification(ParameterSpec("ontology"))
|
||||
|
||||
def to_uri(self, text):
|
||||
|
||||
part = text.replace(" ", "-").lower().encode("utf-8")
|
||||
|
|
@ -132,6 +139,10 @@ class Processor(FlowProcessor):
|
|||
chunk_doc_id = v.document_id if v.document_id else v.metadata.id
|
||||
chunk_uri = v.metadata.id # The URI form for the chunk
|
||||
|
||||
# Get optional provenance parameters
|
||||
llm_model = flow("llm-model")
|
||||
ontology_uri = flow("ontology")
|
||||
|
||||
# Note: Document metadata is now emitted once by librarian at processing
|
||||
# initiation, so we don't need to duplicate it here.
|
||||
|
||||
|
|
@ -157,9 +168,24 @@ class Processor(FlowProcessor):
|
|||
o=Term(type=LITERAL, value=s),
|
||||
))
|
||||
|
||||
triples.append(Triple(
|
||||
# The definition triple - this is the main extracted fact
|
||||
definition_triple = Triple(
|
||||
s=s_value, p=DEFINITION_VALUE, o=o_value
|
||||
))
|
||||
)
|
||||
triples.append(definition_triple)
|
||||
|
||||
# Generate provenance for the definition triple (reification)
|
||||
stmt_uri = statement_uri()
|
||||
prov_triples = triple_provenance_triples(
|
||||
stmt_uri=stmt_uri,
|
||||
extracted_triple=definition_triple,
|
||||
chunk_uri=chunk_uri,
|
||||
component_name=default_ident,
|
||||
component_version=COMPONENT_VERSION,
|
||||
llm_model=llm_model,
|
||||
ontology_uri=ontology_uri,
|
||||
)
|
||||
triples.extend(prov_triples)
|
||||
|
||||
# Link entity to chunk (not top-level document)
|
||||
triples.append(Triple(
|
||||
|
|
|
|||
|
|
@ -18,7 +18,10 @@ from .... schema import PromptRequest, PromptResponse
|
|||
from .... rdf import RDF_LABEL, TRUSTGRAPH_ENTITIES, SUBJECT_OF
|
||||
|
||||
from .... base import FlowProcessor, ConsumerSpec, ProducerSpec
|
||||
from .... base import PromptClientSpec
|
||||
from .... base import PromptClientSpec, ParameterSpec
|
||||
|
||||
from .... provenance import statement_uri, triple_provenance_triples
|
||||
from .... flow_version import __version__ as COMPONENT_VERSION
|
||||
|
||||
RDF_LABEL_VALUE = Term(type=IRI, iri=RDF_LABEL)
|
||||
SUBJECT_OF_VALUE = Term(type=IRI, iri=SUBJECT_OF)
|
||||
|
|
@ -65,6 +68,10 @@ class Processor(FlowProcessor):
|
|||
)
|
||||
)
|
||||
|
||||
# Optional flow parameters for provenance
|
||||
self.register_specification(ParameterSpec("llm-model"))
|
||||
self.register_specification(ParameterSpec("ontology"))
|
||||
|
||||
def to_uri(self, text):
|
||||
|
||||
part = text.replace(" ", "-").lower().encode("utf-8")
|
||||
|
|
@ -113,6 +120,10 @@ class Processor(FlowProcessor):
|
|||
chunk_doc_id = v.document_id if v.document_id else v.metadata.id
|
||||
chunk_uri = v.metadata.id # The URI form for the chunk
|
||||
|
||||
# Get optional provenance parameters
|
||||
llm_model = flow("llm-model")
|
||||
ontology_uri = flow("ontology")
|
||||
|
||||
# Note: Document metadata is now emitted once by librarian at processing
|
||||
# initiation, so we don't need to duplicate it here.
|
||||
|
||||
|
|
@ -142,11 +153,26 @@ class Processor(FlowProcessor):
|
|||
else:
|
||||
o_value = Term(type=LITERAL, value=str(o))
|
||||
|
||||
triples.append(Triple(
|
||||
# The relationship triple - this is the main extracted fact
|
||||
relationship_triple = Triple(
|
||||
s=s_value,
|
||||
p=p_value,
|
||||
o=o_value
|
||||
))
|
||||
)
|
||||
triples.append(relationship_triple)
|
||||
|
||||
# Generate provenance for the relationship triple (reification)
|
||||
stmt_uri = statement_uri()
|
||||
prov_triples = triple_provenance_triples(
|
||||
stmt_uri=stmt_uri,
|
||||
extracted_triple=relationship_triple,
|
||||
chunk_uri=chunk_uri,
|
||||
component_name=default_ident,
|
||||
component_version=COMPONENT_VERSION,
|
||||
llm_model=llm_model,
|
||||
ontology_uri=ontology_uri,
|
||||
)
|
||||
triples.extend(prov_triples)
|
||||
|
||||
# Label for s
|
||||
triples.append(Triple(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue