Show all Wikidata descendants, uniquely - recursion

I have the following working query with the aim of showing all subclasses of Q3314483 [1]:
SELECT ?item (SAMPLE(?itemLabel) AS ?itemLabel) (SAMPLE(?subclass) as ?subklass) (SAMPLE(?subclassLabel) AS ?subLabel) WHERE {
?item wdt:P279* wd:Q3314483 ;
wdt:P279 ?subclass .
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
group by ?item
The SAMPLE and GROUP pattern is designed to make the items unique. It seems to work, however the label columns are blank. How can they be displayed?
Based on this

Thanks to #AKSW in the comments. Answer is:
SELECT ?item (SAMPLE(?itemLabel) AS ?itemLabel) (SAMPLE(?subclass) as ?subklass) (SAMPLE(?subclassLabel) AS ?subLabel) WHERE {
?item wdt:P279* wd:Q3314483 ;
wdt:P279 ?subclass . SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". ?subclass rdfs:label ?subclassLabel. ?item rdfs:label ?itemLabel.
}
}
GROUP BY ?item

Related

string query in Wikidata

I want to find all the reruns of a specific production using a string in the query. I do not get any results. This is the query I am trying:
SELECT ?item ?label
WHERE {
?item wdt:P5935 ?id;
rdfs:label ?label.
FILTER(LANG(?label) = "[AUTO_LANGUAGE]").
FILTER(STRSTARTS(?label, "Der Ring des Nibelungen: Die Walküre")).
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],nl,en". }
}
Does anyone know how to form queries using a string from the label?
On the Wikidata Query Service website, AUTO_LANGUAGE is replaced by the language of your user inteface.
If your user interface is Dutch, you will get a result: Q47471674.
Otherwise, you don't get a result because no other language has an item with the label "Der Ring des Nibelungen: Die Walküre".
I recommend you to either replace in the FILTER expression AUTO_LANGUAGE by a specific language code or if you want a language independent search, omit the expression altogether.
SELECT ?item ?label
WHERE {
?item wdt:P5935 ?id;
rdfs:label ?label.
# FILTER(LANG(?label) = "nl").
FILTER(STRSTARTS(?label, "Der Ring des Nibelungen: Die Walküre")).
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],nl,en". }
}

Sort document by integer Firestore Kotlin

I want to sort documents by img in descending order.
I've tried to add indexes in firebase console. Here is a screenshot from indexes tab:
Here is my database structure:
Here is my code:
db.collection("images").whereEqualTo("user", uid).orderBy("img", Query.Direction.DESCENDING).get()
.addOnSuccessListener {
if (it.isEmpty) {
Log.i("Image", "Sorry, no image")
} else {
for (task in it) {
Log.i("Image", task.get("img").toString())
}
}
}
And here is log:
I/Image: 2
I/Image: 1
I/Image: 3
I/Image: 4
I/Image: 6
I/Image: 7
What am I doing wrong?
Notice that as stated on the documentation there could be two explanations behind the behavior you are experiencing:
If you have a filter with a range comparison (<, <=, >, >=), your first ordering must be on the same field
You cannot order your query by any field included in an equality (=) or in clause.
Based on the following snippet provided on the documentation:
citiesRef.whereGreaterThan("population", 100000).orderBy("population").limit(2)
You could try the following (but I'm not sure if it'll work because of 2.):
db.collection("images").whereEqualTo("user", uid).orderBy("user").orderBy("img", Query.Direction.DESCENDING).get()
.addOnSuccessListener {
if (it.isEmpty) {
Log.i("Image", "Sorry, no image")
} else {
for (task in it) {
Log.i("Image", task.get("img").toString())
}
}
}

How to Update/Insert/Delete CrossCompany

