Given This RDF:
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE rdf:RDF [<!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
<!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#'>
<!ENTITY xsd 'http://www.w3.org/2001/XMLSchema#'>]>
<rdf:RDF xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xml:base="http://www.example.org/"
xmlns:dnr="http://www.dotnetrdf.org/configuration#"
xmlns:nss="http://www.example.org/startTime"
xmlns:nse="http://www.example.org/endTime#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>
<rdf:Description rdf:about="Fadi">
<ns2914:be xmlns:ns2914="http://example.org/">May</ns2914:be>
<nss:startTime>00:00:13</nss:startTime>
<nse:endTime>00:00:16</nse:endTime>
</rdf:Description>
<rdf:Description rdf:about="Fadi">
<ns194:not xmlns:ns194="http://example.org/">Good</ns194:not>
<nss:startTime>00:00:19</nss:startTime>
<nse:endTime>00:00:21</nse:endTime>
</rdf:Description>
<rdf:Description rdf:about="She">
<ns195:be xmlns:ns195="http://example.org/">Good</ns195:be>
<nss:startTime>00:00:21</nss:startTime>
<nse:endTime>00:00:24</nse:endTime>
</rdf:Description>
</rdf:RDF>
how to get the startTime and endTime with query about Object?
i Tried to use:
PREFIX nss: <http://www.example.org/startTime>
PREFIX nse: <http://www.example.org/endTime#>
SELECT *
WHERE
{
?s ?p ?o .
FILTER(REGEX(?o, 'Good', 'i'))
?s nss:startTime ?startTime ;
nse:endTime ?endTime .
}
But it only gave me the first ?startTime and ?endTime For The Subject it find for Object Good.
I need The following answers:
?s,?p,?o,?startTime,?endTime
Fadi,not,Good,00:00:19,00:00:21
She,be,Good,00:00:21,00:00:24
Your query doesn't select that data so why are you surprised it isn't returned? As I suggested in the comment go read a good SPARQL tutorial like SPARQL by Example or pick up a copy of the excellent Learning SPARQL book from O'Reilly
The query you wrote selects triples where the object matches a regular expression and only those triples. If you want to select the start and end times as well you need to add additional patterns to your queries e.g.
PREFIX nss: <http://www.example.org/startTime>
PREFIX nse: <http://www.example.org/endTime#>
SELECT *
WHERE
{
?s ?p ?o .
FILTER(REGEX(?o, "May", "i"))
?s nss:startTime ?startTime ;
nse:endTime ?endTime .
}
Related
i want to get data with sparql from Medical Subject Headings RDF
i try to do this code :
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX meshv: <http://id.nlm.nih.gov/mesh/vocab#>
PREFIX mesh: <http://id.nlm.nih.gov/mesh/>
PREFIX mesh2015: <http://id.nlm.nih.gov/mesh/2015/>
PREFIX mesh2016: <http://id.nlm.nih.gov/mesh/2016/>
PREFIX mesh2017: <http://id.nlm.nih.gov/mesh/2017/>
SELECT DISTINCT ?descriptor ?label
FROM <http://id.nlm.nih.gov/mesh>
WHERE {
mesh:D009369 meshv:treeNumber ?treeNum .
?childTreeNum meshv:parentTreeNumber+ ?treeNum .
?descriptor meshv:treeNumber ?childTreeNum .
?descriptor rdfs:label ?label .
}
ORDER BY ?label
this code return
descriptor label
mesh:D000182 ACTH Syndrome, Ectopic
mesh:D049913 ACTH-Secreting Pituitary Adenoma
mesh:D000008 Abdominal Neoplasms
but me i want to get from this page for example https://meshb.nlm.nih.gov/record/ui?ui=D000172 :
Musculoskeletal Diseases [C05]
Bone Diseases [C05.116]
Bone Diseases, Endocrine [C05.116.132]
Acromegaly [C05.116.132.082]
Congenital Hypothyroidism [C05.116.132.256]
.........
but i want to collect all data (code with label) from mesh, not only this example
I know I'm not answering your question, but you are missing the rdfs prefix in the beginning...
PREFIX rdfs: http://www.w3.org/2000/01/rdf-schema#
Paul
I am using Apache Jena Fuseki Server for Storing Geo Coordinates of location. How to find out that if two polygons or two rectangles intersect each other inside Fuseki. Please share links related to it if possible. Thank you.
Hello...I am just updating question based on the below comments. Please suggest me regarding the problem I am facing. I have stored geocoordinates in WKT serialization format. When I execute below query
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX : <http://example.org/#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX spatial: <http://jena.apache.org/spatial#>
SELECT ?object
WHERE {
GRAPH <http://project/base/default> {
?subject geo:asWKT ?object .
} }
I get these below results.
object
1
"POLYGON((8.463699817657472 48.99872928913063,8.463887572288515 48.998644821906865,8.46399486064911 48.998764483764916,8.46425771713257 48.99865538031766,8.464375734329225 48.998746886450874,8.463919758796694 48.99893693711346,8.463699817657472 48.99872928913063))"
2
"POLYGON((8.463560342788698 48.99847940651206,8.463560342788698 48.99864834137738,8.46377491950989 48.99864834137738,8.46377491950989 48.99847940651206,8.463560342788698 48.99847940651206))"
3
"POLYGON((8.463447690010073 48.99835974396915,8.463447690010073 48.99849348443939,8.463646173477175 48.99849348443939,8.463646173477175 48.99835974396915,8.463447690010073 48.99835974396915))"
4
"POLYGON((8.463254570961 48.99821544463795,8.463254570961 48.99838438039854,8.463635444641115 48.99838438039854,8.463635444641115 48.99821544463795,8.463254570961 48.99821544463795))"
5
"POLYGON((8.463689088821413 48.99826823712468,8.463689088821413 48.99845477012966,8.46402168273926 48.99845477012966,8.46402168273926 48.99826823712468,8.463689088821413 48.99826823712468))"
6
"POLYGON((8.463892936706545 48.99843013373508,8.463892936706545 48.998588510344774,8.464316725730898 48.998588510344774,8.464316725730898 48.99843013373508,8.463892936706545 48.99843013373508))"
7
"POLYGON((8.463093638420107 48.99805354732974,8.463093638420107 48.998243600637835,8.463737368583681 48.998243600637835,8.463737368583681 48.99805354732974,8.463093638420107 48.99805354732974))"
8
"POLYGON((8.463619351387026 48.99797963751407,8.463619351387026 48.998180249615714,8.464118242263796 48.998180249615714,8.464118242263796 48.99797963751407,8.463619351387026 48.99797963751407))"
9
"POLYGON((8.464407920837404 48.998303432084754,8.464407920837404 48.99857443244431,8.46477270126343 48.99857443244431,8.46477270126343 48.998303432084754,8.464407920837404 48.998303432084754))"
10
"POLYGON((8.464225530624391 48.99806762537742,8.464225530624391 48.99839141937611,8.464820981025698 48.99839141937611,8.464820981025698 48.99806762537742,8.464225530624391 48.99806762537742))"
Then later I want to filter out these geo:WKT objects based on geo:intersection (Intersection or equals or contains methods). And I updated my query as below.
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX : <http://example.org/#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX spatial: <http://jena.apache.org/spatial#>
SELECT ?object
WHERE {
GRAPH <http://project/base/default> {
?subject geo:asWKT ?object .
?object geo:equals "POLYGON((8.463699817657472 48.99872928913063,8.463887572288515 48.998644821906865,8.46399486064911 48.998764483764916,8.46425771713257 48.99865538031766,8.464375734329225 48.998746886450874,8.463919758796694 48.99893693711346,8.463699817657472 48.99872928913063))"
} }
Which should result me atleast the coordinates of first geo object which really equals the POLYGON coordinates but I get empty results as shown in below image. Please suggest me where I am getting it wrong.
Continued on from another question here...
I have a(n excerpt from a) construct query below that is successfully pulling records as desired.
CONSTRUCT {
?publication fb:type ?type;
fb:publicationLabel ?publicationLabel;
fb:publicationType ?publicationTypeLabel;
fb:publicationLink ?publicationLink;
}
WHERE {
?publication a bibo:Document .
?publication rdfs:Label ?publicationLabel .
?publication vitro:mostSpecificType ?publicationType .
?publicationType rdfs:Label ?publicationTypeLabel .
?publication obo:ARG_2000028 ?vcard .
?vcard vcard:hasURL ?urllink .
?urllink vcard:url ?publicationLink
}
The above query (trimmed down a bit) currently works fine. I’m now trying to add the following variable: fb:linkInternalExists
To this variable, I want to bind the output of a conditional subquery that looks for a value (we’ll say “internal.url” for this example) within all the possible ?publicationLink values for a specific ?publication.
So the RDF output with the desired addition could return something like the following:
<rdf:Description rdf:about="https://abcd.fgh/individual/publication12345">
<fb:publicationLabel>example record 1</fb:publicationLabel>
<fb:publicationType>journal</fb:publicationType>
<fb:publicationLink>http://external.url/bcde</fb:publicationType>
<fb:publicationLink>http://external.url/abcd</fb:publicationType>
<fb:linkInternalExists>No</fb:linkInternalExists>
</rdf:Description>
<rdf:Description rdf:about="https://abcd.fgh/individual/publication23456">
<fb:publicationLabel>example record 2</fb:publicationLabel>
<fb:publicationType>conference paper</fb:publicationType>
<fb:publicationLink>http://external.url/2345</fb:publicationType>
<fb:publicationLink>http://external.url/1234</fb:publicationType>
<fb:publicationLink>http://internal.url/1234</fb:publicationType>
<fb:linkInternalExists>Yes</fb:linkInternalExists>
</rdf:Description>
My attempts at adding the required subquery to the above, and successfully bind its output to fb:linkInternalExists, have been unsuccessful. So my question is what would the modified query look like.
Regards
You don't actually need a subquery for this. All you need is an OPTIONAL pattern combined with a BIND expression.
The optional pattern should specifically look to find an internal link, like so:
OPTIONAL {
?vcard vcard:hasURL ?internal .
?internal vcard:url ?internalLink .
FILTER(CONTAINS(STR(?internalLlink), "internal.url")
}
or more concisely:
OPTIONAL {
?vcard vcard:hasURL/vcard:url ?internalLink .
FILTER(CONTAINS(STR(?internalLlink), "internal.url")
}
This clause will bind a value to ?internalLink if such a link exists, and leave it unbound otherwise. To then convert that to the output form you want, you can add the following conditional BIND-clause:
BIND (IF(BOUND(?internalLink), "Yes", "No") as ?internalLinkExists)
And then of course finally add the following to your CONSTRUCT-clause:
?publication fb:linkInternalExists ?internalLinkExists .
Upon trying Jeen Broekstra's approach, the query timed out, but it led me to trying other ways to isolate for the internalLink.
I tried the following instead, pulling both the publicationLink and the internalLink variables from distinct UNIONs.
{
?publication a bibo:Document.
?publication obo:ARG_2000028 ?vcard.
?vcard vcard:hasURL ?urllink.
?urllink vcard:url ?publicationLink .
}
UNION {
?publication a bibo:Document .
?publication obo:ARG_2000028 ?vcard .
?vcard vcard:hasURL/vcard:url ?internalLink .
FILTER(CONTAINS(STR(?internalLink), "internal.url"))
}
BIND (IF(BOUND(?internalLink), "Yes", "No") as ?internalLinkExists)
This successfully returned values for ?internalLink, and then the BIND added the Yes/No variable. Job done!
I have a problem, which I explain on following example:
I want to retrieve all information in any language on a category. I must use ?category as a label and the language labels en, as they are inputs in my program.
The query looks like this, but when I change the language I don't receive any information on the category. I know the problem lies in the dcterms:subject, because ?category returns http://dbpedia.org/resource/Category:Countries_in_Europe (see first example below).
For example to search for a category label in german you have to use http://de.dbpedia.org/resource/Kategorie:Staat_in_Europa (see second example below).
prefix dcterms: <http://purl.org/dc/terms/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?objectLabel WHERE {
?subject dcterms:subject ?category ; rdfs:label ?objectLabel
?category rdfs:label "Countries in Europe"#en .
FILTER (LANG(?objectLabel)='en')
}
Equivalent query in different language that doesn't work as example:
prefix dcterms: <http://purl.org/dc/terms/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?objectLabel WHERE {
?subject dcterms:subject ?category ; rdfs:label ?objectLabel
?category rdfs:label "Staat in Europa"#de .
FILTER (LANG(?objectLabel)='de')
}
Is there a similar or different way / method to solve the problem? Thanks in advance for any help.
I am working with Bio2RDF biological database and would like to get resource URL for Novobiocin which is [http://bio2rdf.org/drugbank:DB01051 ] using SPARQL query.Using yasgui.org I selected http://drugbank.bio2rdf.org/sparql service and executed the following query:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT ?resource WHERE { ?resource dcterms:identifier "drugbank:DB01051"}
However, It did not retrieve the result. Could you tell me why it does not work, please ?