sparql - How to remove Xml from query result - sparql

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX base: <http://www.cs7is1.com/ireland-school-county#>
SELECT ((COUNT(?school))/?a AS ?density)
WHERE {
?school base:inCounty base:DUBLIN.
base:area ?a
}
GROUP BY ?a
I run this query, query is fine but I am getting a result like this
"0.47776812"^^<http://www.w3.org/2001/XMLSchema#float>
I want to remove the XML content, I tried to bind it didn't work

Related

How to use simple vocabulary line with GeoSPARQL:sfWithin and polygon?

RDF:
prefix ex: <http://www.example.org/>
prefix geo: <http://www.opengis.net/ont/geosparql#>
ex:b7 a sf:Line ;
geo:asWKT "<http://www.opengis.net/def/crs/EPSG/0/4326> LINESTRING(55.3 -160.5,55.3 -160.5)^^geo:wktLiteral .
SPARQL query:
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
prefix geof: <http://www.opengis.net/def/function/geosparql/>
prefix sf: <http://www.opengis.net/ont/sf#>
prefix ex: <http://www.example.org/>
prefix ogis: <http://www.opengis.net/def/uom/OGC/1.0/>
select * where {
?a a sf:Line .
FILTER (geo:sfWithin(?a, "<http://www.opengis.net/def/crs/EPSG/0/4326> POLYGON((50 -170, 50 -140, 60 -140, 60 -170))"^^geo:wktLiteral))
}
In open-source edition of Virtuoso this results in the error:
Virtuoso 42000 Error RDFGE: RDF box with a geometry RDF type and a non-geometry content
Does the line also need to be declared as a geo:Geometry?
Edit: sf:Line is a subclass of geo:Geometry, so I assumed it could be used in the same fashion.

SPARQL query: show result for individuals without some attributes, and sum two of the attributes

I have to make this SPARQL query on protege:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX sw:<http://www.semanticweb.org/lorep/ontologies/2022/0/untitled-ontology-16#>
SELECT ?Name ?Surname ?test ?written ?oral ?Course
WHERE {
?Candidates sw:take_parts ?Course;
sw:Name ?Name;
sw:Surname ?Surname;
sw:test ?test;
sw:written ?written;
sw:oral ?oral;
}
Now I have some candidates that took only the test without taking written and oral so when I execute the query they does not show. How can I make everyone visible?
And then how could i sum the values from written and oral? I tried with BIND(?written+?oral AS ?total) but it doesn't seem to work

SPARQL Query filter values from another resource

I have a query made like this:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX sw: <http://www.semanticweb.org/lorep/ontologies/2021/7/untitled-ontology-3#>
SELECT ?Name ?Surname ?Birth ?y
WHERE {
?x sw:is_in ?y ;
sw:Name ?Name;
sw:Surname ?Cognome;
sw:Birth ?Birth;
}
Is there any way to filter from a specific value of the resource y?
I'm quite new to query so any help would be appreciated

Retrieve all individuals based on Data Property Assertions

I am trying to retrieve information based on Data Property Assertions in Protege (SPARQL Query), however, my code is not working. I am trying to get all individuals that were born after 1960.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?person ?birthYear
WHERE {
?a rdfs:label ?person .
?person xsd:hasBirthYear ?birthYear .
FILTER(?birthYear>=1960)
}

Yasgui SPARQL Query search for FOAF name doesn't work

I am using the Jamendo Yasgui SPARQL query to search for artist names. It works like this:
PREFIX mo: <http://purl.org/ontology/mo/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT * WHERE {?a a mo:MusicArtist ;foaf:name ?name;}
If I want to find a specific name like below, it does not work. Why?
PREFIX mo: <http://purl.org/ontology/mo/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT * WHERE {?a a mo:MusicArtist ;foaf:name "Carton";}
The data exists as you can see in the RDF/XML:
<foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Carton</foaf:name>
Because SPARQL syntax was built to look like Turtle syntax (and vice versa), it's often helpful to look at your data in Turtle when building SPARQL queries. This RDF/XML --
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE rdf:RDF><rdf:RDF xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:ns1="http://purl.org/ontology/mo/" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
<ns1:MusicArtist rdf:about="http://dbtune.org/jamendo/artist/5655">
<rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Resource"/>
<owl:sameAs rdf:resource="http://zitgist.com/music/artist/b8b40a3c-91c0-413b-a4f9-194ef0c7151a"/>
<foaf:based_near rdf:resource="http://sws.geonames.org/2802361/"/>
<foaf:homepage rdf:resource="http://cartonpate.com"/>
<foaf:img rdf:resource="http://img.jamendo.com/artists/c/carton.jpg"/>
<foaf:made rdf:resource="http://dbtune.org/jamendo/record/4957"/>
<foaf:name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Carton</foaf:name>
</ns1:MusicArtist>
</rdf:RDF>
-- says the same thing as this Turtle --
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
PREFIX owl: <http://www.w3.org/2002/07/owl#> .
PREFIX foaf: <http://xmlns.com/foaf/0.1/> .
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> .
<http://dbtune.org/jamendo/artist/5655>
a <http://purl.org/ontology/mo/MusicArtist>,
rdfs:Resource ;
owl:sameAs <http://zitgist.com/music/artist/b8b40a3c-91c0-413b-a4f9-194ef0c7151a> ;
foaf:based_near <http://sws.geonames.org/2802361/> ;
foaf:homepage <http://cartonpate.com> ;
foaf:img <http://img.jamendo.com/artists/c/carton.jpg> ;
foaf:made <http://dbtune.org/jamendo/record/4957> ;
foaf:name "Carton"^^xsd:string .
-- so your SPARQL query must be (modulo whitespaces, each of which may be reduced to a single space) --
PREFIX mo: <http://purl.org/ontology/mo/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT * WHERE { ?a a mo:MusicArtist ;
foaf:name "Carton"^^xsd:string }