SPARQL INSERT/DELETE - insert

I need some help to write my update query.
DELETE {
?contactInfo vivo:freeTextValue5 ?o .
}
INSERT {
?contactInfo vivo:freeTextValue5 "new_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
WHERE {
?contactInfo vivo:freeTextValue5 "old_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
Can you please let me know what is wrong with this "update" query?

I'm guessing that your problem is that this update adds a new triple, but does not remove the old one.
The reason is that your DELETE clause contains an unbound variable: ?o. This is not allowed - or at least what happens is that patterns with unbound variables are simply ignored by the SPARQL engine. So your DELETE won't actually remove any triples. The variable ?o needs to be bound to a value in your WHERE clause.
One way to fix this is to just replace ?o with the specific value:
DELETE {
?contactInfo vivo:freeTextValue5 "old_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
INSERT {
?contactInfo vivo:freeTextValue5 "new_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
WHERE {
?contactInfo vivo:freeTextValue5 "old_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
More generally, you can use a VALUES clause to bind ?o to a value, like this:
DELETE {
?contactInfo vivo:freeTextValue5 ?o.
}
INSERT {
?contactInfo vivo:freeTextValue5 "new_url"^^<http://www.w3.org/2001/XMLSchema#string> .
}
WHERE {
VALUES ?o { "old_url"^^<http://www.w3.org/2001/XMLSchema#string> }
?contactInfo vivo:freeTextValue5 ?o.
}
This is perhaps the better approach as it makes it easier to extend your update to different values for ?o.

Related

I have two jsonata files but i have to take particular field from jsonata1 and merge that particular field in jsonata2

For example
Json1:
{
"Data":"123",
"Data1":"345"
}
Jsonata1:
{
"Data":$.Data,
"Data1":$.Data1
}
Json2:
{
"Prod":"675",
"Prod2":"564"
}
Jsonata2:
{
"Prod":$.Data
}
How can I use like this if u observed my jsonata2 I call the jsonata1 feild data
I can't find any suggestions
Please help me resolve the issue

Only select shortest value for column with multiple values on Wikidata query

I have the following query:
SELECT ?admin ?name ?abbr
WHERE {
VALUES ?admin { wd:Q771 }
?admin wdt:P131 ?country;
wdt:P17 ?country.
OPTIONAL { ?admin wdt:P1813 ?alias. }
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en".
?admin rdfs:label ?name.
?alias rdfs:label ?abbr.
}
}
This retrieves the administration in VALUES with its English name and abbrevations, if available. For example:
admin
name
abbr
wd:Q771
Massachusetts
MA
wd:Q771
Massachusetts
Mass.
Now I would like to filter it such that only the shortest abbreviation is displayed. For the above output, for example, I would only get one record, the one with MA. How can I accomplish this?

How can I do a WpGraphQL query with a where clause?

This works fine
query QryTopics {
topics {
nodes {
name
topicId
count
}
}
}
But I want a filtered result. I'm new to graphql but I see a param on this collection called 'where', after 'first', 'last', 'after' etc... How can I use that? Its type is 'RootTopicsTermArgs' which is likely something autogenerated from my schema. It has fields, one of which is 'childless' of Boolean. What I'm trying to do, is return only topics (a custom taxonomy in Wordpress) which have posts tagged with them. Basically it prevents me from doing this on the client.
data.data.topics.nodes.filter(n => n.count !== null)
Can anyone direct me to a good example of using where args with a collection? I have tried every permutation of syntax I could think of. Inlcuding
topics(where:childless:true)
topics(where: childless: 'true')
topics(where: new RootTopicsTermArgs())
etc...
Obviously those are all wrong.
If a custom taxonomy, such as Topics, is registered to "show_in_graphql" and is part of your Schema you can query using arguments like so:
query Topics {
topics(where: {childless: true}) {
edges {
node {
id
name
}
}
}
}
Additionally, you could use a static query combined with variables, like so:
query Topics($where:RootTopicsTermArgs!) {
topics(where:$where) {
edges {
node {
id
name
}
}
}
}
$variables = {
"where": {
"childless": true
}
};
One thing I would recommend is using a GraphiQL IDE, such as https://github.com/skevy/graphiql-app, which will help with validating your queries by providing hints as you type, and visual indicators of invalid queries.
You can see an example of using arguments to query terms here: https://playground.wpgraphql.com/#/connections-and-arguments

Map sql out parameter to POGO

I have groovy code like the following
query.call(sqlString, [Sql.out(OracleTypes.CURSOR)]) { ResultSet cursor ->
while (cursor.next()) {
println cursor.getString("whatever")
}
But what I want to be able to do, is to load the whole row into an object. Like in this example
sql.eachRow("Select * from Person") {
persons << new Person( it.toRowResult() )
}
How can I get from one to the other, given that I have to work through an Oracle Out parameter?

Elasticsearch: Return empty value from script field

I'm using Elasticsearch, and I have a script field written in Groovy. It needs to replace the value of myField for some values, but I want to let most of the values pass through unchanged. The script below works except for documents that don't have the field at all. How can I make the script field value empty?
if (some criteria) {
return ...; // modified value
}
// This returns 0 if myField doesn't exist
return doc['myField'].value
I can check the empty condition, but I haven't found a way to return an empty value:
if (doc['myField'].empty)
return ???
It's perfectly ok to return null. I think the problem is more in the sequencing of your different test conditions. I've tried to reproduce your issue and I'm able to return null with the following script:
"script_fields": {
"my_script_field": {
"script": "if (doc.myField.empty) { return null } else if (some criteria) { return modifiedValue } else { return doc.myField.value }"
}
}
First check for fields with empty values and return null.
Then, you're guaranteed to have non-empty and existing fields. So you can check for your criteria and return whatever modified field you want.
Finally, you can return the unmodified values for non-empty fields which do not meet your specified criteria.
The script looks like this:
if (doc.myField.empty) {
return null
} else if (some criteria) {
return modifiedValue
} else {
return doc.myField.value
}

Resources