Production-ready semantic RDF logging toolkit for SEGB-enabled robots
Project description
semantic_log_generator
Python package to build SEGB-compatible RDF logs and publish them to the centralized backend.
Compatibility
- Python: 3.10, 3.11, 3.12
- License: Apache-2.0
- Versioning: Semantic Versioning (see
CHANGELOG.md)
What It Does
- Maps robot runtime facts to RDF triples
- Uses SEGB + PROV + ORO + ONYX + MLS + SOSA vocabularies
- Supports shared-event/shared-context linking across robots
- Publishes TTL payloads to backend
/ttl - Emits
schema:providerlinks as resources (URI or materializedschema:Organization), not literals
What It Does Not Do
- Sensor acquisition
- ROS transport/orchestration
- Robot decision making
- KG reasoning
Install
From PyPI (when available)
python -m pip install semantic-log-generator
From TestPyPI (current published channel)
python -m pip install \
--index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple \
"semantic-log-generator>=1.0.5,<2.0.0"
From GitHub subdirectory
python -m pip install "git+https://github.com/gsi-upm/segb.git@<tag_or_commit>#subdirectory=packages/semantic_log_generator"
Quick Example
from datetime import datetime, timezone
from semantic_log_generator import ActivityKind, SemanticSEGBLogger
robot_id = "r1"
# base_namespace is generated by your application/deployment config.
# End users do not need to manipulate RDF/Turtle details.
base_namespace = f"https://example.org/segb/robots/{robot_id}/"
logger = SemanticSEGBLogger(
base_namespace=base_namespace,
robot_id=robot_id,
)
logger.log_activity(
activity_id="listen_1",
activity_kind=ActivityKind.LISTENING,
started_at=datetime.now(timezone.utc),
)
ttl = logger.serialize(format="turtle")
Main APIs
SemanticSEGBLoggerSEGBPublisherHTTPSharedContextResolverActivityKind,RobotStateSnapshot,EmotionScore,ModelUsage
Shared Context (Cross-Robot)
SemanticSEGBLogger does not auto-read environment variables and does not call
POST /shared-context/resolve unless you pass a resolver explicitly.
To enable backend shared-context resolution, create a resolver and inject it:
from semantic_log_generator import SemanticSEGBLogger, build_http_shared_context_resolver_from_env
robot_id = "r1"
base_namespace = f"https://example.org/segb/robots/{robot_id}/"
resolver = build_http_shared_context_resolver_from_env()
logger = SemanticSEGBLogger(
base_namespace=base_namespace,
robot_id=robot_id,
shared_event_resolver=resolver,
)
Environment variables for build_http_shared_context_resolver_from_env():
- General SEGB API configuration (recommended):
SEGB_API_URLSEGB_API_TOKEN(only when backend auth is enabled)
- Optional:
SEGB_SHARED_CONTEXT_TIMEOUT_SECONDS(must be> 0, default5.0)SEGB_SHARED_CONTEXT_VERIFY_TLS(true/false, defaulttrue)SEGB_SHARED_CONTEXT_RAISE_ON_ERROR(true/false, defaultfalse)
Shared Event RDF Shape
- Shared events are serialized as
schema:Eventandprov:Entity. event_kindandmodalityare still used for resolver/fingerprint logic, but are not emitted asschema:eventType/schema:measurementTechnique.- When
modalityis provided, the logger emits asosa:Observationlinked to the shared event with:sosa:hasFeatureOfInterest(the shared event)sosa:usedProcedure(procedure resource labelled with modality, e.g.speech)sosa:resultTimesosa:hasSimpleResult(when text is available)
- Observation-to-shared-event confidence is emitted as
schema:additionalProperty(schema:PropertyValuewithschema:propertyID="shared_event_confidence").
Robot State RDF Shape
- Robot state snapshots are emitted as entities with
schema:PropertyValuenodes. - State properties are linked with
schema:additionalProperty. - State location is linked with
prov:atLocation.
Related Docs
- Installation guide:
docs/package/installation.md - Usage guide:
docs/package/usage.md - Internal TTL generation:
docs/internals/ttl-generation.md
Tests
Package-specific tests are in packages/semantic_log_generator/tests/unit.
PYTHONPATH=packages/semantic_log_generator/src:apps/backend/src ./.venv/bin/python -m unittest discover -s packages/semantic_log_generator/tests/unit -p 'test_*.py'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file semantic_log_generator-1.0.5.tar.gz.
File metadata
- Download URL: semantic_log_generator-1.0.5.tar.gz
- Upload date:
- Size: 25.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
935af60a5e3e8b59d1460e2f8e0fb38283c4ea626af91183869e699d6cc553ae
|
|
| MD5 |
6bbf1b8c2d48d9950a8aee84e8d26b3e
|
|
| BLAKE2b-256 |
d45fb7ae3356b7ce84c2b01c274e9b6f26a08d64f474bf1860244c2ba268a719
|
File details
Details for the file semantic_log_generator-1.0.5-py3-none-any.whl.
File metadata
- Download URL: semantic_log_generator-1.0.5-py3-none-any.whl
- Upload date:
- Size: 28.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
142b3055e9d53a44110d7fb76f56e5de56bd20f7c9fb5700162afc77727b8d28
|
|
| MD5 |
e45febbfb7fe3909453cdd47c1f1d897
|
|
| BLAKE2b-256 |
eea64803d003d1ee98850e367325272b19d2a2e44bcefb9364ec1729a3f89d64
|