I'm trying to make a sparql query to: http://sparql.lynx-project.eu/
The graph: http://sparql.lynx-project.eu/graph/eurovoc
Which contains some entries with brackets in the prefLabel i.e. "sanction (EU)".
I'm trying to retrieve such exact match of such entries with:
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT ?c ?label
WHERE {
GRAPH <http://sparql.lynx-project.eu/graph/eurovoc> {
?c a skos:Concept .
?c ?p ?label.
FILTER regex(?label, "^sanction (EU)$", "i" )
FILTER (lang(?label) = "en")
FILTER (?p IN (skos:prefLabel, skos:altLabel ) )
}
}
It doesn't return anything. Also tried to escape the brackets with backslash but the query breaks. Do you know how to escape brackets in a sparql string?? thanks in advance!
Related
I'm trying to make a query that filters by a string param with this format:
filter: (status~contains~false~and~username~contains~'admin')
So, i need to make a search() in this request.input('filter') and search the word after the contains to make my query. I'm with difficulty to make the regex (i don't know if i really need a regex)
Something like:
if(request.input('filter').search('regex??'))
queryUsers.where('username', 'like', '%'+request.input('username')+'%')
Tried:
if(filter.search("username")){
let userName = filter.search(/?<=username~contains~).*$/g).replace("'", "")
console.log(userName)
//queryUsers.where('username', 'like', '%'+request.input('username')+'%')
}
But i receive:
Invalid regular expression: /?<=username~contains~).*$/: Nothing to
repeat
No need to use regular expression you can run like query as below -
Database.from('users').whereRaw('username Like ?', ['%'+request.input('username')+'%'])
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
How to search full or partial match with first name and last name in mongodb?
I tried using this,
{"name":{ $regex: str, $options: 'i'}}
But it is only for full match of the string.
Can I use regex for partial match?
For this type of search better to create text index. mongo shell command to create text index for name field.
db.colectionName.createIndex( { name: "text" } );
then you can search using $text and $search
var text = 'John Test''
db.collectionName.find({ $text: { $search: text } });
for this query you will get if name contain john or test and this is case insensitive
I have to do this for my project, how does this work for you? {"name":new RegExp('^'+name, 'i')} you may need to encode the string first str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
Try this
{'name': {'$regex': '.*str.*', $options: 'i'}}
I have responded to similar question here, combining text index and regex pattern makes it work nicely. Note, text index is searching by terms so if you try to search for padavan by supplying pad you won't get what you are expecting having only text index in place.
I cannot find where to quote a field name that has a space in it, for example when doing
FILTER s._key = a.`Supplier Id`
The above, sql-style quote doesn't work, neither does array access. What's the correct way?
Figured it out now, I got bitten by SQL and forgot that equality comparison is made with == in AQL. Then the array access worked, so the way to use field names with spaces is this:
FILTER s._key == a['Supplier Id']
If the field is without spaces but has some special characters, it works to use backtick instead of array access:
FILTER s._key == a.`ÅterförsäljareId`
Edit: Another option is to use bind variables:
FILTER s._key == a.#field
// Passing this to the API as bind variables:
{
"field": "Supplier Id"
}
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.