is possible to make insert, update or delete crossCompany in axapta?
i am trying to do that, debugging in my query i have this:
select forUpdate crossCompany tlRemoteLocationInfo
where tlRemoteLocationInfo.RemoteLocationId == "someId";
if (tlRemoteLocationInfo.RecId)
{
ttsBegin;
changeCompany(tlRemoteLocationInfo.dataAreaId)
//then i make mi update to fields and then i make this:
tlRemoteLocationInfo.update();
ttsCommit;
}
i have a try catch, and debugging, fails to update in the method tlRemoteLocationInfo.update(), the exception is:
$exception {"Se produjo una excepción de tipo
'Microsoft.Dynamics.Ax.Xpp.ErrorException'."} System.Exception
{Microsoft.Dynamics.Ax.Xpp.ErrorException}
Am i missing someghing?
You can't do update operations using the crossCompany keyword. See here:
https://msdn.microsoft.com/en-us/library/cc518738.aspx
I rewrote your code so that it should work. And make sure to do an incremental CIL compile if this is running in CIL. The second method is if you wanted to do a while-select.
// Rewrite 1 - Notice removal of "forUpdate"
select firstOnly crossCompany tlRemoteLocationInfo
where tlRemoteLocationInfo.RemoteLocationId == "someId";
if (tlRemoteLocationInfo)
{
changeCompany(tlRemoteLocationInfo.dataAreaId)
{
// Notice this line
tlRemoteLocationInfo.selectForUpdate(true);
ttsBegin;
//then i make mi update to fields and then i make this:
tlRemoteLocationInfo.update();
ttsCommit;
}
}
// Rewrite 2 - Is a "while select" what you want?
while select crossCompany tlRemoteLocationInfo
where tlRemoteLocationInfo.RemoteLocationId == "someId"
{
changeCompany(tlRemoteLocationInfo.dataAreaId)
{
// Notice this line
tlRemoteLocationInfo.selectForUpdate(true);
ttsBegin;
//then i make mi update to fields and then i make this:
tlRemoteLocationInfo.update();
ttsCommit;
}
}

use aggregates (min, max, avg) in CONSTRUCT query [duplicate]

I mostly use SPARQL SELECT while working on a query for debugging purposes but in the end I want to use the final result it in a CONSTRUCT way; as I want to work with a graph and not key/value query results.
What I don't get yet (and can't seem to find with search engines/docs) is if I can use functions as well that way. As an example, I use a property path to concatenate titles I get into a "superstring", which I later use for building a Lucene index to increase plain text search quality:
PREFIX dc: <http://purl.org/dc/elements/1.1/>
SELECT (group_concat(?title ; separator = " ") AS ?fancytitle) WHERE {
GRAPH ?graph {
<http://data.staatsarchiv-bs.ch/id/archivalresource/CH-000027-1/pa-633c-a-312-fasc-163> dc:relation+ ?relation .
?relation dc:title ?title .
}
}
Now I would like to have the same ?fancytitleas a new triple like
<http://data.staatsarchiv-bs.ch/id/archivalresource/CH-000027-1/pa-633c-a-312-fasc-163> <fancytitle> ?fancytitle .
So I can store it directly in a new graph. Is this possible? I played with some queries but couldn't manage to get it accepted by the SPARQL processor. FYI I'm using Fuseki.
You can try it out at my SPARQL Endpoint
Yes this is possible
You can't use expressions directly in a CONSTRUCT template but you can assign the variable in the WHERE clause either via a SELECT expression in a sub-query or using BIND.
In your case as GROUP_CONCAT is an aggregate it can only be a SELECT expression so you just need to put your entire SELECT as a sub-query e.g.
PREFIX dc: <http://purl.org/dc/elements/1.1/>
CONSTRUCT
{
<http://data.staatsarchiv-bs.ch/id/archivalresource/CH-000027-1/pa-633c-a-312-fasc-163> <http://fancyTitle> ?fancytitle
}
WHERE
{
SELECT (group_concat(?title ; separator = " ") AS ?fancytitle) WHERE {
GRAPH ?graph {
<http://data.staatsarchiv-bs.ch/id/archivalresource/CH-000027-1/pa-633c-a-312-fasc-163> dc:relation+ ?relation .
?relation dc:title ?title .
}
}
}
The above works fine on your endpoint
With the help of my colleague we got it to work, UNION and GROUP BY are essential. This query puts the string together for all locah:ArchivalResource in the graphs:
CONSTRUCT
{
?archresource skos:hiddenLabel ?supertitle
}
WHERE
{
SELECT ?archresource (group_concat(?title ; separator = ", ") AS ?supertitle) WHERE {
GRAPH ?graph {
{
SELECT ?title ?archresource WHERE {
GRAPH ?graph {
{
?archresource a locah:ArchivalResource ;
dc:title ?title .
} UNION
{
?archresource dc:relation+ ?relation .
?relation dc:title ?title .
}
}
}
}
}
} GROUP BY ?archresource
}

Using jsonPath looking for a string

I'm trying to use jsonPath and the pick function to determine if a rule needs to run or not based on the current domain. A simplified version of what I'm doing is here:
global
{
dataset shopscotchMerchants <- "https://s3.amazonaws.com/app-files/dev/merchantJson.json" cachable for 2 seconds
}
rule checkdataset is active
{
select when pageview ".*" setting ()
pre
{
merchantData = shopscotchMerchants.pick("$.merchants[?(#.merchant=='Telefora')]");
}
emit
<|
console.log(merchantData);
|>
}
The console output I expect is the telefora object, instead I get all three objects from the json file.
If instead of merchant=='Telefora' I use merchantID==16 then it works great. I thought jsonPath could do matches to strings as well. Although the example above isn't searching against the merchantDomain part of the json, I'm experiencing the same problem with that.
Your problem comes from the fact that, as stated in the documentation, the string equality operators are eq, neq, and like. == is only for numbers. In your case, you want to test if one string is equal to another string, which is the job of the eq string equality operator.
Simply swap == for eq in you JSONpath filter expression and you will be good to go:
global
{
dataset shopscotchMerchants <- "https://s3.amazonaws.com/app-files/dev/merchantJson.json" cachable for 2 seconds
}
rule checkdataset is active
{
select when pageview ".*" setting ()
pre
{
merchantData = shopscotchMerchants.pick("$.merchants[?(#.merchant eq 'Telefora')]"); // replace == with eq
}
emit
<|
console.log(merchantData);
|>
}
I put this to the test in my own test ruleset, the source for which is below:
ruleset a369x175 {
meta {
name "test-json-filtering"
description <<
>>
author "AKO"
logging on
}
dispatch {
domain "exampley.com"
}
global {
dataset merchant_dataset <- "https://s3.amazonaws.com/app-files/dev/merchantJson.json" cachable for 2 seconds
}
rule filter_some_delicous_json {
select when pageview "exampley.com"
pre {
merchant_data = merchant_dataset.pick("$.merchants[?(#.merchant eq 'Telefora')]");
}
{
emit <|
try { console.log(merchant_data); } catch(e) { }
|>;
}
}
}

Resources