如何修正SPARQL查询以获取含‘human’与‘peace’的诺贝尔奖奖项
Let's break down why your original query is failing and how to fix it to get the results you want:
The Problem with Your Original Query
Blazegraph's bds:search isn't meant to be used as a function inside a FILTER clause. That syntax doesn't align with how Blazegraph handles full-text search—instead, you need to define the search using triple patterns to specify the target property and search terms.
Corrected Queries
Here are two valid approaches to achieve your goal:
Approach 1: Directly Annotate the Target Variable
This is the more concise way, applying the search directly to the ?description variable that holds the motivation text:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX bds: <http://www.bigdata.com/rdf/search#> PREFIX nobel: <http://data.nobelprize.org/terms/> SELECT ?awards ?description WHERE { ?entity rdfs:label ?awards . ?entity nobel:motivation ?description . # Search for entries containing both "human" and "peace" in the motivation ?description bds:search '"human" AND "peace"' . # Optional: Ensure all terms are matched (redundant with AND, but explicit) ?description bds:matchAllTerms true . }
Approach 2: Configure Search via bds:search Subject
If you prefer a more explicit configuration, you can use the bds:search special subject to define your search parameters:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX bds: <http://www.bigdata.com/rdf/search#> PREFIX nobel: <http://data.nobelprize.org/terms/> SELECT ?awards ?description WHERE { ?entity rdfs:label ?awards . ?entity nobel:motivation ?description . # Define the full-text search parameters bds:search bds:searchPredicate nobel:motivation . bds:search bds:searchText '"human" AND "peace"' . bds:search bds:matchAllTerms true . }
Key Notes
- The
"human" AND "peace"syntax ensures both terms are present in thenobel:motivationfield. If you wanted to match the exact phrase"human peace", you'd use that instead. bds:matchAllTerms trueexplicitly enforces that all search terms are found—while theANDoperator already does this, adding it makes your intent clearer.- Both queries will return award labels (
?awards) and their corresponding motivation descriptions that meet your full-text criteria.
内容的提问来源于stack exchange,提问作者user9432913

