SPARQL HTML result displaying in next line - sparql

I'm executing SPARQL query on virtuoso SPARQL editor.
The result of query in HTML format is displaying in next line for each corresponding record as shown on below image:
Kindly advise how to resolve this display issue.
Here is the SPARQL query:
prefix DOL: <http://www.MyOnt.com/something/v1#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
select ?cName ?domain ?dValues ?method ?rType{
{
?class foaf:name "MyJavaClass" .
}
{ ?class foaf:name ?cName }
union
{ ?class DOL:belongsTo ?domain }
union
{ ?class2 DOL:domainName ?dValues }
union
{ ?class DOL:hasMethod ?method }
union
{ ?class2 DOL:returnType ?rType }
}
SPARQL output on virtuoso

UNION is for matching alternatives, so that the results of your query would match any of the patterns joined by UNION. If you want the results to match all the triple patterns in your query, you just group them:
PREFIX DOL: <http://www.MyOnt.com/something/v1#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?cName ?domain ?dValues ?method ?rType
WHERE {
?class foaf:name "MyJavaClass" ;
DOL:belongsTo ?domain ;
DOL:hasMethod ?method .
?class2 DOL:domainName ?dValues ;
DOL:returnType ?rType .
}
If you want the results to match only some of the triple patterns, you can use OPTIONAL to wrap the patterns that the results don't need to match, such as in the following:
PREFIX DOL: <http://www.MyOnt.com/something/v1#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?cName ?domain ?dValues ?method ?rType
WHERE {
?class foaf:name "MyJavaClass" ;
DOL:belongsTo ?domain .
OPTIONAL {
?class DOL:hasMethod ?method .
}
?class2 DOL:domainName ?dValues ;
DOL:returnType ?rType .
}

Related

SPARQL help to build modify query

I have to add a few new fields to existing report. Our system already have a lot of reports with types AccountTeamBodReport, CoordinatorBodReport. Also I want to set default value for new fields.
PREFIX : <http://example.com/knowledge-black-belt#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
INSERT { ?s :hasResult "" ; //(new fields)
:hasResultPriority "MEDIUM";
:hasLowMarginComments "";
:hasLowMarginCommentsPriority "MEDIUM";
}
WHERE
{ ?s rdf:type ?type ;
FILTER ( ?type IN (:AccountTeamBodReport, :CoordinatorBodReport) )
}
It doesn't work. There is any errors. What I did wrong? I use fuseki server and check all my query there. Fuseki logs have only successful responds. When I want to see specific report I use:
PREFIX : <http://dataart.com/knowledge-black-belt#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT *
WHERE
{ ?s :hasId ?name ;
rdf:type ?type ;
:hasCreationTime ?created ;
:hasReportMonth ?reportMonth ;
:hasAchievements ?achievements ;
:hasAchievementsPriority ?achievementsPriority ;
:hasRisksIssues ?risksIssues ;
:hasRisksIssuesPriority ?risksIssuesPriority ;
:hasOther ?other ;
:hasOtherPriority ?otherPriority ;
:hasPerformance ?performance ;
:hasCustomerRelationship ?customerRelationship ;
:hasTeamMorale ?teamMorale ;
:hasNoNews ?noNews ;
:hasResult ?result ;
:hasResultPriority ?resultPriority;
:hasLowMarginComments ?lowMarginComments;
:hasLowMarginCommentsPriority ?lowMarginCommentsPriority;
:hasClient ?client
OPTIONAL
{ ?s :hasIndicatorDescription ?indicatorDescription}
?s rdf:type ?type ;
:hasClient :clientSomeId
FILTER ( ?type IN (:AccountTeamBodReport, :CoordinatorBodReport) )
}
And there is any changes after Insert query.

Duplicated results from Wikidata

