docs: def cooccurrence(corpus_or_featureset, featureset_name=None, min_weight=1,
                   edge_attrs=['ayjid', 'date'],
                   filter=None):
      """
      A network of feature elements linked by their joint occurrence in papers.
      """
  
      if not filter:
          filter = lambda f, v, c, dc: dc >= min_weight
  
      featureset = _get_featureset(corpus_or_featureset, featureset_name)
  
      if type(corpus_or_featureset) in [Corpus, StreamingCorpus]:
          attributes = {i: {a: corpus_or_featureset.indices_lookup[i][a] for a in edge_attrs}
                        for i in corpus_or_featureset.indexed_papers.keys()}
  
      c = lambda f: featureset.count(f)           # Overall count.
      dc = lambda f: featureset.documentCount(f)  # Document count.
      attributes = {}
  
      # select applies filter to the elements in a (Structured)Feature. The
      #  iteration behavior of Feature and StructuredFeature are different, as is
      #  the manner in which the count for an element in each (Structured)Feature.
      if type(featureset) is FeatureSet:
          select = lambda feature: [f for f, v in feature
                                    if filter(f, v, c(f), dc(f))]
      elif type(featureset) is StructuredFeatureSet:
          select = lambda feature: [f for f in feature
                                    if filter(f, feature.count(f), c(f), dc(f))]
  
      pairs = Counter()
      eattrs = defaultdict(dict)
      nattrs = defaultdict(dict)
      nset = set()
  
      for paper, feature in featureset.iteritems():
          if len(feature) == 0:
              continue
  
          selected = select(feature)
          nset |= set(selected)
          for combo in combinations(selected, 2):
              combo = tuple(sorted(combo))
              pairs[combo] += 1
  
              if paper in attributes:
                  eattrs[combo] = attributes[paper]
  
      # Generate node attributes.
      for n in list(nset):
          nattrs[n]['count'] = featureset.count(n)
          nattrs[n]['documentCount'] = featureset.documentCount(n)
  
      return _generate_graph(nx.Graph, pairs, edge_attrs=eattrs,
                              node_attrs=nattrs, min_weight=min_weight)