query-1e870148f47b6d20f9c1993a8acc18a9

rq turtle/ttl

01:58, 23 June 2018 (UTC)) talk (TagishsimonPerhaps this does the second one? We're finding an ?occ, checking it is a P279 of journalist, but checking also that it is not itself journalist. We return the item in the results only if an ?occ can be found which is a P279 of J~ and which is not J~. (I should caution that I'm that dangerous thing, a person with a little knowledge of SPARQL...) In passing, we're maybe not dealing very elegantly with people having multiple occupations ... we may get multiple rows for a single individual. --I'm impressed, thanks! I was "researching" this after your first response, but all my thoughts are in terms of SQL which just doesn't seem to help ("get a subquery of all the relevant subclasses..."). I will need to read a book. It just didn't seem like a challenge to access the name of the subclass involved. I removed the filter line from yours out of curiosity--with a limit of 5000 it still doesn't return "journalist" anywhere--I don't know if that is coincidence due to the limit, or only subclasses are returned with the second line. , who has both). That may either be really easy or quite hard, but I will be able to use your second query. this guy, I'm just talking) would be to exclude items that DO have journalist along with the wanted subclass "war correspondent" (for example, the second query returned which I don't in any way needA bonus problem ( 02:57, 23 June 2018 (UTC)) talk (OutriggrThanks very much. 20:39, 23 June 2018 (UTC)) talk (TagishsimonYes: that's exactly the page of the reference I was in need of reading; thank you. I used an InversePath yesterday and had made a mental note to track down documentation to check my use of it. And now I have. -- 05:34, 23 June 2018 (UTC)) talk (MisterSynergy quantifier, which means “zero or more levels”). —* means “one or more levels” in contrast to the + itself (the (Q1930187)journalist , but not (Q1930187)journalist you select all items that are subclasses of ?occupation wdt:P279+ wd:Q1930187 might help you. With This section in the SPARQL reference 20:39, 23 June 2018 (UTC)) talk (Tagishsimon: Confusion is good. Keeps the brain warm. Your amendment works; but if you remove the limit from the first query & run it, you'll get 7765 results ... if you then comment out the P31/P279 code, you get the same number of hits, since your new bit of code renders the P31/P279 redundant :) --Outriggr@ 04:20, 23 June 2018 (UTC)) talk (OutriggrSorry to confuse you. You are correct. I would then change my bonus problem ( :-D ) to being able to remove the non-journo occupations from the first list. I believe I have figured this out myself by adding the commented row in your first query. (I'm so confused I've pressed Publish instead of Preview three times during this discussion.) Regards, 03:38, 23 June 2018 (UTC)) talk (Tagishsimon return items that have an occ of journalist, if there is also an occ which is a subclass of journalist; but will not provide a row specifying occupation = journalist; and all of the occupations/rows output will be subclasses of journalist, and so if an item has multiple journalist subclasses, we'll get one row per occupation. So the initial query is your last paragraph's exclude items that DO have journalist along with the wanted subclass "war correspondent". I've added comments to the code fwiw. hth --will: I think your last paragraph confused me. Let me recap where I think we are. (I think ...) The first query will not return an Item which has journalist in it, even if it has a subclass of Journalist in it. For those items which are selected on the basis of having a subclass of journalist, it will return one row per occupation per person, irrespective of whether the occupation is a subclass of journalist (so a war correspondent & car mechanic will get one row for each of these). The second query Outriggr@: I see! ... I thought I'd place the final queries below. Removed "distinct" as I don't think it was ever relevant. Tagishsimon@Return items with statement value that is a subclass of X (but exclude items where class X itself is involved), and get the name of the subclasses for a label

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?item ?itemLabel ?occLabel WHERE {
  ?item wdt:P106 ?occ .               #get the occ value/subclass for the Label
  ?occ wdt:P279+ wd:Q1930187 .        #get occ's that are subclasses of "journalist", but exclude "journalist"
  FILTER NOT EXISTS {?item wdt:P106 wd:Q1930187 } 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ?itemLabel
LIMIT 100 # number of rows ~7700

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v2("?item"):::projected v1("?itemLabel"):::projected v3("?occ") c2(["wd:Q1930187"]):::iri c5(["bd:serviceParam"]):::iri c7(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[["not "]] subgraph f0e0["Exists Clause"] e0v1 --"wdt:P106"--> e0c2 e0v1("?item"):::projected e0c2(["wd:Q1930187"]):::iri end f0--EXISTS--> f0e0 f0 --> v2 f0 --> c1 f0 --> c2 v2 --"wdt:P106"--> c2 v2 --"wdt:P106"--> v3 v3 --"wdt:P279"--> c2 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c5 --"wikibase:language"--> c7 end