コード例 #1
0
def topic_coupling(model, threshold=None, **kwargs):
    """
    Two papers are coupled if they both contain a shared topic above a
    ``threshold``.

    Parameters
    ----------
    model : :class:`.LDAModel`
    threshold : float
        Default: ``3./model.Z``
    kwargs : kwargs
        Passed on to :func:`.coupling`\.

    Returns
    -------
    :ref:`networkx.Graph <networkx:graph>`

    """
    if not threshold:
        threshold = 3. / model.Z
    select = lambda f, v, c, dc: v > threshold

    graph = coupling(model.corpus, 'topics', filter=select, **kwargs)
    graph.name = ''
    return graph
コード例 #2
0
 def test_coupling(self):
     g = coupling(self.corpus, 'citations')
     self.assertIsInstance(g, nx.Graph)
     self.assertGreater(len(g.nodes()), 0)
     self.assertGreater(len(g.edges()), 0)
     for s, t, attrs in g.edges(data=True):
         self.assertEqual(len(attrs['features']), attrs['weight'])
コード例 #3
0
def bibliographic_coupling(corpus, min_weight=1, **kwargs):
    """
    Generate a bibliographic coupling network.

    Two papers are **bibliographically coupled** when they both cite the same,
    third, paper.
    """
    return coupling(corpus, 'citations', min_weight=min_weight, **kwargs)
コード例 #4
0
    def test_coupling_min_weight(self):
        """
        Limit edges to weight >= 3.
        """

        min_weight = 3
        g = coupling(self.corpus, 'citations')
        g2 = coupling(self.corpus, 'citations', min_weight=min_weight)

        self.assertIsInstance(g, nx.Graph)
        self.assertGreater(len(g2.nodes()), 0)
        self.assertGreater(len(g.nodes()), len(g2.nodes()))
        self.assertGreater(len(g2.edges()), 0)
        self.assertGreater(len(g.edges()), len(g2.edges()))

        for s, t, attrs in g2.edges(data=True):
            self.assertGreaterEqual(attrs['weight'], min_weight)
コード例 #5
0
def author_coupling(corpus, min_weight=1, **kwargs):
    return coupling(corpus, 'authors', min_weight=min_weight, **kwargs)