From 873a9f9dd26143e040148b1c155fdbc1a2b73d73 Mon Sep 17 00:00:00 2001 From: Roger Rutishauser Date: Thu, 3 Oct 2024 19:44:26 +0200 Subject: [PATCH] rdf --- rdf/README.md | 8 +++ sparql/README.md | 180 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+) create mode 100644 sparql/README.md diff --git a/rdf/README.md b/rdf/README.md index 5154f79..92c6485 100644 --- a/rdf/README.md +++ b/rdf/README.md @@ -33,3 +33,11 @@ rdf:type is a property `` and | 2.0 | xsd:decimal | | True | xsd:boolean | +## Tools + +### Raptor + +Raptor is a free software / Open Source C library that provides a set of parsers and serializers that generate Resource Description Framework (RDF) triples by parsing syntaxes or serialize the triples into a syntax. The supported parsing syntaxes are RDF/XML, N-Quads, N-Triples 1.0 and 1.1, TRiG, Turtle 2008 and 2013, RDFa 1.0 and 1.1, RSS tag soup including all versions of RSS, Atom 0.3 and Atom 1.0, GRDDL and microformats for HTML, XHTML and XML. The serializing syntaxes are RDF/XML (regular, abbreviated, XMP), Turtle 2013, N-Quads, N-Triples 1.1, Atom 1.0, RSS 1.0, GraphViz DOT, HTML, JSON and mKR. + +https://librdf.org/raptor/ + diff --git a/sparql/README.md b/sparql/README.md new file mode 100644 index 0000000..9a24226 --- /dev/null +++ b/sparql/README.md @@ -0,0 +1,180 @@ +--- +gitea: none +include_toc: true +--- +# Sparql Queries + +## Select + +### Übersichts-Queries + +#### Finde alle Classes + +``` +PREFIX rdf: +SELECT DISTINCT ?type +WHERE { + ?s a ?type. +} +``` + +#### Finde alle Classes mit bestimmten Prefix + +``` +PREFIX bc: +SELECT DISTINCT ?type +WHERE { + ?subject a ?type. + FILTER( STRSTARTS(STR(?type),str(bc:)) ) +} +``` + +#### Select all Triples + +``` +select ?s ?p ?o +where {?s ?p ?o} +``` + +#### Select Triples with rdf:type as ?p + +``` +select ?s ?p ?o +where { + ?s rdf:type ?o . +} +```` + +#### Select Triples with rdf:type and multiple ?o + +``` +select ?s ?p ?o +where { + values ?o { } + ?s rdf:type ?o +} +``` + +#### Count + +``` +prefix rico: +SELECT (count (?c) as ?cCount) +WHERE { + ?c a +} +``` + +### Suche nach String + +#### Select resource with needle in 2nd level of haystack + +``` +prefix rico: +SELECT ?s +WHERE { + ?s ^rico:isOrWasIdentifierOf ?o . + FILTER EXISTS { ?o rico:name "CH-000249-X:666377" } +} +``` + + +### Date Queries + +#### Events zwischen Start- und Enddatum + +``` +# Events zwischen Start- und Enddatum +# *********************************** +prefix rdf: +prefix rdfs: +prefix dcterms: +prefix skos: +prefix schema: +prefix roru: +SELECT ?s ?event_name ?datestart ?startmonth ?dateend ?dateend2 +WHERE { + ?s schema:name ?event_name . + ?s schema:startDate ?datestart . + ?s schema:endDate ?dateend . + BIND(xsd:date(?dateend) AS ?dateend2) . + BIND(MONTH(?datestart) AS ?startmonth) . + #BIND(STRLEN(?dateend) AS ?len_dateend) . + #FILTER (?len_dateend > 0) . + + # achtung, nur xsd:dateTime lassen sich vergleichen, xsd:date nicht + FILTER (xsd:dateTime(?datestart) < "2022-02-14T00:00:00"^^xsd:dateTime) + FILTER (xsd:dateTime(?dateend) > "2022-02-14T00:00:00"^^xsd:dateTime) +} +order by desc(?dateend) +``` + +#### Events genaues Datum + +``` turtle +# Events genaues Datum +# ******************** +prefix rdf: +prefix rdfs: +prefix dcterms: +prefix skos: +prefix schema: +prefix roru: +SELECT ?s ?event_name ?datestart ?dateend ?datestartyear ?dateendyear +WHERE { + ?s schema:name ?event_name . + OPTIONAL { ?s schema:startDate ?datestart .} + OPTIONAL { ?s schema:endDate ?dateend .} + + BIND ( STR(YEAR(?datestart)) AS ?datestartyear ) . + BIND ( STR(MONTH(?datestart)) AS ?datestartmonth ) . + BIND ( STR(DAY(?datestart)) AS ?datestartday ) . + + BIND ( STR(YEAR(?dateend)) AS ?dateendyear ) . + BIND ( STR(MONTH(?dateend)) AS ?dateendmonth ) . + BIND ( STR(DAY(?dateend)) AS ?dateendday ) . + + FILTER (?datestartyear = "2022" || ?dateendyear = "2022") . + FILTER (?datestartmonth = "3" || ?dateendmonth = "3") . + FILTER (?datestartday = "15" || ?dateendday = "15") . +} +order by desc(?dateend) +``` + +### RANDOM select example 1 + +``` +# select all unitdate values of any resource + +prefix rico: + +SELECT DISTINCT ?resource ?s ?date +WHERE { + { + ?s rico:normalizedDateValue ?date . + } + UNION + { + ?s rico:expressedDate ?date . + } + ?s rico:hasOrHadCategory . + ^rico:hasOrHadCategory ?relation . + ?relation rico:relationHasSource ?resource . + +} +ORDER BY ASC (?resource) +``` + +## Update + +### Delete Triples where ?s ?p ?o contains string + +``` +DELETE +{ ?s ?p ?o } +WHERE +{ + ?s ?p ?o . + FILTER(regex(str(?s), "needle")) +} +```