Chuyển tới nội dung chính

NGSI-LD to RDF Agent

The NGSI-LD to RDF Agent converts NGSI-LD entities to pure RDF/Turtle format.

📋 Overview

PropertyValue
Modulesrc.agents.rdf_linked_data.ngsi_ld_to_rdf_agent
ClassNGSILDToRDFAgent
AuthorUIP Team
Version1.0.0

🎯 Purpose

  • Convert NGSI-LD to RDF with proper ontology mappings
  • Preserve semantic meaning during conversion
  • Apply domain ontologies (SOSA, SSN, GeoSPARQL)
  • Generate clean Turtle output

🚀 Usage

Convert Single Entity

from src.agents.rdf_linked_data.ngsi_ld_to_rdf_agent import NGSILDToRDFAgent

agent = NGSILDToRDFAgent()

ngsi_entity = {
"id": "urn:ngsi-ld:TrafficCamera:CAM_001",
"type": "TrafficCamera",
"location": {
"type": "GeoProperty",
"value": {"type": "Point", "coordinates": [106.6297, 10.8231]}
},
"vehicleCount": {
"type": "Property",
"value": 42,
"observedAt": "2025-11-29T10:30:00Z"
}
}

# Convert to RDF
rdf_graph = agent.convert(ngsi_entity)

# Serialize to Turtle
turtle = rdf_graph.serialize(format="turtle")

Batch Conversion

# Convert multiple entities
entities = [entity1, entity2, entity3]
combined_graph = agent.convert_batch(entities)

With Ontology Mappings

# Convert with SOSA/SSN ontology
rdf_graph = agent.convert(
entity=sensor_entity,
ontology="sosa",
include_metadata=True
)

⚙️ Configuration

# config/ngsi_ld_mappings.yaml
ngsi_ld_to_rdf:
enabled: true

# Base URI
base_uri: "https://uip.city.gov/entities/"

# Ontology mappings
ontologies:
sosa:
prefix: "http://www.w3.org/ns/sosa/"
mappings:
TrafficCamera: "sosa:Platform"
vehicleCount: "sosa:observedProperty"
geo:
prefix: "http://www.opengis.net/ont/geosparql#"
mappings:
location: "geo:hasGeometry"

# Output settings
output:
format: "turtle"
include_prefixes: true
pretty_print: true

📊 Mapping Example

NGSI-LD Input

{
"id": "urn:ngsi-ld:TrafficCamera:CAM_001",
"type": "TrafficCamera",
"vehicleCount": {
"type": "Property",
"value": 42
}
}

RDF/Turtle Output

@prefix sosa: <http://www.w3.org/ns/sosa/> .
@prefix uip: <https://uip.city.gov/entities/> .

uip:TrafficCamera_CAM_001 a sosa:Platform ;
sosa:hosts uip:Sensor_CAM_001 ;
sosa:madeObservation [
a sosa:Observation ;
sosa:observedProperty uip:vehicleCount ;
sosa:hasSimpleResult 42
] .

See the complete agents reference for all available agents.