Improve sparql query to extract all the words of different categories from a Dbnary (dbpedia) - sparql

I am trying to retrieve from Dbnary database based on dbpedia all words belongigs to categorie of noun, adjectif, adverb and verb and their synonyms.
So far I get can access it just for one categorie but I would like to know how to improve my query to get all words from the 4 categories and their synonym with only one query rather than making one query per category (i.e 4 query and 4 files)
#Query for noun which work
SELECT DISTINCT * where {
?l a ontolex:LexicalEntry;
lime:language "fr";
ontolex:canonicalForm ?f ;
lexinfo:partOfSpeech lexinfo:noun ;
ontolex:sense ?s .
?f ontolex:writtenRep ?w .
OPTIONAL { ?l dbnary:synonym ?syn ; rdfs:label ?synonyme .}
}
LIMIT 100
This query work , you can test it since dbnary in online : http://kaiko.getalp.org/sparql
but I wanted to upgrade the query below. When adding the following line on the previous query, it does not work :
#lexinfo:partOfSpeech lexinfo:verb ;
Any help will be fine.

Related

SPARQL Query to Identify Predicates from One of Many Graphs [duplicate]

This question already has an answer here:
SPARQL - Restricting Result Resource to Certain Namespace(s)
(1 answer)
Closed 4 years ago.
I have created an ontology by grouping together many ontologies.
I want to use SPARQL to identify all middle terms (relationships) from one ontology from the group ontology.
The following approach only produces a pyparsing error.
g = rdflib.Graph()
result = g.parse("without-bfo.owl")
qres = g.query(
""" PREFIX sudo: <http://purl.url/sudo/ontology#>
SELECT ?v
WHERE {
?s sudo:?v ?o.
}""")
If I remove the sudo: prefix, this query returns all triples.
You can check if the relation starts with your namespace with CONTAINS
SELECT ?v
WHERE {
?s ?v ?o.
FILTER CONTAINS(?v, "http://purl.url/sudo/ontology#")
}
You can also try STRSTARTS
see w3 documentation
#Arcturus was close.
The following worked for me. One has to declare ?v as a string using STR. This SO post suggested the syntax.
qres = g.query(
""" SELECT DISTINCT ?v
WHERE {
?s ?v ?o .
FILTER CONTAINS(STR(?v), "sudo")
}""")
for row in qres:
print row

Getting a list of available hierarchies from statistics.gov.scot

I'm interested in obtaining a list of available distinct hierarchies from statistics.gov.scot. The best-fit hierarchies, which I would like to list, are as follow:
http://statistics.gov.scot/def/hierarchy/best-fit#community-health-partnership
http://statistics.gov.scot/def/hierarchy/best-fit#council-area
http://statistics.gov.scot/def/hierarchy/best-fit#country
As available through API section of this sample geography.
Desired results
I would like for the desired results to return:
community-health-partnership
council-area
country
How can I construct query that would actually produce that, I can get a list of available all geographies via:
PREFIX sdmx: <http://purl.org/linked-data/sdmx/2009/dimension#>
SELECT DISTINCT ?framework
WHERE {
?a sdmx:refArea ?framework .
} LIMIT 10
I was trying something on the lines:
PREFIX fits: <http://statistics.gov.scot/def/hierarchy/best-fit#>
SELECT DISTINCT ?framework
WHERE {
?a fits ?framework .
} LIMIT 10
but naturally this syntax is not correct.
Starting on their SPARQL endpoint, you could do something like this --
DESCRIBE <http://statistics.gov.scot/def/hierarchy/best-fit#country>
Then, based on those results, you might try something like this, which results aren't exactly what you say you want, but might be better --
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?hierarchy
?label
WHERE
{ ?hierarchy rdfs:subPropertyOf <http://statistics.gov.scot/def/hierarchy/best-fit>
; rdfs:label ?label
}

SPARQL How to get the type of an individual

I made this ontology:
SensorOntology:MedicalCabinet-01 rdf:type owl:NamedIndividual ,
SensorOntology:MedicalCabinetSensor ;
SensorOntology:hasId "57"^^xsd:int ;
SensorOntology:hasValue "0"^^xsd:int .
I am trying to write a query to get the type of MedicalCabinet-01 which is MedicalCabinetSensor by given id number. However, I am printing owl:NamedIndividual and SensorOntology:MedicalCabinetSensor. Is it anyway I print just SensorOntology:MedicalCabinetSensor. This is my query:
SELECT DISTINCT ?sensor ?sensorclass
WHERE {?sensor :hasId "100"^^xsd:int.
?sensor rdf:type ?sensorclass}
There are multiple ways to ignore results, so it's not clear which one you want to use - especially since some are quite obvious. Here are two options:
As you tagged it with Jena, use Java and ignore resources whose URI matches owl:NamedIndividual.
Use a FILTER in SPARQL, i.e. add FILTER(?sensorclass != owl:NamedIndividual) to the graph pattern of the SPARQL query.
Indeed, there are multiple ways. Here's another:
SELECT DISTINCT ?sensor ?sensorclass
WHERE {?sensor :hasId "100"^^xsd:int.
?sensor rdf:type ?sensorclass
FILTER ( strstarts(str(?sensorclass), "[sensor ontology URI]") )
}

SPARQL search query

I have some RDF data structured like this:
[ pref:ip_address "127.0.0.1" ;
pref:time "1459630844.482" ;
pref:url "https://google.com" ;
pref:user "johndoe"
] .
I need query that will return all results matching given IP, time frame (between from time and end time), url (even partial match) and user (also even partial match).
What I have now is simple query to get results based on single value, like this:
PREFIX pref: <http://something> SELECT DISTINCT * WHERE { ?u pref:user USER_VALUE . ?u ?p ?o . }
This returns all results with given user but only if given username is full match. Meaning it will return all results for johndoe if USER_VALUE is johndoe but not if it is john.
My knowledge of SPARQL is extremely limited and I appreciate any help. Thank you.
To do anything more than exact match, you need to use a FILTER and use operations like CONTAINS or REGEX.
Example:
{ ?u pref:user ?user .
?u ?p ?o .
FILTER( CONTAINS(?user, "john") )
}
There are a number of FILTER functions that may be useful including REGEX. See the spec for details.

SPARQL query failing to match literal on Pubchem RDF data

I have loaded part of the PubChem RDF data in Virtuoso and am trying to use SPARQL to query it, through iSQL.
While the following query works:
SELECT ?syno ?type ?value
WHERE {
?syno sio:is-attribute-of <http://rdf.ncbi.nlm.nih.gov/pubchem/compound/CID1829049> .
?syno rdf:type ?type .
?syno sio:has-value ?value .
} LIMIT 10;
I am not able to get any results for a query like (the value being taken from one of the above results):
SELECT ?syno
WHERE {?syno sio:has-value "AC1LXI26"};
In the previous case, I am simply trying to match a litteral.
Do I need to build an extra index? Is exact text match not supported in Virtuoso?
I solved my problem by simply adding #en at the end of the query string!
SELECT ?syno
WHERE {?syno sio:has-value "AC1LXI26"#en};