ontocast.onto
¶
AgentState
¶
Bases: BasePydanticModel
State for the ontology-based knowledge graph agent.
This class maintains the state of the agent during document processing, including input text, chunks, ontologies, and workflow status.
Attributes:
Name | Type | Description |
---|---|---|
input_text |
str
|
Input text to process. |
current_domain |
str
|
IRI used for forming document namespace. |
doc_hid |
Optional[str]
|
An almost unique hash/id for the parent document. |
files |
dict[str, bytes]
|
Files to process. |
current_chunk |
Optional[Chunk]
|
Current document chunk for processing. |
chunks |
list[Chunk]
|
List of chunks of the input text. |
chunks_processed |
list[Chunk]
|
List of processed chunks. |
current_ontology |
Ontology
|
Current ontology object. |
ontology_addendum |
Ontology
|
Additional ontology content. |
failure_stage |
Optional[str]
|
Stage where failure occurred. |
failure_reason |
Optional[str]
|
Reason for failure. |
success_score |
Optional[float]
|
Score indicating success level. |
status |
Status
|
Current workflow status. |
node_visits |
defaultdict[WorkflowNode, int]
|
Number of visits per node. |
max_visits |
int
|
Maximum number of visits allowed per node. |
max_chunks |
Optional[int]
|
Maximum number of chunks to process. |
Source code in ontocast/onto.py
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 |
|
doc_iri
property
¶
Get the document IRI.
Returns:
Name | Type | Description |
---|---|---|
str |
The document IRI. |
doc_namespace
property
¶
Get the document namespace.
Returns:
Name | Type | Description |
---|---|---|
str |
The document namespace. |
__init__(**kwargs)
¶
clear_failure()
¶
model_post_init(__context)
¶
set_failure(stage, reason, success_score=0.0)
¶
Set failure state with stage and reason.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stage
|
str
|
The stage where the failure occurred. |
required |
reason
|
str
|
The reason for the failure. |
required |
success_score
|
float
|
The success score at failure (default: 0.0). |
0.0
|
Source code in ontocast/onto.py
set_text(text)
¶
Set the input text and generate document hash.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
The input text to set. |
required |
BasePydanticModel
¶
Bases: BaseModel
Base class for Pydantic models with serialization capabilities.
Source code in ontocast/onto.py
__init__(**kwargs)
¶
load(file_path)
classmethod
¶
Load state from a JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str | Path
|
Path to the JSON file. |
required |
Returns:
Type | Description |
---|---|
The loaded model instance. |
Source code in ontocast/onto.py
serialize(file_path)
¶
Serialize the state to a JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str | Path
|
Path to save the JSON file. |
required |
Source code in ontocast/onto.py
Chunk
¶
Bases: BaseModel
A chunk of text with associated metadata and RDF graph.
Attributes:
Name | Type | Description |
---|---|---|
text |
str
|
Text content of the chunk. |
hid |
str
|
An almost unique (hash) id for the chunk. |
doc_iri |
str
|
IRI of parent document. |
graph |
Optional[RDFGraph]
|
RDF triples representing the facts from the current document. |
processed |
bool
|
Whether chunk has been processed. |
Source code in ontocast/onto.py
FailureStages
¶
Bases: StrEnum
Enumeration of possible failure stages in the workflow.
Source code in ontocast/onto.py
KGCritiqueReport
¶
Bases: BaseModel
Report from knowledge graph critique process.
Attributes:
Name | Type | Description |
---|---|---|
facts_graph_derivation_success |
bool
|
True if the facts graph derivation was performed successfully, False otherwise. |
facts_graph_derivation_score |
float
|
Score 0-100 for how well the triples of facts represent the original document. |
facts_graph_derivation_critique_comment |
Optional[str]
|
A concrete explanation of why the semantic graph of facts derivation is not satisfactory. |
Source code in ontocast/onto.py
Ontology
¶
Bases: OntologyProperties
A Pydantic model representing an ontology with its RDF graph and description.
Attributes:
Name | Type | Description |
---|---|---|
graph |
RDFGraph
|
The RDF graph containing the ontology data. |
Source code in ontocast/onto.py
__iadd__(other)
¶
In-place addition operator for Ontology instances.
Merges the RDF graphs and takes properties from the right-hand operand.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Union[Ontology, RDFGraph]
|
The ontology or graph to add to this one. |
required |
Returns:
Name | Type | Description |
---|---|---|
Ontology |
Ontology
|
self after modification. |
Source code in ontocast/onto.py
describe()
¶
Get a human-readable description of the ontology.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A formatted description string. |
Source code in ontocast/onto.py
from_file(file_path, format='turtle', **kwargs)
classmethod
¶
Create an Ontology instance by loading a graph from a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
Path
|
Path to the ontology file. |
required |
format
|
str
|
Format of the input file (default: "turtle"). |
'turtle'
|
**kwargs
|
Additional arguments to pass to the constructor. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Ontology |
A new Ontology instance. |
Source code in ontocast/onto.py
set_properties(**kwargs)
¶
Set ontology properties from keyword arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Property values to set. |
{}
|
OntologyProperties
¶
Bases: BaseModel
Properties of an ontology.
Attributes:
Name | Type | Description |
---|---|---|
short_name |
Optional[str]
|
A short name (identifier) for the ontology. |
title |
Optional[str]
|
Ontology title. |
description |
Optional[str]
|
A concise description of the ontology. |
version |
Optional[str]
|
Version of the ontology. |
iri |
Optional[str]
|
Ontology IRI (Internationalized Resource Identifier). |
Source code in ontocast/onto.py
namespace
property
¶
Get the namespace for this ontology.
Returns:
Name | Type | Description |
---|---|---|
str |
The namespace string. |
OntologySelectorReport
¶
Bases: BasePydanticModel
Report from ontology selection process.
Attributes:
Name | Type | Description |
---|---|---|
short_name |
Optional[str]
|
A short name (identifier) for the ontology that could be used to represent the domain of the document, None if no ontology is suitable. |
present |
bool
|
Whether an ontology that could represent the domain of the document is present in the list of ontologies. |
Source code in ontocast/onto.py
OntologyUpdateCritiqueReport
¶
Bases: BaseModel
Report from ontology update critique process.
Attributes:
Name | Type | Description |
---|---|---|
ontology_update_success |
bool
|
True if the ontology update was performed successfully, False otherwise. |
ontology_update_score |
float
|
Score 0-100 for how well the update improves the original domain ontology of the document. |
ontology_update_critique_comment |
Optional[str]
|
A concrete explanation of why the ontology update is not satisfactory. |
Source code in ontocast/onto.py
RDFGraph
¶
Bases: Graph
Subclass of rdflib.Graph with Pydantic schema support.
This class extends rdflib.Graph to provide serialization and deserialization capabilities for Pydantic models, with special handling for Turtle format.
Source code in ontocast/onto.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
|
__add__(other)
¶
Addition operator for RDFGraph instances.
Merges the RDF graphs while maintaining the RDFGraph type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Union[RDFGraph, Graph]
|
The graph to add to this one. |
required |
Returns:
Name | Type | Description |
---|---|---|
RDFGraph |
RDFGraph
|
A new RDFGraph containing the merged triples. |
Source code in ontocast/onto.py
__get_pydantic_core_schema__(_source_type, handler)
classmethod
¶
Get the Pydantic core schema for this class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
_source_type
|
The source type. |
required | |
handler
|
GetCoreSchemaHandler
|
The core schema handler. |
required |
Returns:
Type | Description |
---|---|
A union schema that handles both Graph instances and string conversion. |
Source code in ontocast/onto.py
__iadd__(other)
¶
In-place addition operator for RDFGraph instances.
Merges the RDF graphs while maintaining the RDFGraph type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Union[RDFGraph, Graph]
|
The graph to add to this one. |
required |
Returns:
Name | Type | Description |
---|---|---|
RDFGraph |
RDFGraph
|
self after modification. |
Source code in ontocast/onto.py
__new__(*args, **kwargs)
¶
sanitize_prefixes_namespaces()
¶
Rematches prefixes in an RDFLib graph to correct namespaces when a namespace with the same URI exists. Handles cases where prefixes might not be bound as namespaces.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self
|
RDFGraph
|
The RDFLib graph to process |
required |
Returns:
Name | Type | Description |
---|---|---|
RDFGraph |
The graph with corrected prefix-namespace mappings |
Source code in ontocast/onto.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
|
unbind_chunk_namespaces(chunk_pattern='/chunk/')
¶
Unbinds namespace prefixes that point to URIs containing a chunk pattern. Returns a new graph with chunk namespaces dereferenced (expanded to full URIs).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chunk_pattern
|
str
|
The pattern to look for in URIs (default: "/chunk/") |
'/chunk/'
|
Returns:
Name | Type | Description |
---|---|---|
RDFGraph |
RDFGraph
|
New graph with chunk-related namespaces unbound |
Source code in ontocast/onto.py
SemanticTriplesFactsReport
¶
Bases: BaseModel
Report containing semantic triples and evaluation scores.
Attributes:
Name | Type | Description |
---|---|---|
semantic_graph |
RDFGraph
|
Semantic triples (facts) representing the document in turtle (ttl) format. |
ontology_relevance_score |
Optional[float]
|
Score 0-100 for how relevant the ontology is to the document. 0 is the worst, 100 is the best. |
triples_generation_score |
Optional[float]
|
Score 0-100 for how well the facts extraction / triples generation was performed. 0 is the worst, 100 is the best. |
Source code in ontocast/onto.py
Status
¶
ToolType
¶
Bases: StrEnum
Enumeration of tool types used in the workflow.
Source code in ontocast/onto.py
WorkflowNode
¶
Bases: StrEnum
Enumeration of workflow nodes in the processing pipeline.
Source code in ontocast/onto.py
iri2namespace(iri, ontology=False)
¶
Convert an IRI to a namespace string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iri
|
str
|
The IRI to convert. |
required |
ontology
|
bool
|
If True, append '#' for ontology namespace, otherwise '/'. |
False
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The converted namespace string. |