Skip to content

magbak/stOTTRs

Repository files navigation

stOTTRs

A Rust-based implementation of stOTTR with extensions for mapping asset structures based on the Epsilon Transformation Language. Implemented with Apache Arrow in Rust using Pola.rs. with a Python wrapper

Mapping

We can easily map DataFrames to RDF-graphs using the Python library.

from stottrs import Mapping
#We use polars dataframes instead of pandas dataframes. The api is pretty similar.
import polars as pl

#Define a stOttr document with a template:
doc = """
    @prefix ex:<http://example.net/ns#>.
    ex:ExampleTemplate [?MyValue] :: {
    ottr:Triple(ex:myObject, ex:hasValue, ?MyValue)
    } .
    """

#Define a data frame to instantiate:
df = pl.DataFrame({"MyValue": [1, 2]})
#Create a mapping object
mapping = Mapping([doc])
#Expand the template using the data in the dataframe
mapping.expand("http://example.net/ns#ExampleTemplate", df)
#Export triples
triples = mapping.to_triples()
print(triples)

Results in:

[<http://example.net/ns#myObject> <http://example.net/ns#hasValue> "1"^^<http://www.w3.org/2001/XMLSchema#long>, 
 <http://example.net/ns#myObject> <http://example.net/ns#hasValue> "2"^^<http://www.w3.org/2001/XMLSchema#long>]

An example mapping is provided in this jupyter notebook. The Python API is documented here

Installing pre-built wheels

From the latest release, copy the appropriate .whl-file for your system, then run e.g.:

pip install https://github.com/magbak/stOTTRs/releases/download/v0.1.45/stottr-0.1.45-cp310-cp310-manylinux_2_31_x86_64.whl

All code is licensed to Prediktor AS under the Apache 2.0 license unless otherwise noted, and has been financed by The Research Council of Norway (grant no. 316656) and Prediktor AS as part of a PhD Degree.