ontocast.tool.agg.uri_builder¶
URI construction with naming convention normalization.
Builds final URIs for entity representatives following RDF/Semantic Web naming conventions (see README.md): - Classes (entities / types): PascalCase (e.g., JudicialDecision) - Properties (predicates): lowerCamelCase (e.g., hasDecision) - Instances with natural names: PascalCase (e.g., FrenchCourtOfCassation) - Instances with structured/external IDs: preserve structure (e.g., Case_2023_456)
Underscores are avoided in ontology terms (classes, properties). Underscores are acceptable for instances derived from external IDs.
EntityRole
¶
URIBuilder
¶
Build normalized URIs for all entities following RDF naming conventions.
- Fact entities (under base_iri) get new URIs under base_iri.
- Ontology entities (everything else) are preserved as-is.
Source code in ontocast/tool/agg/uri_builder.py
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 | |
__init__(base_iri=DEFAULT_IRI)
¶
Initialise the builder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_iri
|
str
|
Base IRI for fact entities (default |
DEFAULT_IRI
|
Source code in ontocast/tool/agg/uri_builder.py
build_uri(entity, representation, role, target_iri=None, is_ontology_entity=None)
¶
Build a normalised URI for a single entity.
Fact entities are normalised and placed under target_iri (falling back to base_iri). Ontology entities are preserved as-is.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
URIRef
|
Original entity URI. |
required |
representation
|
EntityRepresentation
|
Entity representation with metadata. |
required |
role
|
EntityRole | str
|
Entity role (an :class: |
required |
target_iri
|
URIRef | str | None
|
Optional document IRI to use as namespace for fact
entities instead of the default base_iri. When chunks carry
different |
None
|
is_ontology_entity
|
bool | None
|
Explicit ontology/fact classification. When provided this takes precedence over namespace-based inference. |
None
|
Returns:
| Type | Description |
|---|---|
URIRef
|
Normalised URI. |
Source code in ontocast/tool/agg/uri_builder.py
compose_mappings(clustering_mapping, uri_mapping)
staticmethod
¶
Compose clustering and URI mappings.
e → representative(e) → normalised_uri(representative(e))
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clustering_mapping
|
dict[URIRef, URIRef]
|
|
required |
uri_mapping
|
dict[URIRef, URIRef]
|
|
required |
Returns:
| Type | Description |
|---|---|
dict[URIRef, URIRef]
|
Composed mapping |
Source code in ontocast/tool/agg/uri_builder.py
create_entity_uri_mapping(identity_mapping, representations, entity_doc_iris, entity_is_ontology)
¶
Create final URI mapping from identity mapping + namespace policy.
This method decouples canonical identity choice from URI surface choice:
identity mapping decides what is the same entity, while this method
decides how each source entity should be rendered as a final URI.
Fact entities are always rendered in their source doc_iri namespace.
Ontology entities are preserved as their canonical URI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identity_mapping
|
dict[URIRef, URIRef]
|
Mapping |
required |
representations
|
dict[URIRef, EntityRepresentation]
|
All entity representations. |
required |
entity_doc_iris
|
dict[URIRef, URIRef]
|
Mapping from source entity to source |
required |
entity_is_ontology
|
dict[URIRef, bool]
|
Classification map where |
required |
Returns:
| Type | Description |
|---|---|
dict[URIRef, URIRef]
|
Mapping |
Source code in ontocast/tool/agg/uri_builder.py
is_ontology_entity(entity)
¶
detect_role(entity, graph)
¶
Detect the role of an entity: class, property, or instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
URIRef
|
The entity URI. |
required |
graph
|
RDFGraph
|
The RDF graph containing the entity. |
required |
Returns:
| Type | Description |
|---|---|
EntityRole
|
The detected :class: |
Source code in ontocast/tool/agg/uri_builder.py
detect_role_from_context(types, is_predicate=False)
¶
Detect entity role from pre-extracted context (no graph scan needed).
This is the preferred entry point when the caller has already extracted
types and predicate usage via
:meth:EntityNormalizer.extract_entity_context, avoiding a redundant
full-graph iteration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
types
|
list[URIRef]
|
|
required |
is_predicate
|
bool
|
Whether the entity appears in the predicate position of at least one triple. |
False
|
Returns:
| Type | Description |
|---|---|
EntityRole
|
The detected :class: |
Source code in ontocast/tool/agg/uri_builder.py
format_structured_id(entity)
¶
Format a structured identifier preserving underscores and digits.
The leading word segment is capitalised so that the result starts
with an uppercase letter (e.g. Case_2023_456).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
URIRef
|
Original entity URI. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Cleaned identifier string. |
Source code in ontocast/tool/agg/uri_builder.py
has_structured_id(entity)
¶
Detect if an entity represents a structured/external identifier.
Structured IDs contain digits together with underscores, e.g.
Case_2023_456 or Decision_2021_09_15.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
URIRef
|
Original entity URI. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the entity appears to have a structured ID. |
Source code in ontocast/tool/agg/uri_builder.py
normalize_local_name(representation, role)
¶
Produce a properly-cased local name following RDF conventions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
representation
|
EntityRepresentation
|
Entity representation with metadata. |
required |
role
|
EntityRole | str
|
Entity role (an :class: |
required |
Returns:
| Type | Description |
|---|---|
str
|
Properly cased local name. |
Source code in ontocast/tool/agg/uri_builder.py
to_lower_camel_case(normalized)
¶
Convert a space-separated lowercase string to lowerCamelCase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normalized
|
str
|
Space-separated lowercase string. |
required |
Returns:
| Type | Description |
|---|---|
str
|
lowerCamelCase string. |
Examples:
>>> to_lower_camel_case('has decision')
'hasDecision'
>>> to_lower_camel_case('date published')
'datePublished'
Source code in ontocast/tool/agg/uri_builder.py
to_pascal_case(normalized)
¶
Convert a space-separated lowercase string to PascalCase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normalized
|
str
|
Space-separated lowercase string. |
required |
Returns:
| Type | Description |
|---|---|
str
|
PascalCase string. |
Examples:
>>> to_pascal_case('judicial decision')
'JudicialDecision'
>>> to_pascal_case('french court of cassation')
'FrenchCourtOfCassation'