ontocast.onto.sparql_models¶
Pydantic models for SPARQL operations.
This module provides Pydantic models for structured SPARQL queries that can be used with PydanticOutputParser for LLM integration.
FactsUpdateReport
¶
Bases: BaseModel
Report from facts update process using structured SPARQL.
Attributes:
| Name | Type | Description |
|---|---|---|
update_success |
bool
|
True if the facts update was performed successfully |
structured_query |
StructuredSPARQLQueryModel
|
The structured SPARQL query used for the update |
add_count |
int
|
Number of ADD operations |
update_count |
int
|
Number of UPDATE operations |
remove_count |
int
|
Number of REMOVE operations |
critique |
str | None
|
Optional critique of the update process |
Source code in ontocast/onto/sparql_models.py
FreshFactsReport
¶
Bases: BaseModel
Report from fresh facts generation process.
Attributes:
| Name | Type | Description |
|---|---|---|
generation_success |
bool
|
True if the facts were generated successfully |
facts_graph |
RDFGraph
|
The generated facts as an RDFGraph |
facts_score |
float | None
|
Score 0-100 for facts quality |
critique |
str | None
|
Optional critique of the facts generation |
Source code in ontocast/onto/sparql_models.py
FreshOntologyReport
¶
Bases: BaseModel
Report from fresh ontology generation process.
Attributes:
| Name | Type | Description |
|---|---|---|
generation_success |
bool
|
True if the ontology was generated successfully |
ontology_graph |
RDFGraph
|
The generated ontology as an RDFGraph |
ontology_score |
float | None
|
Score 0-100 for ontology quality |
critique |
str | None
|
Optional critique of the ontology generation |
Source code in ontocast/onto/sparql_models.py
GenericSparqlQuery
¶
Bases: BaseModel
Operation for custom SPARQL queries that go beyond basic insert/delete operations.
This operation allows for complex SPARQL queries that cannot be expressed using the structured operations. Use this when you need custom SPARQL syntax, complex WHERE clauses, or operations that don't fit the basic patterns.
Source code in ontocast/onto/sparql_models.py
GraphUpdate
¶
Bases: BaseModel
Structured representation of RDF graph updates for LLM output.
This model represents ontology updates as a structured set of operations. Each operation in the list is executed in order to modify the graph.
Source code in ontocast/onto/sparql_models.py
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 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 | |
count_total_triples()
¶
Count total triples across all operations.
Returns:
| Type | Description |
|---|---|
int
|
Tuple of (total_operations, total_triples) where: |
int
|
|
tuple[int, int]
|
|
Source code in ontocast/onto/sparql_models.py
generate_diff_summary()
¶
Generate a human-readable diff summary of all operations for LLM consumption.
Returns:
| Type | Description |
|---|---|
str
|
String representation of all operations showing what will be added, removed, and modified. |
str
|
Returns empty string if no operations to perform. |
Source code in ontocast/onto/sparql_models.py
generate_sparql_queries()
¶
Generate a list of SPARQL queries to execute the graph update.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of SPARQL query strings that can be executed to perform the update. |
list[str]
|
The queries are generated in the exact order of operations in the operations list. |
Source code in ontocast/onto/sparql_models.py
OntologyUpdateReport
¶
Bases: BaseModel
Report from ontology update process using structured SPARQL.
Attributes:
| Name | Type | Description |
|---|---|---|
update_success |
bool
|
True if the ontology update was performed successfully |
structured_query |
StructuredSPARQLQueryModel
|
The structured SPARQL query used for the update |
add_count |
int
|
Number of ADD operations |
update_count |
int
|
Number of UPDATE operations |
remove_count |
int
|
Number of REMOVE operations |
critique |
str | None
|
Optional critique of the update process |
Source code in ontocast/onto/sparql_models.py
SPARQLOperationModel
¶
Bases: BaseModel
Pydantic model for a single SPARQL operation.
Attributes:
| Name | Type | Description |
|---|---|---|
operation_type |
SPARQLOperationType
|
Type of SPARQL operation (INSERT, UPDATE, DELETE) |
query |
str
|
The SPARQL query string |
description |
str
|
Optional description of the operation |
metadata |
dict[str, Any]
|
Optional metadata dictionary |
Source code in ontocast/onto/sparql_models.py
StructuredSPARQLQueryModel
¶
Bases: BaseModel
Pydantic model for structured SPARQL queries.
Attributes:
| Name | Type | Description |
|---|---|---|
operations |
list[SPARQLOperationModel]
|
List of SPARQL operations (INSERT, UPDATE, DELETE) |
namespaces |
dict[str, str]
|
Dictionary mapping prefixes to URIs |
Source code in ontocast/onto/sparql_models.py
get_add_operations()
¶
get_all_operations()
¶
Get all operations in execution order (INSERT, UPDATE, DELETE).
Source code in ontocast/onto/sparql_models.py
get_remove_operations()
¶
get_summary()
¶
Get a summary of the structured query.
Source code in ontocast/onto/sparql_models.py
get_update_operations()
¶
TripleOp
¶
Bases: BaseModel
Operation to modify triples in the RDF graph.
This operation can insert or delete triples. Prefixes are automatically extracted from the RDFGraph's namespace bindings (from @prefix declarations in Turtle).