Sparql 仅返回teacher3。@AnthonyT我在示例数据上使用了ApacheJena,它按预期工作。你用哪家三联书店?查询应该是正确的,我们在这里多次遇到这个问题,Stanislav Kralin和我总是发布相同的两种解决方案:双重否定或多重计数查询。我使用

Sparql 仅返回teacher3。@AnthonyT我在示例数据上使用了ApacheJena,它按预期工作。你用哪家三联书店?查询应该是正确的,我们在这里多次遇到这个问题,Stanislav Kralin和我总是发布相同的两种解决方案:双重否定或多重计数查询。我使用,sparql,rdf,semantic-web,linked-data,Sparql,Rdf,Semantic Web,Linked Data,仅返回teacher3。@AnthonyT我在示例数据上使用了ApacheJena,它按预期工作。你用哪家三联书店?查询应该是正确的,我们在这里多次遇到这个问题,Stanislav Kralin和我总是发布相同的两种解决方案:双重否定或多重计数查询。我使用的是MarkLogic triple store,它应该遵循相同的W3C标准。我会通过他们的帮助系统,也许他们能给我一个更好的答案,因为这似乎只是他们系统的问题。我会把你的答案记为正确的-谢谢你的帮助! SELECT ?otherTeacher


仅返回
teacher3
。@AnthonyT我在示例数据上使用了ApacheJena,它按预期工作。你用哪家三联书店?查询应该是正确的,我们在这里多次遇到这个问题,Stanislav Kralin和我总是发布相同的两种解决方案:双重否定或多重计数查询。我使用的是MarkLogic triple store,它应该遵循相同的W3C标准。我会通过他们的帮助系统,也许他们能给我一个更好的答案,因为这似乎只是他们系统的问题。我会把你的答案记为正确的-谢谢你的帮助!
SELECT ?otherTeacher
WHERE {
VALUES ?teacher {$teacher}
  ?teacher hasStudent ?student .
  ?otherTeacher hasStudent ?student .
  FILTER(?teacher <> ?otherTeacher)
}
<teacher1> <hasStudent> "Alice" .
<teacher1> <hasStudent> "Bob" .
<teacher1> <hasStudent> "Charlie" .
<teacher2> <hasStudent> "Alice" .
<teacher2> <hasStudent> "Dan" .
<teacher3> <hasStudent> "Alice" .
<teacher3> <hasStudent> "Bob" .
<teacher3> <hasStudent> "Charlie" .
<teacher3> <hasStudent> "Dan" .
select distinct ?otherTeacher
where{
  {
    select (max(?count) as ?max)
      where{
        {
          SELECT DISTINCT ?otherTeacher (COUNT(?student) as ?count)
          WHERE {
          VALUES ?teacher {<teacher1> }
            ?otherTeacher <hasStudent> ?student .
            FILTER(?teacher != ?otherTeacher)
            FILTER EXISTS {
              ?teacher <hasStudent> ?student . 
            }
          }
          group by ?otherTeacher
       }
    }
  }
  {
    SELECT DISTINCT ?otherTeacher (COUNT(?student) as ?count)
    WHERE {
    VALUES ?teacher {<teacher1> }
      ?otherTeacher <hasStudent> ?student .
      FILTER(?teacher != ?otherTeacher)
      FILTER EXISTS {
        ?teacher <hasStudent> ?student . 
      }
    }
    group by ?otherTeacher
  }
  filter(?count >= ?max) # epsilon error/no match if it's equal?
}