Skip to content

Instantly share code, notes, and snippets.

@paul121
Last active March 12, 2024 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paul121/1d83c0d4dcdf06c3bcff44a4c42cffd7 to your computer and use it in GitHub Desktop.
Save paul121/1d83c0d4dcdf06c3bcff44a4c42cffd7 to your computer and use it in GitHub Desktop.
LinkML Project Posts

LinkML Project Post

This was created following the LinkML tutorial

Schema

  • projectpost.yaml contains the LinkML schema for a project post. There are separate classes for ProjectPost, File and FileLocation that utilize standard GeoSPARQL + WKT conventions.
  • This schema sets the default prefix/context to regenschema, but uses a few DC terms for most of the semantic modelling.
  • Project post files are referenced via the Regen IRI of the anchored data ?post dct:references regen:1111.rdf and the same Regen IRI is used as the subject for metadata about the file regen:111.rdf dct:title "File name"
    • This seems like the simplest approach for referencing files. There is no complexity of other blank or list nodes that the post uses to reference the files. Odering of files is not deterministic but could be solved with a separate order property.
    • More practically, I wonder if the order of files may be preserved simply by fact that the resolver (likely) returns the same JSON-LD document that was anchored. Would this work in the short term? If file order is important more semantic importance (eg when indexing/aggregating rdf data into a larger graph) then order could be added.
  • Blank nodes are only generated in RDF serialization to properly model the location geo:hasGeometry with a geo:asWKT serialization.
  • Relevant LinkML issue to allow distinguishing between a set and list: linkml/linkml#221

Data + validation

  • data.json contains a simple JSON definition of a project post.
  • To validate + convert to json-ld run: linkml-convert -s post.yaml data.json -t json-ld, This will yield the example in jsonld-data.jsonld
  • JSON Schema + SHACL can be generated, attaching the SHACL here, but didn't investigate how this could be further constrained.
{
"title": "Post title",
"comment": "Post description",
"files": [
{
"iri": "regen:1111.png",
"name": "Image file name",
"description": "Image description",
"credit": "Paul",
"location": {"wkt": "POINT(1 2)"}
},
{
"iri": "regen:2222.pdf",
"name": "File name",
"description": "File description",
"credit": "Paul"
}
]
}
{
"title": "Post title",
"comment": "Post description",
"files": [
{
"iri": "regen:1111.png",
"name": "Image file name",
"description": "Image description",
"location": {
"wkt": "POINT(1 2)"
},
"credit": "Paul"
},
{
"iri": "regen:2222.pdf",
"name": "File name",
"description": "File description",
"credit": "Paul"
}
],
"@type": "ProjectPost",
"@context": {
"dcterms": "http://purl.org/dc/terms/",
"geo": "http://www.opengis.net/ont/geosparql#",
"linkml": "https://w3id.org/linkml/",
"regenschema": "https://schema.regen.network/",
"@vocab": "https://schema.regen.network/",
"credit": {
"@id": "dcterms:creator"
},
"description": {
"@id": "dcterms:description"
},
"iri": "@id",
"location": {
"@type": "@id",
"@id": "geo:hasGeometry"
},
"name": {
"@id": "dcterms:title"
},
"wkt": {
"@id": "geo:asWKT"
},
"comment": {
"@id": "dcterms:description"
},
"files": {
"@type": "@id",
"@id": "dcterms:references"
},
"title": {
"@id": "dcterms:title"
},
"FileLocation": {
"@id": "geo:Geometry"
}
}
}
# metamodel_version: 1.7.0
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix geo: <http://www.opengis.net/ont/geosparql#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix regenschema: <https://schema.regen.network/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
regenschema:ProjectPost a sh:NodeShape ;
sh:closed true ;
sh:ignoredProperties ( rdf:type ) ;
sh:property [ sh:class regenschema:File ;
sh:nodeKind sh:IRI ;
sh:order 2 ;
sh:path dcterms:references ],
[ sh:datatype xsd:string ;
sh:maxCount 1 ;
sh:minCount 1 ;
sh:order 0 ;
sh:path dcterms:title ],
[ sh:datatype xsd:string ;
sh:maxCount 1 ;
sh:order 1 ;
sh:path dcterms:description ] ;
sh:targetClass regenschema:ProjectPost .
geo:Geometry a sh:NodeShape ;
sh:closed true ;
sh:ignoredProperties ( rdf:type ) ;
sh:property [ sh:datatype xsd:string ;
sh:maxCount 1 ;
sh:order 0 ;
sh:path geo:asWKT ] ;
sh:targetClass geo:Geometry .
regenschema:File a sh:NodeShape ;
sh:closed true ;
sh:ignoredProperties ( rdf:type ) ;
sh:property [ sh:datatype xsd:string ;
sh:maxCount 1 ;
sh:order 4 ;
sh:path dcterms:creator ],
[ sh:datatype xsd:string ;
sh:maxCount 1 ;
sh:order 2 ;
sh:path dcterms:description ],
[ sh:datatype xsd:string ;
sh:maxCount 1 ;
sh:order 0 ;
sh:path regenschema:iri ],
[ sh:datatype xsd:string ;
sh:maxCount 1 ;
sh:minCount 1 ;
sh:order 1 ;
sh:path dcterms:title ],
[ sh:class geo:Geometry ;
sh:maxCount 1 ;
sh:nodeKind sh:BlankNode ;
sh:order 3 ;
sh:path geo:hasGeometry ] ;
sh:targetClass regenschema:File .
id: https://schema.regen.network/schemas/projectpost
name: projectpost
prefixes:
linkml: https://w3id.org/linkml/
dcterms: http://purl.org/dc/terms/
geo: http://www.opengis.net/ont/geosparql#
regenschema: https://schema.regen.network/
imports:
- linkml:types
default_range: string
default_prefix: regenschema
classes:
ProjectPost:
attributes:
title:
required: true
slot_uri: dcterms:title
comment:
slot_uri: dcterms:description
files:
range: File
slot_uri: dcterms:references
multivalued: true
inlined_as_list: true
list_elements_ordered: true
File:
attributes:
iri:
identifier: true
name:
required: true
slot_uri: dcterms:title
description:
slot_uri: dcterms:description
location:
range: FileLocation
slot_uri: geo:hasGeometry
credit:
slot_uri: dcterms:creator
FileLocation:
class_uri: geo:Geometry
attributes:
wkt:
slot_uri: geo:asWKT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment