Skip to main content

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:provider links as resources (URI or materialized schema: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

  • SemanticSEGBLogger
  • SEGBPublisher
  • HTTPSharedContextResolver
  • ActivityKind, 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_URL
    • SEGB_API_TOKEN (only when backend auth is enabled)
  • Optional:
    • SEGB_SHARED_CONTEXT_TIMEOUT_SECONDS (must be > 0, default 5.0)
    • SEGB_SHARED_CONTEXT_VERIFY_TLS (true/false, default true)
    • SEGB_SHARED_CONTEXT_RAISE_ON_ERROR (true/false, default false)

Shared Event RDF Shape

  • Shared events are serialized as schema:Event and prov:Entity.
  • event_kind and modality are still used for resolver/fingerprint logic, but are not emitted as schema:eventType/schema:measurementTechnique.
  • When modality is provided, the logger emits a sosa:Observation linked to the shared event with:
    • sosa:hasFeatureOfInterest (the shared event)
    • sosa:usedProcedure (procedure resource labelled with modality, e.g. speech)
    • sosa:resultTime
    • sosa:hasSimpleResult (when text is available)
  • Observation-to-shared-event confidence is emitted as schema:additionalProperty (schema:PropertyValue with schema:propertyID="shared_event_confidence").

Robot State RDF Shape

  • Robot state snapshots are emitted as entities with schema:PropertyValue nodes.
  • State properties are linked with schema:additionalProperty.
  • State location is linked with prov:atLocation.

Related Docs

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

semantic_log_generator-1.0.5.tar.gz (25.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

semantic_log_generator-1.0.5-py3-none-any.whl (28.3 kB view details)

Uploaded Python 3

File details

Details for the file semantic_log_generator-1.0.5.tar.gz.

File metadata

File hashes

Hashes for semantic_log_generator-1.0.5.tar.gz
Algorithm Hash digest
SHA256 935af60a5e3e8b59d1460e2f8e0fb38283c4ea626af91183869e699d6cc553ae
MD5 6bbf1b8c2d48d9950a8aee84e8d26b3e
BLAKE2b-256 d45fb7ae3356b7ce84c2b01c274e9b6f26a08d64f474bf1860244c2ba268a719

See more details on using hashes here.

File details

Details for the file semantic_log_generator-1.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for semantic_log_generator-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 142b3055e9d53a44110d7fb76f56e5de56bd20f7c9fb5700162afc77727b8d28
MD5 e45febbfb7fe3909453cdd47c1f1d897
BLAKE2b-256 eea64803d003d1ee98850e367325272b19d2a2e44bcefb9364ec1729a3f89d64

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page