Show triples containing a text pattern. The bif:search_excerpt
is used to format a short excerpt of
the matching literal in search-engine style.
This query requires V6 or higher.
SELECT ?s
?p
( bif:search_excerpt
( bif:vector
( 'web', 'semantic' ) ,
?o
)
)
WHERE
{
?s ?p ?o .
FILTER
(
bif:contains
( ?o, '"semantic web"' )
)
}
LIMIT 10
## See LOD live results.
What sources talk the most about a given subject? Show the top N graphs containing triples with the given text pattern. Sort by descending triple count.
This query requires V6 or higher.
SELECT ?g
COUNT (*)
WHERE
{
GRAPH ?g
{
?s ?p ?o .
FILTER
(
bif:contains
( ?o, 'dakar AND paris' )
)
}
}
GROUP BY ?g
ORDER BY DESC 2
LIMIT 50
## See LOD live results.
What types of objects contain a text pattern? Find matches, get the type. Group by type, order by count.
This query requires V6 or higher.
SELECT ?tp
COUNT (*)
WHERE
{
GRAPH ?g
{
?s ?p ?o .
?s a ?tp
FILTER
(
bif:contains
( ?o, '"Paris Hilton"' )
)
}
}
GROUP BY ?tp
ORDER BY DESC 2
LIMIT 10
## See LOD live results.
Given a person, find people with the most interests in common with this person. Show the person, the number of shared interests, and the total number of interests.
This query requires V6 or higher.
SELECT ?p
?n
((
SELECT COUNT (*)
WHERE
{
?p foaf:interest ?i .
?ps foaf:interest ?i
}
))
((
SELECT COUNT (*)
WHERE
{
?p foaf:interest ?i
}
))
WHERE
{
?ps foaf:nick "brisch"@en .
{
SELECT DISTINCT ?p
?psi
WHERE
{
?p foaf:interest ?i .
?psi foaf:interest ?i
}
} .
FILTER
( ?ps = ?psi )
?p foaf:nick ?n
}
ORDER BY DESC 3
LIMIT 50
## See LOD live results.
What else are people interested in X interested in? What else do Harry Potter fans like?
This query requires V6 or higher.
SELECT ?i2
COUNT (*)
WHERE
{
?p foaf:interest <http://dbpedia.org/resource/Semantics> .
?p foaf:interest ?i2
}
GROUP BY ?i2
ORDER BY DESC 2
LIMIT 20
## See LOD live results.
Who writes the most about a topic? Show for each author the number of works mentioning the topic and total number of works. For all documents and posts, we have extracted named entities; the entity count shows the entities which occur in the works of each author. There are statistics about named entities occurring together; these are used to display a list of related entities.
This query requires V6 or higher.
SELECT ?auth
?cnt
((
SELECT COUNT (DISTINCT ?xx)
WHERE
{
?xx dc:creator ?auth
}
))
WHERE
{
{
SELECT ?auth
COUNT (DISTINCT ?d) AS ?cnt
WHERE
{
?d dc:creator ?auth .
?d ?p ?o
FILTER
(
bif:contains
( ?o, 'web AND semantic' )
&&
isIRI ( ?auth )
)
}
GROUP BY ?auth
ORDER BY DESC 2
LIMIT 100
}
}
## See LOD live results.
Show the people a person directly or indirectly knows. Sort by distance and count of connections of the known person.
This query requires V6 or higher.
SELECT ?o
?dist
((
SELECT COUNT (*)
WHERE
{
?o foaf:knows ?xx
}
))
WHERE
{
{
SELECT ?s ?o
WHERE
{
?s foaf:knows ?o
}
}
OPTION (
TRANSITIVE ,
T_DISTINCT ,
T_IN ( ?s ) ,
T_OUT ( ?o ) ,
T_MIN ( 1 ) ,
T_MAX ( 4 ) ,
T_STEP ( 'step_no' ) AS ?dist
) .
FILTER
(
?s = <http://www.w3.org/People/Berners-Lee/card#i>
)
}
ORDER BY ?dist
DESC 3
LIMIT 50
## See LOD live results.
Given two people, find what chain of acquaintances links them together. For each step in the chain, show the person linked to, the graph linking this person to the previous person, the number of the step, and the number of the path. Note that there may be many paths through which the people are linked.
This query requires V6 or higher.
SELECT ?link
?g
?step
?path
WHERE
{
{
SELECT ?s
?o
?g
WHERE
{
GRAPH ?g
{
?s foaf:knows ?o
}
}
}
OPTION
(
TRANSITIVE ,
T_DISTINCT ,
T_IN ( ?s ) ,
T_OUT ( ?o ) ,
T_NO_CYCLES ,
T_SHORTEST_ONLY ,
T_STEP ( ?s ) AS ?link ,
T_STEP ( 'path_id' ) AS ?path ,
T_STEP ( 'step_no' ) AS ?step ,
T_DIRECTION 3
) .
FILTER
(
?s = <http://www.w3.org/People/Berners-Lee/card#i>
&&
?o = <http://myopenlink.net/dataspace/person/kidehen#this>
)
}
LIMIT 20
## See LOD live results.
This query requires V6 or higher.
# Show names of things surrounding a person. These
# may be interests, classes of things, other people, and
# so forth. For each link shows the count of occurrences
# largest count first.
SELECT ?s
?lbl
COUNT (*)
WHERE
{
?s ?p2 ?o2 .
?o2 <http://yago-knowledge.org/resource/linksTo> ?lbl .
?s foaf:nick ?o .
FILTER
(
bif:contains
( ?o, '"King"' )
)
}
GROUP BY ?s
?lbl
ORDER BY DESC 3
LIMIT 10
## See LOD live results.
This example shows how to extract a part of a literal as a variable for use in a numeric comparison.
Suppose there are the following triples inserted:
SQL>sparql
insert into graph <http://b3s-demo.openlinksw.com/label> { <:a>
<:p>
"123 abc" };
callret-0
VARCHAR
_________________________________________________________
Insert into <http://b3s-demo.openlinksw.com/label>, 1 triples -- done
1 Rows. -- 30 msec.
SQL>sparql
insert into graph <http://b3s-demo.openlinksw.com/label> { <:a>
<:p>
"234 abc" };
callret-0
VARCHAR
_________________________________________________________
Insert into <http://b3s-demo.openlinksw.com/label>, 1 triples -- done
1 Rows. -- 0 msec.
In order to extract the numeric part, and then do a numeric ( >.<,= ), you can use atoi (), atol or atof in the filter:
SELECT *
FROM <http://b3s-demo.openlinksw.com/label>
WHERE
{
?s ?p ?o .
FILTER (bif:atoi (?o) > 130)
}
## See LOD live results.