I created the following SPARQL query to Wikidata. And the result of this query are records related to states in Germany. But as you can see, results are occurring four times in a row (you can test it here: https://query.wikidata.org/). I supposed that there is a problem with geo coordinates and languages but I can't resolve it anyway. What is wrong with this query and how can I fix it to receive a result without repetition?
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX schema: <http://schema.org/>
PREFIX psv: <http://www.wikidata.org/prop/statement/value/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT DISTINCT ?subject ?featureCode ?countryCode ?name ?latitude ?longitude ?description ?iso31662
WHERE
{ ?subject wdt:P31 wd:Q1221156 ;
rdfs:label ?name ;
wdt:P17 ?countryClass .
?countryClass
wdt:P297 ?countryCode .
?subject wdt:P31/(wdt:P279)* ?adminArea .
?adminArea wdt:P2452 "A.ADM1" ;
wdt:P2452 ?featureCode .
?subject wdt:P300 ?iso31662
OPTIONAL
{ ?subject schema:description ?description
FILTER ( lang(?description) = "en" )
?subject p:P625 ?coordinate .
?coordinate psv:P625 ?coordinateNode .
?coordinateNode
wikibase:geoLatitude ?latitude ;
wikibase:geoLongitude ?longitude
}
FILTER ( lang(?name) = "en" )
FILTER EXISTS { ?subject wdt:P300 ?iso31662 }
}
ORDER BY lcase(?name)
OFFSET 0
LIMIT 200
In short, "9.0411111111111"^^xsd:double and "9.0411111111111"^^xsd:decimal are distinct, though they might be equal in some sense.
Check this:
SELECT DISTINCT ?subject ?featureCode ?countryCode ?name ?description ?iso31662
(datatype(?latitude) AS ?lat)
(datatype(?longitude) AS ?long)
and this:
SELECT DISTINCT ?subject ?featureCode ?countryCode ?name ?description ?iso31662
(xsd:decimal(?latitude) AS ?lat)
(xsd:decimal(?longitude) AS ?long)

SPARQL Query for all Books by George Orwell

I created this query to return all books that are notable works by George Orwell but it returns no result.
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/resource/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?title where {
?person foaf:name ?name .
?title dbo:author ?person .
?title dbo:notableWork dbp:George_Orwell .
}
I cannot seem to figure out why there is no result.
I am running the query in http://dbpedia.org/snorql
Don't you have the triples about notable works in the wrong order?
Try rewriting based on this working query
SELECT *
WHERE {
:George_Orwell dbo:notableWork ?title
}
.
title
:Nineteen_Eighty-Four
:Animal_Farm
You can also bind :George_Orwell to a variable and ask more about that:
SELECT *
WHERE {
values ?author { :George_Orwell } .
?author rdfs:label ?l .
?title ?p ?author .
?title rdf:type dbo:Book .
filter (lang(?l) = "en")
}
and DESCRIBE things
describe :Animal_Farm

sparql exclude multiple type hierarchy

In dbpedia I select some pages with label starting 'A'. Here I'm using additional filter by subject to narrow the set. In original version there are another conditions (result set is much bigger)
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX purl: <http://purl.org/dc/terms/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX : <http://dbpedia.org/page/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX dbr: <http://dbpedia.org/resource/>
SELECT DISTINCT
?pageType
WHERE
{
{
?page rdfs:label ?label .
?page a ?pageType .
?page <http://purl.org/dc/terms/subject> <http://dbpedia.org/resource/Category:Banking> .
}
FILTER ( strstarts(str(?pageType), 'http://dbpedia.org/ontology') )
}
LIMIT 1000
sparql results
Here I select only page types to be clear with rest of the question.
This is the whole set. Now I want to exclude some pages. Exclude all agents (persons, organization etc):
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX purl: <http://purl.org/dc/terms/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX : <http://dbpedia.org/page/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX dbr: <http://dbpedia.org/resource/>
SELECT DISTINCT
?pageType
WHERE
{
{
?page rdfs:label ?label .
?page a ?pageType .
?page <http://purl.org/dc/terms/subject> <http://dbpedia.org/resource/Category:Banking> .
MINUS { ?page a dbo:Agent }
}
FILTER ( strstarts(str(?pageType), 'http://dbpedia.org/ontology') )
}
LIMIT 1000
The result.
Ok. Then I want to exclude more types, for example Written_Work. I tried different approaches, but unabled to find the correct one.
This returns nothing:
WHERE
{
{
?page rdfs:label ?label .
?page a ?pageType .
?page <http://purl.org/dc/terms/subject> <http://dbpedia.org/resource/Category:Banking> .
MINUS { ?page a dbo:Agent }
MINUS { ?page a dbo:WrittenWork }
}
This is like no filter is set:
WHERE
{
{
?page rdfs:label ?label .
?page a ?pageType .
?page <http://purl.org/dc/terms/subject> <http://dbpedia.org/resource/Category:Banking> .
MINUS { ?page a dbo:Agent, dbo:WrittenWork }
}
The question is:
what way should I go to exclude pages of certain types (direct and superclass)?
It look's like this is working answer (how to exclude multiple of types)
{
?page purl:subject ?id .
?page a ?pageType .
FILTER NOT EXISTS {
?page a/rdfs:subClassOf* ?skipClasses .
FILTER(?skipClasses in (dbo:Agent, dbo:Place, dbo:Work))
}
}
In this example all dbo:Agents, db:Places, dbo:Works will be filtered out.

Sparql of DbPedia based upon name not subject

I am trying to query dbpedia to get some people data and I don't have subjects just names of the people I want to query and their birth/death dates.
I am trying to do a query along these lines. I want the name, birth date, death date and thumbnail of everyone with the surname Presley. What I then intend to do is loop through the results returned and find the best match for Elvis Presley 1935-1977 which is the data I have.
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?Name ?thumbnail ?birthDate ?deathDate WHERE {
{
dbo:name ?Name ;
dbo:birthDate ?birthDate ;
dbo:birthDate ?deathDate ;
dbo:thumbnail ?thumbnail ;
FILTER contains(?Name#en, "Presley")
}
What is the best way to construct my sparql query?
UPDATE:
I have put together this query which seems to work to some extent but I don't entirely understand it, and I can't figure out the contains, but it does at least run and return results.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?subject ?thumbnail ?birthdate ?deathdate WHERE {
{
?subject rdfs:label "Elvis Presley"#en ;
dbo:thumbnail ?thumbnail ;
dbo:birthDate ?birthdate ;
dbo:deathDate ?deathdate ;
a owl:Thing .
}
UNION
{
?altName rdfs:label "Elvis Presley"#en ;
dbo:thumbnail ?thumbnail ;
dbo:birthDate ?birthdate ;
dbo:deathDate ?deathdate ;
dbo:wikiPageRedirects ?s .
}
}
Some entities might not have all of that information, so it's better to use optional. You can use foaf:surname to check for surname directly.
select * where {
?s foaf:surname "Presley"#en
optional { ?s dbo:name ?name }
optional { ?s dbo:birthDate ?birth }
optional { ?s dbo:deathDate ?death }
optional { ?s dbo:thumbnail ?thumb }
}