在Wikidata SPARQL查询中使项成为可选项

在Wikidata SPARQL查询中使项成为可选项,sparql,wikidata,Sparql,Wikidata,如果我使用了错误的术语来描述我的问题,请原谅 我想通过WIKIDATA SPARQL查询提取关于世界岛屿区域的信息,包括坐标、它们所属的国家、它们所属的群岛以及它们的地理名称。当然,并非每个岛都提供此信息,因此如果我将其包括在查询中,我将结果列表限制为已包含以下属性的项: SELECT ?item ?itemLabel ?coords ?GeoNamesID WHERE { ?item wdt:P31 wd:Q23442. ?item wdt:P625 ?coords. ?it

如果我使用了错误的术语来描述我的问题,请原谅

我想通过WIKIDATA SPARQL查询提取关于世界岛屿区域的信息,包括坐标、它们所属的国家、它们所属的群岛以及它们的地理名称。当然,并非每个岛都提供此信息,因此如果我将其包括在查询中,我将结果列表限制为已包含以下属性的项:

SELECT ?item ?itemLabel ?coords ?GeoNamesID

  WHERE {
  ?item wdt:P31 wd:Q23442.
  ?item wdt:P625 ?coords.
  ?item wdt:P1566 ?GeoNamesID.
  ?item wdt:P17 ?country.
  ?item wdt:P706 ?terrain.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
SELECT ?item ?itemLabel ?coords ?GeoNamesID ?country ?continent ?terrain ?date ?named ?archipelago

  WHERE {
  ?item wdt:P31 wd:Q23442.
  ?item wdt:P625 ?coords.
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  
  OPTIONAL {?item wdt:P1566 ?GeoNamesID.}
  OPTIONAL {?item wdt:P17 ?country.}
  OPTIONAL {?item wdt:P30 ?continent.}          
  OPTIONAL {?item wdt:P706 ?terrain.}
  OPTIONAL {?item wdt:P571 ?date.}
  OPTIONAL {?item wdt:P138 ?named.}
  OPTIONAL {?item wdt:P361 ?archipelago.}
}
如果这些属性存在,但仍然包含根本没有这些属性的项,如何使它们中的某些属性成为“可选”以显示这些值


我在的长列表中找不到任何类似的问题,非常感谢您的帮助。

以下是我更新的查询,包括几个可选属性:

SELECT ?item ?itemLabel ?coords ?GeoNamesID

  WHERE {
  ?item wdt:P31 wd:Q23442.
  ?item wdt:P625 ?coords.
  ?item wdt:P1566 ?GeoNamesID.
  ?item wdt:P17 ?country.
  ?item wdt:P706 ?terrain.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
SELECT ?item ?itemLabel ?coords ?GeoNamesID ?country ?continent ?terrain ?date ?named ?archipelago

  WHERE {
  ?item wdt:P31 wd:Q23442.
  ?item wdt:P625 ?coords.
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  
  OPTIONAL {?item wdt:P1566 ?GeoNamesID.}
  OPTIONAL {?item wdt:P17 ?country.}
  OPTIONAL {?item wdt:P30 ?continent.}          
  OPTIONAL {?item wdt:P706 ?terrain.}
  OPTIONAL {?item wdt:P571 ?date.}
  OPTIONAL {?item wdt:P138 ?named.}
  OPTIONAL {?item wdt:P361 ?archipelago.}
}
我应该注意,当我第一次查询所有可选属性时,我得到了一个“超时”。我必须再试一次。但它与一个可选项同时起作用:

    SELECT ?item ?itemLabel ?coords ?GeoNamesID
    
      WHERE {
      ?item wdt:P31 wd:Q23442.
      ?item wdt:P625 ?coords.
      
      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
      
      OPTIONAL {?item wdt:P1566 ?GeoNamesID.}
}

:-)。太棒了,我不知道会这么容易。:-)将在下面为可能有相同问题的其他人发布我的新查询作为答复。