### Optimized version using sub quer SELECT DISTINCT ?s1 as ?href, ?name, (bif:search_excerpt (bif:vector ('ceo'), ?o1)) as ?excerpt, ?sc, ?image, (?s1) as ?rank WHERE { { { SELECT DISTINCT * FROM WHERE { ?s1 ?s1textp ?o1 . optional {?s1 foaf:depiction ?image} . ?o1 bif:contains '"ceo"' option (score ?sc). ?s1 a dbpedia-owl:Person. optional {?s1 rdfs:label ?name}. FILTER (lang(?o1) = "en") FILTER (lang(?name) = "en") } ORDER BY DESC (?sc * 3e-1 + sql:rnk_scale ( (?s1))) LIMIT 100 } } } ### ### Costly version modulo sub query SELECT DISTINCT ?s1 as ?href, ?name, (bif:search_excerpt (bif:vector ('ceo'), ?o1)) as ?excerpt, ?sc, ?image, (?s1) as ?rank WHERE { { { SELECT DISTINCT * WHERE { ?s1 ?s1textp ?o1 . optional {?s1 foaf:depiction ?image} . ?o1 bif:contains '"ceo"' option (score ?sc). ?s1 a dbpedia-owl:Person. optional {?s1 rdfs:label ?name}. FILTER (lang(?o1) = "en") } ORDER BY DESC (?sc * 3e-1 + sql:rnk_scale ( (?s1))) } } } LIMIT 100 ## PREFIX yago: PREFIX prop: SELECT DISTINCT ?s2 AS ?c1 ( (?s2) ) as ?Rank WHERE { ?s1 ?s1textp ?o1 . ?o1 bif:contains 'Shakespeare' . ?s1 a yago:Writer110794014 . ?s2 prop:writer ?s1 } ORDER BY DESC ( (?s2) ) LIMIT 20 OFFSET 0 ## 6 Degrees connectivity between artists in DBpedia ## Default: Nas select ?s as ?Artist ?o as ?associated_artist ?dist as ?degrees_of_separation where { { select ?s ?o where { ?s ?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= ) } order by ?dist desc 3 limit 100 ## Show the bands associated (max 4 degrees of separation) with Grateful Dead entity in DBpedia. ## Sort by distance (degrees of separation) and connection count ## select ?s as ?Band ?o as ?associated_grp ?dist as ?degrees_of_separation ( ( select count ( * ) where { ?o ?xx } ) ) as ?3rd_party_association_count where { { select ?s ?o where { ?s ?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= ) } order by ?dist desc 3 limit 100 ## Show the bands associated (max 4 degrees of separation) with Grateful Dead entity in DBpedia. select ?s as ?Band ?o as ?associated_grp ?dist as ?degrees_of_separation where { { select ?s ?o where { ?s ?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= ) } order by ?dist desc 3 limit 100 ## Show the bands associated (max 4 degrees of separation) with Grateful Dead entity in DBpedia. ## Sort by DESC distance (degrees of separation) select ?s as ?Band ?o as ?associated_grp ?dist as ?degrees_of_separation where { { select ?s ?o where { ?s ?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= ) } order by desc ( (?o) ) limit 100 ## Show the bands associated (max 4 degrees of separation) with Grateful Dead entity in DBpedia. ## Sort by DESC entity Rank select ?s as ?Band ?o as ?associated_grp ?dist as ?degrees_of_separation ( (?o)) as ?enity_rank where { { select ?s ?o where { ?s ?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= ) } order by desc 4 limit 100 ## Finding what Connects to Entities ## Example: ## Connecting Nas to Grateful Dead select ?link ?g ?step ?path ( (?o) ) as ?entity_rank where { { select ?s ?o ?g where { graph ?g { ?s ?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= && ?o = ) } ORDER BY DESC 5 LIMIT 20 ##Show the people a person knows directly or indirectly that aren't blank nodes. ##Order by distance (degrees of separation) and count of connections of the known person select ?o as ?knowee ?dist as ?degrees_of_separation ( ( select count ( * ) where { ?o foaf:knows ?xx } ) ) as ?knowee_connections where { { select ?s ?o where { ?s foaf:knows ?o. filter (!isBlank (?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= ) } order by ?dist desc 3 limit 50 ##Show the people a person directly or indirectly knows. ## Sort by Entity Rank (Entity Link Coefficient a la Page Rank) of the host Quad Store.Thus, results will vary ## Replenish local cache by fetching FOAF profile doc via Sponger pragmas define get:soft "replace" select ?o ?dist ( ( select count ( * ) from where { ?o foaf:knows ?xx } ) ) from 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= ) } order by desc ( (?o) ) limit 100 ##Show the people a person directly or indirectly knows. ## Replenish local cache by fetching FOAF profile and then crawl designated paths ### courtesy of Sponger pragmas for depth- and breadth-wise (selected property paths) crawling define input:grab-var "o" define input:grab-follow-predicate foaf:knows define input:grab-depth 5 define input:grab-limit 50 select ?o ?dist ( ( select count ( * ) from where { ?o foaf:knows ?xx } ) ) as ?count from 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= ) } order by ?dist desc 3 limit 100