获取DBpedia无重复单曲的relYear/released字段及Billboard单曲查询
解决DBpedia单曲数据查询的两个需求
Hey there! Let's break down how to address your two requirements for querying DBpedia's single data:
需求1:获取无重复的单曲发行年份(relYear/released)
The core goal here is to pull either the relYear or released field from DBpedia's single records, with strict no-duplicate results. Key points to note:
- DBpedia stores release year info in two separate property fields:
prop:relyearandprop:released - Using
DISTINCTis essential to eliminate duplicate entries - We'll use
OPTIONALclauses to capture both fields without excluding records that only have one of them
需求2:优化Billboard Hot 100冠军单曲查询
You shared a SPARQL query for fetching Billboard Hot 100 number-one singles, and we can tweak it to align with the no-duplicate requirement while properly capturing release year data. Here's the refined query:
PREFIX prop: <http://dbpedia.org/property/> PREFIX ont: <http://dbpedia.org/ontology/> PREFIX dct: <http://purl.org/dc/terms/> PREFIX dbc: <http://dbpedia.org/resource/Category:> SELECT DISTINCT ?page ?artist ?releaseYear ?runTime WHERE { ?page dct:subject dbc:Billboard_Hot_100_number-one_singles . # Fetch artist info if available OPTIONAL { ?page prop:artist ?artist } # Unify release year into a single field (covers both relYear and released) OPTIONAL { ?page prop:released ?releaseYear } OPTIONAL { ?page prop:relyear ?relyearVal . BIND(?relyearVal AS ?releaseYear) } # Get runtime if the data exists OPTIONAL { ?page ont:runtime ?runTime } }
What this query does better:
- No duplicates: The
DISTINCTkeyword ensures every returned row is a unique single entry - Unified release year: Instead of having two separate columns for
relYearandreleased, we map both into a singlereleaseYearfield for cleaner results - Robust data capture:
OPTIONALclauses mean we won't drop records that lack artist, release year, or runtime info—we'll just return whatever data is available for each single
内容的提问来源于stack exchange,提问作者dfrankow
相关产品推荐
相关产品推荐

