# RDF、om2m semantic description
## om2m semantic description

om2m semantic description文件上有說明,但目前釋出的程式碼還沒有實做
> [oneM2M tr0045](https://www.onem2m.org/tr-0045/implementation)
> **[TR-0045- V2.0.0 / Developer Guide: Implementing Semantics](https://www.onem2m.org/images/files/deliverables/Release2A/TR-0045-Developer_Guide_Implementing_Semantics-v_2_0_0.pdf)**
> [om2m source code](https://git.eclipse.org/c/om2m/org.eclipse.om2m.git)
> [oneM2M TS-0004 version 2.7.1 Release 2](https://drive.google.com/open?id=1_fbkS4fIgeg7wpuc5fn-lTZRV4jQsdUB&authuser=410421220@gms.ndhu.edu.tw&usp=drive_fs)
---
```sequence
Note left of IPE: IPE訂閱Sensor
IPE->CSE: subscribe cin
Note right of Sensor1\n(風速計): Sensor1\n(風速計)新增觀測值
Sensor1\n(風速計)->CSE: create_cin
CSE-->IPE: notify IPE
Note left of IPE: 分析cin 加入描述\n(semantic description)
IPE->CSE: create_smd
Note right of Sensor2\n(溫度計): Sensor2\n(溫度計)新增觀測值
Sensor2\n(溫度計)->CSE: create_cin
CSE-->IPE: notify IPE
Note left of IPE: 分析cin 加入描述\n(semantic description)
IPE->CSE: create_smd
IPE-->IPE: 定期分析smd
IPE->CSE: create_smd
IPE->Actuator\n(窗戶): do something
```
## RDF(Resource Description Framework)
### 介紹
RDF(資源描述架構)是網際網路標準組織(W3C)為解決資源描述問題的規範,本質是一個數據模型(Data Model)。
它提供了一個統一的標準,用於描述實體/資源
* RDF 資料基本模型包括**資源(Resources)**、**屬性(Properties)**以及**宣告(Statements)**。
1. 來源(Resources):資料來源。
2. 屬性(Properties):屬性可以是來源的觀點、特徵或是關係。每個屬性都有一個意義,定義許可的值。描述來源的型別和其他屬性的關係。
3. 敘述(Statements):敘述的語句以RDF的格式表示。敘述被分成三個部分,分別是Subject、Predicate和Object。Subject可以表示來源,Predicate可以表示屬性,Object可以是文字或是其他的來源。
```graphviz
digraph graphname{
T [label="Subject\n(表示來源)", shape=box] // node T
P [label="Object\n(表示文字或其他來源)", shape=box] // node P
T->P [label=" Predicate\n(表示屬性)", fontcolor=black] // edge T->P
}
```
* SSN (Semantic Sensor Network):用來描述sensors及觀察的結果、所涉及的過程、所研究的感興趣特徵
* SOSA (Sensor, Observation, Sample, and Actuator):SSN基本元素和屬性(sensor, observation, sample, actuator)
:::spoiler
The Semantic Sensor Network (SSN) ontology is an ontology for describing sensors and their observations, the involved procedures, the studied features of interest, the samples used to do so, and the observed properties, as well as actuators. SSN follows a horizontal and vertical modularization architecture by including a lightweight but self-contained core ontology called SOSA (Sensor, Observation, Sample, and Actuator) for its elementary classes and properties. With their different scope and different degrees of axiomatization, SSN and SOSA are able to support a wide range of applications and use cases, including satellite imagery, large-scale scientific monitoring, industrial and household infrastructures, social sensing, citizen science, observation-driven ontology engineering, and the Web of Things. Both ontologies are described below, and examples of their usage are given.
:::
### RDF/ttl範例

```ttl
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix sosa: <http://www.w3.org/ns/sosa/> .
@prefix ssn: <http://www.w3.org/ns/ssn/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix qudt-1-1: <http://qudt.org/1.1/schema/qudt#> .
@prefix qudt-unit-1-1: <http://qudt.org/1.1/vocab/unit#> .
@prefix ssn-system: <http://www.w3.org/ns/ssn/systems/> .
@prefix schema: <http://schema.org/>.
@prefix exq: <http://example.org/ns#>.
exq:obs005 rdf:type sosa:Observation ;
sosa:observedProperty exq:adreamTemperature ;
sosa:madeBySensor exq:thermometer ;
sosa:hasResult [
rdf:type qudt-1-1:QuantityValue ;
qudt-1-1:numericValue 13 ;
qudt-1-1:unit qudt-unit-1-1:DegreeCelsius ] ;
sosa:resultTime "2019-06-19T23:30:12+00:00"^^xsd:dateTimeStamp .
```
> 畫圖參考 http://www.ldf.fi/service/rdf-grapher
### SPARQL Query Language for RDF
DATA
```ttl=1
@prefix ex: <http://example.org/ns#> .
@prefix qudt-1-1: <http://qudt.org/1.1/schema/qudt#> .
@prefix qudt-unit-1-1: <http://qudt.org/1.1/vocab/unit#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <http://schema.org/> .
@prefix sosa: <http://www.w3.org/ns/sosa/> .
@prefix ssn-system: <http://www.w3.org/ns/ssn/systems/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
ex:obs001 a sosa:Observation ;
sosa:hasResult [ a qudt-1-1:QuantityValue ;
qudt-1-1:numericValue 130 ;
qudt-1-1:unit qudt-unit-1-1:KilometerPerHour ] ;
sosa:madeBySensor ex:anemometer ;
sosa:observedProperty ex:windSpeed ;
sosa:resultTime "2019-06-19T23:30:12+00:00"^^xsd:dateTimeStamp .
ex:anemometer a sosa:Sensor ;
sosa:isHostedBy ex:weather_station ;
sosa:observes ex:adreamWindSpeed ;
ssn-system:hasOperatingRange ex:AnemometerOperatingRange.
ex:AnemometerOperatingRange a ssn-system:OperatingRange ;
rdfs:comment "Wind speeds that should be measured by the anemometer without damage."@en ;
ssn-system:inCondition ex:NormalWindSpeed .
ex:NormalWindSpeed a schema:PropertyValue,
ssn-system:Condition ;
schema:maxValue 100.0 ;
schema:minValue 0.0 ;
schema:unitCode qudt-unit-1-1:KilometerPerHour ;
rdfs:comment "A wind speed ranging from 0 to 100 km/h."@en .
```
Query
```ttl=1
PREFIX sosa: <http://www.w3.org/ns/sosa/>
PREFIX qudt-1-1: <http://qudt.org/1.1/schema/qudt#>
PREFIX ssn-system: <http://www.w3.org/ns/ssn/systems/>
PREFIX schema: <http://schema.org/>
SELECT ?sensor ?val ?unit ?observation
WHERE {
?observation a sosa:Observation;
sosa:madeBySensor ?sensor ;
sosa:hasResult [
qudt-1-1:numericValue ?val;
].
?sensor ssn-system:hasOperatingRange [
ssn-system:inCondition [
schema:minValue ?min ;
schema:maxValue ?max ;
schema:unitCode ?unit;
] ;
].
FILTER (?val < ?min || ?val > ?max)
}
```
Query result
| sensor | val | unit | observation |
| ---------- | --- | ---------------- | ----------- |
| anemometer | 130 | KilometerPerHour | obs001 |
> [SPARQL Query Language for RDF](https://www.w3.org/TR/rdf-sparql-query/)
> [Semantic Sensor Network Ontology](https://www.w3.org/TR/vocab-ssn/)
> [知识图谱基础之RDF,RDFS与OWL](https://zhuanlan.zhihu.com/p/32122644)