https://github.com/connctd/wotlib
Simplify working with WoT Thing Descriptions
https://github.com/connctd/wotlib
iot thing-description w3c webofthings
Last synced: 5 months ago
JSON representation
Simplify working with WoT Thing Descriptions
- Host: GitHub
- URL: https://github.com/connctd/wotlib
- Owner: connctd
- License: apache-2.0
- Created: 2020-04-28T15:45:29.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-11-08T10:40:40.000Z (over 4 years ago)
- Last Synced: 2024-12-25T04:02:44.730Z (over 1 year ago)
- Topics: iot, thing-description, w3c, webofthings
- Language: Go
- Homepage: https://pkg.go.dev/github.com/connctd/wotlib?tab=doc
- Size: 23.4 KB
- Stars: 0
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WoT Lib
This lib was created to simplify working with [WoT Thing Descriptions](https://www.w3.org/TR/wot-thing-description/).
It is coupled to W3C's recommendation from 9 April 2020 (https://www.w3.org/TR/2020/REC-wot-thing-description-20200409/) which means it assumes a certain structure. So far only a subset of the fields are
implemented.
## Working principle
Read Thing Description -> Expand -> Perform operations
## Capabilities
- Determine if a thing and its sub elements do match with certain criteria
- Search for property affordances with specific constraints
- Search for action affordances with specific constraints
## Example
The following example reads a td from bytes and retrieves all property affordances that
match a given criteria
```go
// Define additionally used schema
var iotSchema = wotlib.SchemaMapping{
Prefix: wotlib.SchemaPrefix("iot"),
IRI: "http://iotschema.org/",
}
// Append it so its used during compaction
wotlib.AppendSchema(iotSchema)
expandedTD, err := wotlib.FromBytes(input)
if err != nil {
panic(err)
}
// Retrieve all property affordances that match given criteria
props := expandedTD.GetPropertyAffordances(wotlib.PropertyConstraint{
Type: &[]string{iotSchema.IRIPrefix("SwitchStatus")},
})
// Prints the href of the first match
fmt.Printf("Result: %s", props[0].Form.Value().Href.Value())
```
In case multiple Thing Descriptions have to be processed append them to a set
and apply the operation
```go
set := wotlib.NewExpandedThingDescriptionSet(expandedTD)
set.GetActionAffordances(thingConstraint)
```