get dbpedia type/category for any word - dbpedia

I am trying to get type/category to which the word belongs to like if its basketball then its under the category sports and if its tea then beverage is the category.
I tried :
select * where {basketball} LIMIT 100
and
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
PREFIX dbpprop: <http://dbpedia.org/property/>
PREFIX dbres: <http://dbpedia.org/resource/>
select ? {
a owl:basketball .
}
limit 10
also
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
PREFIX dbpprop: <http://dbpedia.org/property/>
PREFIX dbres: <http://dbpedia.org/resource/>
SELECT ?y WHERE {
?y dbpedia-owl:binomialAuthority dbres:basketball.
}
limit 10
but there is a query error especially if I dont know the property of the word typed.How can I get the name of the category.

May be you can query rdf:type of basketball.
PREFIX dbres: <http://dbpedia.org/resource/>
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
select ?o where {dbres:Basketball rdf:type ?o} LIMIT 10
Demo

Related

is there a method to select all categories MeSH with sparql

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

How to find the Polygons Intersection inside Apache Fuseki Server?

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.

Sparqlwrapper: Its not returning anything but the query is working with dbpedia.org/sparql

I have also added the snippet below. This query will return the name of the company uri, its name and parent company. It is working with DBpedia.org/sparql but not with sparqlwrapper(not returning anything; )
query1 = """
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX db: <http://dbpedia.org/resource/>
select distinct ?iri ?name ?parent (concat('[',group_concat(distinct ?location;separator=','),']') as ?location)
{
?iri a dbo:Company ;
rdfs:label ?label ;
foaf:name ?name
OPTIONAL { ?iri dbo:parentCompany ?parent.
filter (!isBlank(?parent)) }
OPTIONAL { ?iri dbo:location ?location.}
filter(regex(?name, "\\btata steel\\b","i" )) .
filter(regex(?label, "\\btata steel\\b","i" ))
}
GROUP BY ?iri ?name ?parent
"""
def get_country_description(query1):
sparql = SPARQLWrapper("http://dbpedia.org/sparql")
sparql.setReturnFormat('json')
sparql.setQuery(query1) # the previous query as a literal string
return sparql.query().convert()
get rid of \\b in your regex expression, and it works! (i dont know why it is needed as tata steel is a whole word)
Also you need to pass query1! to your function!
and use sparql.setReturnFormat('json') not JSON,
cheers

SPARQL DBpedia - Retrieve category information in any language by using labels

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.

sparql query - triple

I am a biology trying to understand the meaning of a triple from this SPARQL query. If "a" is a triple, what are the resources for subject, object and predicate in this sample query?
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX obo: <http://purl.obolibrary.org/obo/>
PREFIX sio: <http://semanticscience.org/resource/>
PREFIX efo: <http://www.ebi.ac.uk/efo/>
PREFIX atlas: <http://rdf.ebi.ac.uk/resource/atlas/>
PREFIX atlasterms: <http://rdf.ebi.ac.uk/terms/atlas/>
SELECT DISTINCT ?experiment ?description WHERE
{?experiment
a atlasterms:Experiment ;
dcterms:description ?description ;
atlasterms:hasAssay
[atlasterms:hasSample
[atlasterms:hasSampleCharacteristic
[ atlasterms:propertyType ?propertyType ;
atlasterms:propertyValue ?propertyValue]
]
]
filter regex (?description, "diabetes", "i")
}
I appreciate your help?
Thanks,
AD
?experiment
a atlasterms:Experiment ;
is the same as
?experiment a atlasterms:Experiment ;
is the same as
?experiment rdf:type atlasterms:Experiment ;
so the form in the query is just a whitespace rearrangement and using the built-in abbreviation "a" for property rdf:type.
See http://www.sparql.org/query-validator.html for an online formatter of SPARQL queries.
A simpler query is:
SELECT DISTINCT ?experiment ?description
WHERE
{ ?experiment rdf:type atlasterms:Experiment .
?experiment dcterms:description ?description
FILTER regex(?description, "diabetes", "i")
}
because
SELECT DISTINCT ?experiment ?description
means that the ?propertyType/?propertyValue part is not affecting the outcome.

Resources