rdf
This commit is contained in:
parent
8ab95bb548
commit
873a9f9dd2
@ -33,3 +33,11 @@ rdf:type is a property `<http://www.w3.org/1999/02/222-rdf-syntax-ns#type>` 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/
|
||||
|
||||
|
||||
180
sparql/README.md
Normal file
180
sparql/README.md
Normal file
@ -0,0 +1,180 @@
|
||||
---
|
||||
gitea: none
|
||||
include_toc: true
|
||||
---
|
||||
# Sparql Queries
|
||||
|
||||
## Select
|
||||
|
||||
### Übersichts-Queries
|
||||
|
||||
#### Finde alle Classes
|
||||
|
||||
```
|
||||
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
||||
SELECT DISTINCT ?type
|
||||
WHERE {
|
||||
?s a ?type.
|
||||
}
|
||||
```
|
||||
|
||||
#### Finde alle Classes mit bestimmten Prefix
|
||||
|
||||
```
|
||||
PREFIX bc: <http://base22.com/ont/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 { <http://fedora.info/definitions/v4/repository#ArchivalGroup> <http://www.loc.gov/premis/rdf/v3/File> }
|
||||
?s rdf:type ?o
|
||||
}
|
||||
```
|
||||
|
||||
#### Count
|
||||
|
||||
```
|
||||
prefix rico: <https://www.ica.org/standards/RiC/ontology#>
|
||||
SELECT (count (?c) as ?cCount)
|
||||
WHERE {
|
||||
?c a <http://www.loc.gov/premis/rdf/v3/File>
|
||||
}
|
||||
```
|
||||
|
||||
### Suche nach String
|
||||
|
||||
#### Select resource with needle in 2nd level of haystack
|
||||
|
||||
```
|
||||
prefix rico: <https://www.ica.org/standards/RiC/ontology#>
|
||||
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: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
||||
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
||||
prefix dcterms: <http://purl.org/dc/terms/>
|
||||
prefix skos: <http://www.w3.org/2004/02/skos/core#>
|
||||
prefix schema: <http://schema.org/>
|
||||
prefix roru: <http://ld.rutishauser.info/rogerevents/>
|
||||
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: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
||||
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
||||
prefix dcterms: <http://purl.org/dc/terms/>
|
||||
prefix skos: <http://www.w3.org/2004/02/skos/core#>
|
||||
prefix schema: <http://schema.org/>
|
||||
prefix roru: <http://ld.rutishauser.info/rogerevents/>
|
||||
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: <https://www.ica.org/standards/RiC/ontology#>
|
||||
|
||||
SELECT DISTINCT ?resource ?s ?date
|
||||
WHERE {
|
||||
{
|
||||
?s rico:normalizedDateValue ?date .
|
||||
}
|
||||
UNION
|
||||
{
|
||||
?s rico:expressedDate ?date .
|
||||
}
|
||||
?s rico:hasOrHadCategory <http://docuteam.ch/vocab/types/unitdate> .
|
||||
<http://docuteam.ch/vocab/types/unitdate> ^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"))
|
||||
}
|
||||
```
|
||||
Loading…
Reference in New Issue
Block a user