SciPy
Need help? Have a feature request? Please check out the tethne-users group .

Source code for tethne.tests.test_networks_papers

import sys
sys.path.append('../tethne')

import unittest

import networkx as nx

from tethne.readers.wos import read
from tethne.networks.papers import *

datapath = './tethne/tests/data/wos2.txt'


[docs]class TestAuthorPapers(unittest.TestCase):
[docs] def setUp(self): self.corpus = read(datapath)
[docs] def test_direct_citation(self): g = direct_citation(self.corpus) self.assertIsInstance(g, nx.DiGraph) self.assertGreater(g.order(), 0) self.assertGreater(g.size(), 0) types = set([attr['type'] for n, attr in g.nodes(data=True)]) self.assertEqual(len(types), 2, "Bipartite graph") self.assertSetEqual(types, set(['paper', 'citations']), "Containing papers and their citations.")
[docs] def test_bibliographic_coupling(self): g = bibliographic_coupling(self.corpus) self.assertIsInstance(g, nx.Graph) self.assertGreater(g.order(), 0) self.assertGreater(g.size(), 0) for s, t, attrs in g.edges(data=True): self.assertIn('weight', attrs) self.assertIn('features', attrs) for f in attrs['features']: self.assertIn(f, self.corpus.indices['citations'])
[docs] def test_cocitation(self): g = cocitation(self.corpus, min_weight=2) self.assertIsInstance(g, nx.Graph) self.assertGreater(g.order(), 0) self.assertGreater(g.size(), 0) for s, t, attrs in g.edges(data=True): self.assertIn('weight', attrs)
[docs] def test_author_coupling(self): g = author_coupling(self.corpus) self.assertIsInstance(g, nx.Graph) self.assertGreater(g.order(), 0) self.assertGreater(g.size(), 0) for s, t, attrs in g.edges(data=True): self.assertIn('weight', attrs) self.assertIn('features', attrs) for f in attrs['features']: self.assertIn(f, self.corpus.indices['authors'])
[docs]class TestAuthorPapersWithStreaming(unittest.TestCase):
[docs] def setUp(self): self.corpus = read(datapath, streaming=True)
[docs] def test_direct_citation(self): g = direct_citation(self.corpus) self.assertIsInstance(g, nx.DiGraph) self.assertGreater(g.order(), 0) self.assertGreater(g.size(), 0) types = set([attr['type'] for n, attr in g.nodes(data=True)]) self.assertEqual(len(types), 2, "Bipartite graph") self.assertSetEqual(types, set(['paper', 'citations']), "Containing papers and their citations.")
[docs] def test_bibliographic_coupling(self): g = bibliographic_coupling(self.corpus) self.assertIsInstance(g, nx.Graph) self.assertGreater(g.order(), 0) self.assertGreater(g.size(), 0) for s, t, attrs in g.edges(data=True): self.assertIn('weight', attrs) self.assertIn('features', attrs) for f in attrs['features']: self.assertIn(f, self.corpus.indices['citations'])
[docs] def test_cocitation(self): g = cocitation(self.corpus, min_weight=2) self.assertIsInstance(g, nx.Graph) self.assertGreater(g.order(), 0) self.assertGreater(g.size(), 0) for s, t, attrs in g.edges(data=True): self.assertIn('weight', attrs)
[docs] def test_author_coupling(self): g = author_coupling(self.corpus) self.assertIsInstance(g, nx.Graph) self.assertGreater(g.order(), 0) self.assertGreater(g.size(), 0) for s, t, attrs in g.edges(data=True): self.assertIn('weight', attrs) self.assertIn('features', attrs) for f in attrs['features']: self.assertIn(f, self.corpus.indices['authors'])
if __name__ == '__main__': unittest.main()