Dit kan efficiënter:
match (w:word)<-[:rel{rel:'hd'}]-()-[:rel{rel:'obj1'}]->(:node{cat:'whrel'}),
(w1:word{lemma:w.lemma})<-[:rel{rel:'hd'}]-()-[:rel{rel:'vc'}]->(:node{cat:'whsub'}),
(w2:word{lemma:w.lemma})<-[:rel{rel:'hd'}]-()-[:rel{rel:'vc'}]->(:node{cat:'whsub'})
where w1.sentid != w.sentid
and w2.sentid != w.sentid
and w1.sentid != w2.sentid
and w.pt = 'ww'
return w
… en veel, veel sneller:
match (w1:word{pt:'ww'})<-[:rel{rel:'hd'}]-()-[:rel{rel:'vc'}]->(:node{cat:'whsub'})
with w1.lemma as lemma1, count(w1.lemma) as n
where n > 1
match (w:word{pt:'ww'})<-[:rel{rel:'hd'}]-()-[:rel{rel:'obj1'}]->(:node{cat:'whrel'})
where w.lemma in lemma1
return w
De tweede variant is niet identiek aan de eerste. De tweede variant kijkt wel of een lemma met de vc/whsub-constructie meer dan eens voorkomt, maar niet of het in meerdere zinnen voorkomt. Als je die laatste eis wilt toevoegen wordt het een stuk complexer:
match (w:word{pt:'ww'})<-[:rel{rel:'hd'}]-()-[:rel{rel:'obj1'}]->(:node{cat:'whrel'})
where w.lemma in (
select lemma
from (
select lemma, count(lemma) as n
from (
match (w1:word{pt:'ww'})<-[:rel{rel:'hd'}]-()-[:rel{rel:'vc'}]->(:node{cat:'whsub'})
return distinct w1.lemma, w1.sentid
) as foo
group by lemma
) as bar
where n > 1
)
return w