Ontology SPARQL basic query

What are the advantages of SPARQL?

  • SPARQL can fetch results/data from structured and semi-structured data.
  • SPARQL can handle complex joins and relationships
  • SPARQL can help to find the data by running queries of unknown relationships.
  • SPARQL can transform RDF data into different vocabulries.

What is mean by RDF triples?

RDF triples are

  1. Subject
  2. Predicate
  3. Object

What are literals?

Literal is the lexical representation of values such as numbers and dates. 

A literal can be the object but it can’t be subject or predicate.

Representation of literals = Representation of URI

SELECT *
WHERE{
?S ?P ?O
}
limit 10

Example:

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name
WHERE {
?person a foaf:Person.
?person foaf:name ?name
}
LIMIT 10

Note: It will show the name of from the DBpedia database. Output can be like this;

Output:

name
“Akram”@en
“Ali”@en
“Azhar:@en

Explanation:

Akram is the name of the person and en indicates that Akram name is a word of English languages.

Example 2:

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?age
WHERE {
?person a foaf:Person;
foaf:name ?name.
OPTIONAL {?person foaf:age ?age}
}

challan2