prefix dcterms:
prefix dbr:
select ?showB ?subjCountShowAB ?subjCountShowA ?subjCountShowB (strdt(?subjCountShowAB,xsd:double) / (?subjCountShowA + ?subjCountShowB - ?subjCountShowAB) as ?subjScore)
where {
{
select ?showB ?subjCountShowAB ?subjCountShowA (count(?subject) as ?subjCountShowB)
where {
?showB dcterms:subject ?subject .
{
select ?showB (count(?subject) as ?subjCountShowAB) ?subjCountShowA
where {
?showA dcterms:subject ?subject .
?showB dcterms:subject ?subject filter(!sameTerm(?showA,?showB)) .
{
select ?showA (count(?subject) as ?subjCountShowA)
where {
?showA dcterms:subject ?subject filter(sameTerm(?showA,dbr:Friends)) .
}
}
} group by ?showB ?subjCountShowA
}
} group by ?showB ?subjCountShowAB ?subjCountShowA
}
} order by desc(?subjScore) limit 100