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
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 |
|
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. |
current_domain |
str
|
The domain used to construct the ontology IRI if ontology_id is set. |
Source code in ontocast/onto.py
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 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 |
|
__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 and sync to graph. Only update properties if they are missing (None or empty). Also enforces ontology_id/iri consistency as in init, but only if graph does not provide a valid pair.
Source code in ontocast/onto.py
sync_properties_from_graph()
¶
Update Ontology properties from the RDF graph if present, but only if missing, and only for entities explicitly typed as owl:Ontology. Optimized to avoid multiple loops over triples.
Source code in ontocast/onto.py
sync_properties_to_graph()
¶
Update the RDF graph with the Ontology's properties. Only sync properties for the entity that is explicitly typed as owl:Ontology. Only add property triples if they do not already exist in the graph. Optimized to avoid multiple loops over triples.
Source code in ontocast/onto.py
OntologyProperties
¶
Bases: BaseModel
Properties of an ontology.
Attributes:
Name | Type | Description |
---|---|---|
ontology_id |
Optional[str]
|
Ontology identifier. |
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 |
---|---|---|
ontology_id |
Optional[str]
|
Ontology id 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
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 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 |
|
__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
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 |
|
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.