Skip to main content

SSNOlib is a Python library for working with the Standard Name Ontology (SSNO).

Project description

ssnolib: Library for the Simple Standard Name Ontology (SSNO)

Tests Coverage Python Versions SSNO Version License

A Python library to work with the SSNO ontology. It provides Python classes for ontology concepts and facilitates the creation of RDF files (JSON-LD, TTL, XML). RDF files are both human- and machine-readable, and most importantly, machine-actionable. The library can be integrated into your data (conversion) pipelines.

Features

  • Python classes for all SSNO ontology concepts
  • Easy creation and export of JSON-LD, TTL, and XML files
  • Support for Standard Name Tables (SNT)
  • Extensible for HDF5, XML, and YAML formats
  • Local web apps (Streamlit, Flask) for management and enrichment
  • Compatible with Python 3.8–3.12
  • Comprehensive documentation and tutorials

Note: The library version matches the supported ontology version. For example, 1.5.0.1 refers to ontology version 1.5.0 and patch version .1 of the library.

Installation

Install the core library:

pip install ssnolib

Quickstart

Describe a Standard Name and dump it to Turtl

import ssnolib

air_temp = ssnolib.StandardName(
    standardName='air_temperature',
    unit='K',
    description='Air temperature is the bulk temperature of the air, not the surface (skin) temperature.@en')
with open('air_temperature.jsonld', 'w') as f:
    f.write(air_temp.model_dump_ttl())

The serialized TTL file looks like this:

@prefix ssno: <https://matthiasprobst.github.io/ssno#> .

[] a ssno:StandardName ;
    ssno:description "Air temperature is the bulk temperature of the air, not the surface (skin) temperature."@en ;
    ssno:standardName "air_temperature" ;
    ssno:unit <http://qudt.org/vocab/unit/K> .

Describe Standard Name Tables

A Standard Name Table (SNT) defines Standard Names and exists as an RDF file (usually in TTL, XML, or JSON-LD format). The SNT itself is modeled by ssnolib.StandardNameTable. In the following example, we define a SNT with one Standard Name (air_temperature) which is stored in a dcat:Dataset with one dcat:Distribution. The distribution points to a TTL file containing the SNT, which can be downloaded.

import ssnolib
from ssnolib.dcat import Dataset, Distribution

distribution = Distribution(
    title='TTL Table@en',
    downloadURL='https://example.org/cf-standard-name-table.ttl',
    mediaType='text/turtle'
)
snt_dataset = Dataset(
    title='CF Standard Name Table Dataset@en',
    description='The CF Standard Name Table is a controlled vocabulary for climate and forecast metadata.@en',
    distribution=distribution
)
snt = ssnolib.StandardNameTable(
    id="https://doi.org/10.5281/zenodo.12345678",
    title='CF Standard Name Table (latest version)@en',
    dataset=snt_dataset,
    created="2023-10-10",
    standardNames=[air_temp,]
)

The serialized version in TTL format can be obtained by:

print(snt.serialize("ttl", base_uri="https://example.org#"))

which results in:

@prefix dcat: <http://www.w3.org/ns/dcat#> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix ssno: <https://matthiasprobst.github.io/ssno#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<https://doi.org/10.5281/zenodo.12345678> a ssno:StandardNameTable ;
    dcterms:created "2023-10-10"^^xsd:date ;
    dcterms:title "CF Standard Name Table (latest version)"@en ;
    ssno:dataset <https://example.org/#N2f15bceee1cf431688c375b242d2c61b> ;
    ssno:standardNames <https://example.org/#N5542e225237745dfa57de897543fa5c8> .

<https://example.org/#N2f15bceee1cf431688c375b242d2c61b> a dcat:Dataset ;
    dcterms:description "The CF Standard Name Table is a controlled vocabulary for climate and forecast metadata."@en ;
    dcterms:title "CF Standard Name Table Dataset"@en ;
    dcat:distribution <https://example.org/#Ncd83fad310144161b45f7c466d6fd7cc> .

<https://example.org/#N5542e225237745dfa57de897543fa5c8> a ssno:StandardName ;
    ssno:description "Air temperature is the bulk temperature of the air, not the surface (skin) temperature."@en ;
    ssno:standardName "air_temperature" ;
    ssno:unit <http://qudt.org/vocab/unit/K> .

<https://example.org/#Ncd83fad310144161b45f7c466d6fd7cc> a dcat:Distribution ;
    dcterms:title "TTL Table"@en ;
    dcat:downloadURL <https://example.org/cf-standard-name-table.ttl> ;
    dcat:mediaType <https://www.iana.org/assignments/media-types/text/turtle> .

Web App Usage

Two simple web-apps exist to manage Standard Name Tables and to semantically enrich HDF5 files with Standard Names.

  1. A Streamlit app to semantically enrich HDF5 files (requires hdf extra)
  2. A Flask app to create and manage Standard Name Tables (requires app extra)

Install the library with the required extras:

pip install ssnolib[app,hdf]

To start the GUI:

ssnolib --h5sn

or

ssnolib --app

This will start a local development server at https://127.0.0.1:5000/.

Note: The web app is work in progress. Do not expose it to the public. Feedback and contributions are welcome!

Testing

To run tests:

pytest tests

Contribution

Contributions are welcome! Please open an issue or pull request. Guidelines:

  • Write clear commit messages
  • Add tests for new features
  • Document changes in CHANGELOG.md

Citation

Please cite this project using the CITATION.cff.

License

This project is licensed under the MIT License.

Support & Contact

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

ssnolib-1.5.1.4.tar.gz (76.4 kB view details)

Uploaded Source

Built Distribution

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

ssnolib-1.5.1.4-py3-none-any.whl (67.5 kB view details)

Uploaded Python 3

File details

Details for the file ssnolib-1.5.1.4.tar.gz.

File metadata

  • Download URL: ssnolib-1.5.1.4.tar.gz
  • Upload date:
  • Size: 76.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.11

File hashes

Hashes for ssnolib-1.5.1.4.tar.gz
Algorithm Hash digest
SHA256 0e63532ad4b822664b385cc9c6fc6ac7ed6538245cd53e424ace536c8cf6ce7d
MD5 ea7b11c5f36af1d1ea6f8c33e87f6674
BLAKE2b-256 9347ea96d91feaf13bb97273e53c3b767028fea9e0612604b02696c8bd14a456

See more details on using hashes here.

File details

Details for the file ssnolib-1.5.1.4-py3-none-any.whl.

File metadata

  • Download URL: ssnolib-1.5.1.4-py3-none-any.whl
  • Upload date:
  • Size: 67.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.11

File hashes

Hashes for ssnolib-1.5.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 79d4f774eafe0ac5c96906749570159bbcb04ea5c854f79f6e9fbb4dfa5774dc
MD5 e3265db0de4362f3b81e77e9aaaf9516
BLAKE2b-256 85befd948757fa553918bd0bad87f1f81efdff692ee2ca1943bcaaa4f5e12176

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