Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPARQL Query returns multiple lines per fountain #6

Open
mmmatthew opened this issue Jun 27, 2018 · 3 comments
Open

SPARQL Query returns multiple lines per fountain #6

mmmatthew opened this issue Jun 27, 2018 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@mmmatthew
Copy link
Member

The following query is supposed to return all fountains in Zurich, including the WVZ catalog code, when available. However, some fountains also have another catalog code, from the "Kunst im Stadtraum" catalog.
In these cases, the query returns two lines of data.

How can we get the query to only return the catalog information for a fountain if the corresponding catalog is Q53629101?

Here is the query:

SELECT ?place ?placeLabel ?location ?date ?catalog_code ?catalogLabel ?operator
WHERE
{
  # Enter coordinates
  SERVICE wikibase:box {
    ?place wdt:P625 ?location .
    bd:serviceParam wikibase:cornerWest "Point(8.45960259979614 47.3229261255644)"^^geo:wktLiteral.
    bd:serviceParam wikibase:cornerEast "Point(8.61940272745742 47.431119712250506)"^^geo:wktLiteral.
  } .
  # Is a water well or fountain or subclass of fountain
  FILTER (EXISTS { ?place wdt:P31/wdt:P279* wd:Q43483 } || EXISTS { ?place wdt:P31/wdt:P279* wd:Q483453 }).
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],de" .
  } 
  OPTIONAL { ?place p:P528 ?catalog_code.
            ?catalog_code pq:P972 ?catalog.}
  OPTIONAL { ?place wdt:P571 ?date.}
  OPTIONAL { ?place wdt:P137 ?operator.}
}
@mmmatthew mmmatthew added the help wanted Extra attention is needed label Jun 27, 2018
@criscod
Copy link

criscod commented Jul 10, 2018

How about this query?

SELECT ?place ?placeLabel ?location ?date ?catalog_code_st ?catalogue_code ?operator
WHERE
{
  # Enter coordinates
  SERVICE wikibase:box {
    ?place wdt:P625 ?location .
    bd:serviceParam wikibase:cornerWest "Point(8.45960259979614 47.3229261255644)"^^geo:wktLiteral.
    bd:serviceParam wikibase:cornerEast "Point(8.61940272745742 47.431119712250506)"^^geo:wktLiteral.
  } .
  # Is a water well or fountain or subclass of fountain
  FILTER (EXISTS { ?place wdt:P31/wdt:P279* wd:Q43483 } || EXISTS { ?place wdt:P31/wdt:P279* wd:Q483453 }).
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],de" .
  } 
  
 
  ?place p:P528 ?catalog_code_st.
  ?catalog_code_st pq:P972 wd:Q53629101.
  ?catalog_code_st ps:P528 ?catalogue_code.
  
  #?catalog_code_st ps:P528 ?catalog_code.
           
  OPTIONAL { ?place wdt:P571 ?date.}
  OPTIONAL { ?place wdt:P137 ?operator.}
}

I see that the results (https://tinyurl.com/ya2jsxae) include sometimes two values for catalogue_code, but I checked the item description and indeed there are two values coming from the FountainsWVZ catalogue. For example, in this item: https://www.wikidata.org/wiki/Q55166163

@mmmatthew
Copy link
Member Author

Thanks for that. Since we also need fountains with no catalog code, would you then suggest doing a union of two queries: one for all fountains with WVZ code and one for fountains with no WVZ code?

@criscod
Copy link

criscod commented Jul 11, 2018

+1 (the UNION operator in SPARQL should help you.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants