当前位置:网站首页>SPARQL learning notes of query, an rrdf query language

SPARQL learning notes of query, an rrdf query language

2022-06-25 14:47:00 HELLOWORLD2424

SPARQL query Learning from

This article mainly records SPARQL The learning process and demo Results of operation , This practice project is based on apache-jena-fuseki,demo The database file for is kg-demo-for-movie

1. Check all the links with movieTitle= Chill related triples

PREFIX : <http://www.kgdemo.com#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT * WHERE {
?x :movieTitle ' chills '.
?x ?p ?o.
}

Query results
 Insert picture description here

2. Yes 1 Format the results in , Display only predicate Predicate sum object object

PREFIX : <http://www.kgdemo.com#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?p ?o WHERE {
?x :movieTitle ' chills '.
?x ?p ?o.
}

Query results
 Insert picture description here

3. Use CONCAT Format all movie titles and release times

PREFIX : <http://www.kgdemo.com#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT (CONCAT("movie name: ", ?name, " release: ", ?date)) WHERE {
?x :movieTitle ?name.
?x :movieReleaseDate ?date.
}

Query results
 Insert picture description here

4. Use BIND Key words put 3 Copy the results found in to info Variable

PREFIX : <http://www.kgdemo.com#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?info  WHERE {
?x :movieTitle ?name.
?x :movieReleaseDate ?date.
BIND (CONCAT("movie name: ", ?name, " release: ", ?date) AS ?info)
}

Query results
 Insert picture description here

5. Use CONSTRUCT Keyword query and build RDF Return after drawing

PREFIX : <http://www.kgdemo.com#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

CONSTRUCT {?x :movieTitle ?name}  WHERE {
?x :movieTitle ?name.
}

Query results
 Insert picture description here

6. Use FILTER Field to filter the results

Select to ’' cold " Is the name of the movie that begins

PREFIX : <http://www.kgdemo.com#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?name WHERE {
?x :movieTitle ?name.
  FILTER regex(?name, "^ cold ")
}

Query results
 Insert picture description here

7. Use OPTIONAL Keyword to build a variety of query patterns

PREFIX : <http://www.kgdemo.com#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT  ?name  ?date WHERE {
?x :movieTitle ?name.
OPTIONAL {?x :movieReleaseDate ?date}
}

In the above statement ,optional The condition inside is the second match
 Insert picture description here

原网站

版权声明
本文为[HELLOWORLD2424]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202200519299867.html