从表达式

时间:2017-06-04 12:14:55

标签: sparql dbpedia

我正在尝试进行测试查询,我想基于从表达式分配的变量进行过滤。这是在巴拉克奥巴马出生之前寻找美国总统的测试问题:

  PREFIX db: <http://dbpedia.org/resource/>
  PREFIX dbprop: <http://dbpedia.org/property/>
  PREFIX dbc: <http://dbpedia.org/resource/Category:>
  PREFIX dct: <http://purl.org/dc/terms/>

  SELECT ?president (min(?termStart) as ?minTermStart) ?birthDate
  WHERE {
    db:Barack_Obama dbprop:birthDate ?birthDate .
    ?president dct:subject dbc:Presidents_of_the_United_States .
    ?president dbprop:termStart ?termStart .
    filter($minTermStart < ?birthDate) .
  }

没有结果。

带走filter(minTermStart < ?birthDate)给出以下内容:

                                              president minTermStart  birthDate
1       <http://dbpedia.org/resource/John_Quincy_Adams>  -5527303492 -265456800
2     <http://dbpedia.org/resource/William_Howard_Taft>  -2454919492 -265456800
3        <http://dbpedia.org/resource/William_McKinley>  -2929428292 -265456800
4          <http://dbpedia.org/resource/Woodrow_Wilson>  -1860573600 -265456800
5       <http://dbpedia.org/resource/Chester_A._Arthur>  -3439706692 -265456800
6            <http://dbpedia.org/resource/James_Monroe>  -5653274692 -265456800
7          <http://dbpedia.org/resource/Zachary_Taylor>  -3813041092 -265456800
8         <http://dbpedia.org/resource/Calvin_Coolidge>  -1703757600 -265456800
9         <http://dbpedia.org/resource/John_F._Kennedy>   -725709600 -265456800
10  <http://dbpedia.org/resource/Franklin_D._Roosevelt>  -1792317600 -265456800
11         <http://dbpedia.org/resource/George_W._Bush>    790261200 -265456800
12            <http://dbpedia.org/resource/Gerald_Ford>   -662551200 -265456800
13           <http://dbpedia.org/resource/Barack_Obama>    852642000 -265456800
14           <http://dbpedia.org/resource/Bill_Clinton>    221058000 -265456800
15        <http://dbpedia.org/resource/Abraham_Lincoln>  -3876199492 -265456800
16          <http://dbpedia.org/resource/Richard_Nixon>   -725709600 -265456800
17       <http://dbpedia.org/resource/Millard_Fillmore>  -4317962692 -265456800
18    <http://dbpedia.org/resource/Rutherford_B._Hayes>  -3308119492 -265456800
19      <http://dbpedia.org/resource/Warren_G._Harding>  -2082016800 -265456800
20       <http://dbpedia.org/resource/Thomas_Jefferson>  -6138929092 -265456800
21       <http://dbpedia.org/resource/Martin_Van_Buren>  -4696653892 -265456800
22         <http://dbpedia.org/resource/Herbert_Hoover>  -1540893600 -265456800
23           <http://dbpedia.org/resource/Jimmy_Carter>   -219837600 -265456800
24          <http://dbpedia.org/resource/James_K._Polk>  -4570423492 -265456800
25      <http://dbpedia.org/resource/Lyndon_B._Johnson>  -1032861600 -265456800
26   <http://dbpedia.org/resource/Dwight_D._Eisenhower>   -777981600 -265456800
27      <http://dbpedia.org/resource/George_Washington>  -6142471492 -265456800
28         <http://dbpedia.org/resource/James_Buchanan>  -4696653892 -265456800
29             <http://dbpedia.org/resource/John_Tyler>  -4829537092 -265456800
30          <http://dbpedia.org/resource/Ronald_Reagan>    -94644000 -265456800
31      <http://dbpedia.org/resource/James_A._Garfield>  -3371277892 -265456800
32 <http://dbpedia.org/resource/William_Henry_Harrison>  -5412391492 -265456800
33             <http://dbpedia.org/resource/John_Adams>  -6142471492 -265456800
34      <http://dbpedia.org/resource/George_H._W._Bush>    -94557600 -265456800
35         <http://dbpedia.org/resource/Andrew_Johnson>  -4002429892 -265456800
36          <http://dbpedia.org/resource/James_Madison>  -5959130692 -265456800
37      <http://dbpedia.org/resource/Benjamin_Harrison>  -2803197892 -265456800
38       <http://dbpedia.org/resource/Ulysses_S._Grant>  -3339223492 -265456800
39         <http://dbpedia.org/resource/Andrew_Jackson>  -5461725892 -265456800
40       <http://dbpedia.org/resource/Grover_Cleveland>  -2776932292 -265456800
41        <http://dbpedia.org/resource/Franklin_Pierce>  -4317962692 -265456800
42        <http://dbpedia.org/resource/Harry_S._Truman>  -1356256800 -265456800
43     <http://dbpedia.org/resource/Theodore_Roosevelt>  -2777018692 -265456800

使用filter(minTermStart < \"1961-08-03\"^^xsd:date)也没有给出任何结果。 为什么过滤器表达式不起作用?我错过了什么?

1 个答案:

答案 0 :(得分:1)

“没有结果”?

您的查询是编译,如果您在http://dbpedia.org/sparql上运行它会导致错误:

  1. minTermStart缺少?
  2. 必须是termStart而不是
  3. PREFIX  dbc:  <http://dbpedia.org/resource/Category:>
    PREFIX  dct:  <http://purl.org/dc/terms/>
    PREFIX  db:   <http://dbpedia.org/resource/>
    PREFIX  dbprop: <http://dbpedia.org/property/>
    
    SELECT  ?president (MIN(?termStart) AS ?minTermStart) ?birthDate
    WHERE
      { db:Barack_Obama
                  dbprop:birthDate  ?birthDate .
        ?president  dct:subject     dbc:Presidents_of_the_United_States ;
                  dbprop:termStart  ?termStart
        FILTER ( ?termStart < ?birthDate )
      }
    GROUP BY ?president ?birthDate
    

    如果你在没有过滤器的情况下运行结果,你也不清楚从哪里得到结果,我的显示以下(样本)

    +-------------------------------------------------+--------------+------------+
    |                    president                    | minTermStart | birthDate  |
    +-------------------------------------------------+--------------+------------+
    | http://dbpedia.org/resource/John_Quincy_Adams   | 1794-11-06   | 1961-08-04 |
    | http://dbpedia.org/resource/William_Howard_Taft | 1892-03-17   | 1961-08-04 |
    | http://dbpedia.org/resource/William_McKinley    | 1877-03-04   | 1961-08-04 |
    | http://dbpedia.org/resource/Woodrow_Wilson      | 1911-01-17   | 1961-08-04 |
    | http://dbpedia.org/resource/Chester_A._Arthur   | 1861-01-01   | 1961-08-04 |
    | http://dbpedia.org/resource/James_Monroe        | 1790-11-09   | 1961-08-04 |
    | http://dbpedia.org/resource/Zachary_Taylor      | 1849-03-04   | 1961-08-04 |
    | ...                                             | ...          | ...        |
    +-------------------------------------------------+--------------+------------+