query-1eea7c2ebcd9d456085f4b200828f2cb
Royal Navy ship classes without a named_after, with the ships that are part of the class, and match the name
Use at
- https://query.wikidata.org/sparql
 
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?item ?itemLabel ?ship ?shipLabel WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en-gb,en,mul". }
  {
    SELECT DISTINCT ?item ?namedafter ?class ?ship ?shipLabel WHERE {
      ?item wdt:P31 wd:Q559026;
      rdfs:label ?itemlabel.
      MINUS {?item wdt:P138 ?namedafter.    
      ?namedafter wdt:P289 ?class.}
      ?item wdt:P137 wd:Q172771.
      ?ship wdt:P289 ?item;
      rdfs:label ?shiplabel.
      FILTER(LANG(?shiplabel) = "en").
      BIND (SUBSTR(?shiplabel,4) AS ?shiplabel1)
      FILTER (CONTAINS(?itemlabel, ?shiplabel1))
    }
  }
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v6("?class")
  v4("?item"):::projected 
  v1("?itemlabel")
  v5("?namedafter")
  v7("?ship"):::projected 
  v3("?shiplabel")
  v8("?shiplabel1")
  c4(["en-gb,en,mul"]):::literal 
  c2(["bd:serviceParam"]):::iri 
  c7(["wd:Q559026"]):::iri 
  c12(["wd:Q172771"]):::iri 
  subgraph s1["http://wikiba.se/ontology#label"]
    style s1 stroke-width:4px;
    c2 --"wikibase:language"-->  c4
  end
  f0[["contains(?itemlabel,?shiplabel1)"]]
  f0 --> v1
  f0 --> v8
  f1[["?shiplabel = 'en'"]]
  f1 --> v3
  v4 --"wdt:P31"-->  c7
  v4 --"rdfs:label"-->  v1
  subgraph minus2["MINUS"]
    style minus2 stroke-width:6px,fill:pink,stroke:red;
    v4 --"wdt:P138"-->  v5
    v5 --"wdt:P289"-->  v6
  end
  v4 --"wdt:P137"-->  c12
  v7 --"wdt:P289"-->  v4
  v7 --"rdfs:label"-->  v3
  bind3[/"substring(?shiplabel,'4^^xsd:integer')"/]
  v3 --o bind3
  bind3 --as--o v8