SELECT 
  count(*)
FROM
  (
    SELECT DISTINCT
      node1.id AS id1, node2.id AS id2, node3.id AS id3, node4.id AS id4, node5.id AS id5, node6.id AS id6, node1.toplevel_corpus
    FROM
      node AS node1, rank AS rank1, component AS component1, node_annotation AS node_annotation1,
      node AS node2, rank AS rank2, component AS component2, edge_annotation AS edge_annotation2,
      node AS node3, rank AS rank3, component AS component3, node_annotation AS node_annotation3,
      node AS node4, rank AS rank4, component AS component4, edge_annotation AS edge_annotation4,
      node AS node5, rank AS rank5, component AS component5, node_annotation AS node_annotation5,
      node AS node6, rank AS rank6, component AS component6, node_annotation AS node_annotation6
    WHERE
      component2.name IS NULL AND
      component2.type = 'd' AND
      component3.name IS NULL AND
      component3.type = 'd' AND
      component4.name IS NULL AND
      component4.type = 'd' AND
      edge_annotation2.name = 'func' AND
      edge_annotation2.rank_ref = rank2.pre AND
      edge_annotation2.value = 'OA' AND
      edge_annotation4.name = 'func' AND
      edge_annotation4.rank_ref = rank4.pre AND
      edge_annotation4.value = 'SB' AND
      node1.corpus_ref = node2.corpus_ref AND
      node1.corpus_ref = node3.corpus_ref AND
      node1.corpus_ref = node4.corpus_ref AND
      node1.corpus_ref = node5.corpus_ref AND
      node1.corpus_ref = node6.corpus_ref AND
      node1.id = node5.id AND
      node1.id = node6.id AND
      node2.corpus_ref = node4.corpus_ref AND
      node2.corpus_ref = node5.corpus_ref AND
      node2.corpus_ref = node6.corpus_ref AND
      node2.right_token BETWEEN SYMMETRIC node3.left_token - 1 AND node3.left_token - 50 AND
      node2.text_ref = node3.text_ref AND
      node3.corpus_ref = node5.corpus_ref AND
      node3.corpus_ref = node6.corpus_ref AND
      node3.right_token BETWEEN SYMMETRIC node4.left_token - 1 AND node4.left_token - 50 AND
      node3.text_ref = node4.text_ref AND
      node4.corpus_ref = node5.corpus_ref AND
      node4.corpus_ref = node6.corpus_ref AND
      node5.corpus_ref = node6.corpus_ref AND
      node_annotation1.name = 'cat' AND
      node_annotation1.node_ref = node1.id AND
      node_annotation1.value = 'S' AND
      node_annotation3.name = 'pos' AND
      node_annotation3.node_ref = node3.id AND
      node_annotation3.value = 'VVFIN' AND
      node_annotation5.name = 'cat' AND
      node_annotation5.node_ref = node5.id AND
      node_annotation5.value = 'S' AND
      node_annotation6.name = 'cat' AND
      node_annotation6.node_ref = node6.id AND
      node_annotation6.value = 'S' AND
      rank1.component_ref = component1.id AND
      rank1.node_ref = node1.id AND
      rank1.pre = rank4.parent AND
      rank2.component_ref = component2.id AND
      rank2.node_ref = node2.id AND
      rank3.component_ref = component3.id AND
      rank3.node_ref = node3.id AND
      rank4.component_ref = component4.id AND
      rank4.node_ref = node4.id AND
      rank5.component_ref = component5.id AND
      rank5.node_ref = node5.id AND
      rank5.pre = rank2.parent AND
      rank6.component_ref = component6.id AND
      rank6.node_ref = node6.id AND
      rank6.pre = rank3.parent
  ) AS solutions;
