def test_cite(self):
     Gdefault = self.RC.networkCitation(fullInfo = True, count = False, dropAnon = True)
     Ganon = self.RC.networkCitation(dropAnon = False)
     Gauths = self.RC.networkCitation(nodeType = "author", detailedCore = True, dropAnon = True)
     GauthsNoExtra = self.RC.networkCitation(nodeType = "author", nodeInfo = False, dropAnon = True)
     Gunwei = self.RC.networkCitation(nodeType = 'original', weighted = False)
     if not disableJournChecking:
         Gjour = self.RC.networkCitation(nodeType = "author", dropNonJournals = True, nodeInfo = True, count = False)
     Gyear = self.RC.networkCitation(nodeType = "year", nodeInfo = True)
     Gcore = self.RC.networkCitation(detailedCore = True, coreOnly = False)
     Gexplode = self.RC.networkCitation(expandedCore = True, keyWords = ['b', 'c'])
     self.assertIsInstance(Gdefault, nx.classes.digraph.DiGraph)
     self.assertLessEqual(len(Gdefault.edges()), len(Gunwei.edges()))
     self.assertLessEqual(len(Gdefault.nodes()), len(Gunwei.nodes()))
     self.assertEqual(len(GauthsNoExtra.edges()), len(Gauths.edges()))
     self.assertEqual(len(GauthsNoExtra.nodes()), len(Gauths.nodes()))
     self.assertTrue('weight' in Gdefault.edges(data = True)[0][2])
     self.assertTrue('info' in Gdefault.nodes(data = True)[0][1])
     self.assertFalse('weight' in Gunwei.edges(data = True)[0][2])
     self.assertEqual(metaknowledge.graphStats(Gdefault, sentenceString = True), "The graph has 510 nodes, 816 edges, 1 isolates, 0 self loops, a density of 0.00314342 and a transitivity of 0.00600437")
     self.assertEqual(metaknowledge.graphStats(Ganon, sentenceString = True), "The graph has 511 nodes, 817 edges, 0 isolates, 0 self loops, a density of 0.00313495 and a transitivity of 0.00600437")
     self.assertEqual(metaknowledge.graphStats(Gauths, sentenceString = True), "The graph has 324 nodes, 568 edges, 1 isolates, 15 self loops, a density of 0.00542751 and a transitivity of 0.0210315")
     if not disableJournChecking:
         self.assertEqual(len(Gjour.edges()), 432)
         self.assertTrue('info' in Gjour.nodes(data=True)[0][1])
     self.assertTrue('info' in Gyear.nodes(data=True)[0][1])
     self.assertEqual(Gcore.node['Gilles H, 2002, OPT LETT']['info'], 'WOS:000177484300017, Gilles H, Simple technique for measuring the Goos-Hanchen effect with polarization modulation and a position-sensitive detector, OPTICS LETTERS, 27, 1421')
     self.assertEqual(metaknowledge.graphStats(Gexplode, sentenceString = True), "The graph has 19 nodes, 29 edges, 0 isolates, 3 self loops, a density of 0.0847953 and a transitivity of 0.132075")
 def test_coCite(self):
     Gdefault = self.RC.networkCoCitation(fullInfo = True)
     Gauths = self.RC.networkCoCitation(nodeType = "author", dropAnon = False, detailedCore = True)
     GauthsNoExtra = self.RC.networkCoCitation(nodeType = "author", nodeInfo = False)
     Gunwei = self.RC.networkCoCitation(nodeType = 'original', weighted = False)
     if not disableJournChecking:
         Gjour = self.RC.networkCoCitation(nodeType = "journal", dropNonJournals = True)
     Gyear = self.RC.networkCoCitation(nodeType = "year", fullInfo = True, count = False)
     Gcore = self.RC.networkCoCitation(detailedCore = ['AF','AU', 'DE', 'ID', 'PY'], coreOnly = True)
     Gexplode = self.RC.networkCoCitation(expandedCore = True, keyWords = 'a')
     Gcr = self.RC.networkCoCitation(addCR = True, coreOnly = True)
     self.assertIsInstance(Gdefault, nx.classes.graph.Graph)
     self.assertLessEqual(len(Gdefault.edges()), len(Gunwei.edges()))
     self.assertLessEqual(len(Gdefault.nodes()), len(Gunwei.nodes()))
     self.assertEqual(len(GauthsNoExtra.edges()), len(Gauths.edges()))
     self.assertEqual(len(GauthsNoExtra.nodes()), len(Gauths.nodes()) - 1 )
     self.assertTrue('weight' in Gdefault.edges(data = True)[0][2])
     self.assertTrue('info' in Gdefault.nodes(data = True)[0][1])
     self.assertTrue('fullCite' in Gdefault.nodes(data = True)[0][1])
     self.assertFalse('weight' in Gunwei.edges(data = True)[0][2])
     self.assertEqual(metaknowledge.graphStats(Gdefault, sentenceString = True), "The graph has 493 nodes, 13011 edges, 0 isolates, 22 self loops, a density of 0.107282 and a transitivity of 0.611431")
     self.assertEqual(metaknowledge.graphStats(Gauths, sentenceString = True), "The graph has 321 nodes, 6733 edges, 1 isolates, 68 self loops, a density of 0.131094 and a transitivity of 0.598575")
     self.assertEqual(metaknowledge.graphStats(Gyear, sentenceString = True), "The graph has 91 nodes, 1926 edges, 0 isolates, 55 self loops, a density of 0.47033 and a transitivity of 0.702332")
     if not disableJournChecking:
         self.assertEqual(len(Gjour.nodes()), 85)
         self.assertEqual(len(Gjour.edges()), 1195)
         self.assertTrue('info' in Gjour.nodes(data=True)[0][1])
     self.assertTrue('info' in Gyear.nodes(data=True)[0][1])
     self.assertTrue('fullCite' in Gyear.nodes(data = True)[0][1])
     self.assertEqual(Gcore.node['Costadebeauregard O, 1975, CAN J PHYS']['info'], 'COSTADEBEAUREGARD O, COSTADEBEAUREGARD O')
     self.assertEqual(metaknowledge.graphStats(Gexplode, sentenceString = True), "The graph has 73 nodes, 369 edges, 0 isolates, 5 self loops, a density of 0.140411 and a transitivity of 0.523179")
     self.assertIn('AUDOIN C, 1976, J PHYS E SCI INSTRUM', Gcr.node['Huard S, 1979, CAN J PHYS']['citations'])
예제 #3
0
 def test_graphs(self):
     self.assertEqual(
         metaknowledge.graphStats(self.RC.networkCoAuthor(),
                                  sentenceString=True),
         "The graph has 1798 nodes, 89244 edges, 36 isolates, 15 self loops, a density of 0.0552422 and a transitivity of 0.994673"
     )
     self.assertEqual(
         metaknowledge.graphStats(self.RC.networkCitation(),
                                  sentenceString=True),
         "The graph has 10026 nodes, 10362 edges, 0 isolates, 0 self loops, a density of 0.000103094 and a transitivity of 0"
     )
예제 #4
0
 def test_nMode(self):
     G = self.RC.networkMultiMode(metaknowledge.WOS.tagToFullDict.keys())
     Gstem = self.RC.networkMultiMode(
         metaknowledge.WOS.tagToFullDict.keys(), stemmer=lambda x: x[0])
     self.assertEqual(
         metaknowledge.graphStats(G, sentenceString=True),
         'The graph has 1186 nodes, 38564 edges, 0 isolates, 56 self loops, a density of 0.0549192 and a transitivity of 0.295384'
     )
     self.assertEqual(
         metaknowledge.graphStats(Gstem, sentenceString=True),
         'The graph has 50 nodes, 997 edges, 0 isolates, 35 self loops, a density of 0.828571 and a transitivity of 0.855834'
     )
예제 #5
0
 def test_cite(self):
     Gdefault = self.RC.networkCitation(fullInfo=True,
                                        count=False,
                                        dropAnon=True)
     Ganon = self.RC.networkCitation(dropAnon=False)
     Gauths = self.RC.networkCitation(nodeType="author",
                                      detailedCore=True,
                                      dropAnon=True)
     GauthsNoExtra = self.RC.networkCitation(nodeType="author",
                                             nodeInfo=False,
                                             dropAnon=True)
     Gunwei = self.RC.networkCitation(nodeType='original', weighted=False)
     if not disableJournChecking:
         Gjour = self.RC.networkCitation(nodeType="author",
                                         dropNonJournals=True,
                                         nodeInfo=True,
                                         count=False)
     Gyear = self.RC.networkCitation(nodeType="year", nodeInfo=True)
     Gcore = self.RC.networkCitation(detailedCore=True, coreOnly=False)
     Gexplode = self.RC.networkCitation(expandedCore=True,
                                        keyWords=['b', 'c'])
     self.assertIsInstance(Gdefault, nx.classes.digraph.DiGraph)
     self.assertLessEqual(len(Gdefault.edges()), len(Gunwei.edges()))
     self.assertLessEqual(len(Gdefault.nodes()), len(Gunwei.nodes()))
     self.assertEqual(len(GauthsNoExtra.edges()), len(Gauths.edges()))
     self.assertEqual(len(GauthsNoExtra.nodes()), len(Gauths.nodes()))
     self.assertTrue('weight' in list(Gdefault.edges(data=True))[0][2])
     self.assertTrue('info' in list(Gdefault.nodes(data=True))[0][1])
     self.assertFalse('weight' in list(Gunwei.edges(data=True))[0][2])
     self.assertEqual(
         metaknowledge.graphStats(Gdefault, sentenceString=True),
         "The graph has 510 nodes, 816 edges, 1 isolates, 0 self loops, a density of 0.00314342 and a transitivity of 0.00600437"
     )
     self.assertEqual(
         metaknowledge.graphStats(Ganon, sentenceString=True),
         "The graph has 511 nodes, 817 edges, 0 isolates, 0 self loops, a density of 0.00313495 and a transitivity of 0.00600437"
     )
     self.assertEqual(
         metaknowledge.graphStats(Gauths, sentenceString=True),
         "The graph has 324 nodes, 568 edges, 1 isolates, 15 self loops, a density of 0.00542751 and a transitivity of 0.0210315"
     )
     if not disableJournChecking:
         self.assertEqual(len(Gjour.edges()), 432)
         self.assertTrue('info' in list(Gjour.nodes(data=True))[0][1])
     self.assertTrue('info' in list(Gyear.nodes(data=True))[0][1])
     self.assertEqual(
         Gcore.node['Gilles H, 2002, OPT LETT']['info'],
         'WOS:000177484300017, Gilles H, Simple technique for measuring the Goos-Hanchen effect with polarization modulation and a position-sensitive detector, OPTICS LETTERS, 27, 1421'
     )
     self.assertEqual(
         metaknowledge.graphStats(Gexplode, sentenceString=True),
         "The graph has 19 nodes, 29 edges, 0 isolates, 3 self loops, a density of 0.0847953 and a transitivity of 0.132075"
     )
예제 #6
0
 def test_diffusionGraph(self):
     G = metaknowledge.diffusionGraph(self.RC, self.RC)
     Gcr_ut = metaknowledge.diffusionGraph(self.RC,
                                           self.RC,
                                           sourceType="CR",
                                           targetType="UT")
     self.assertEqual(
         metaknowledge.graphStats(G, sentenceString=True),
         'The graph has 42 nodes, 1569 edges, 0 isolates, 35 self loops, a density of 0.91115 and a transitivity of 0.894934'
     )
     self.assertEqual(
         metaknowledge.graphStats(Gcr_ut, sentenceString=True),
         'The graph has 528 nodes, 3591 edges, 246 isolates, 0 self loops, a density of 0.0129054 and a transitivity of 0'
     )
예제 #7
0
 def test_twoMode(self):
     self.RC.dropBadEntries()
     Gutti = self.RC.networkTwoMode('UT',
                                    'title',
                                    directed=True,
                                    recordType=False)
     Gafwc = self.RC.networkTwoMode('AF',
                                    'WC',
                                    nodeCount=False,
                                    edgeWeight=False)
     Gd2em = self.RC.networkTwoMode('D2', 'email')
     Gemd2 = self.RC.networkTwoMode('email', 'D2')
     Gstemm = self.RC.networkTwoMode('title',
                                     'title',
                                     stemmerTag1=lambda x: x[:-1],
                                     stemmerTag2=lambda x: x + 's')
     self.assertIsInstance(Gutti, nx.classes.digraph.DiGraph)
     self.assertIsInstance(Gafwc, nx.classes.graph.Graph)
     self.assertEqual(
         list(Gutti.edges('WOS:A1979GV55600001'))[0][1][:31],
         "EXPERIMENTS IN PHENOMENOLOGICAL")
     self.assertEqual(len(Gutti.nodes()), 2 * len(self.RC) - 1)
     with self.assertRaises(metaknowledge.TagError):
         G = self.RC.networkTwoMode('TI', b'not a tag')
         del G
     with self.assertRaises(metaknowledge.TagError):
         G = self.RC.networkTwoMode(b'Not a Tag', 'TI')
         del G
     self.assertTrue(nx.is_isomorphic(Gd2em, Gemd2))
     self.assertEqual(
         metaknowledge.graphStats(Gstemm, sentenceString=True),
         'The graph has 62 nodes, 31 edges, 0 isolates, 0 self loops, a density of 0.0163934 and a transitivity of 0'
     )
     self.assertTrue(
         'Optical properties of nanostructured thin filmss' in Gstemm)
 def test_coCite(self):
     Gdefault = self.RC.coCiteNetwork(fullInfo = True)
     Gauths = self.RC.coCiteNetwork(nodeType = "author", dropAnon = False, detailedCore = True)
     GauthsNoExtra = self.RC.coCiteNetwork(nodeType = "author", nodeInfo = False)
     Gunwei = self.RC.coCiteNetwork(nodeType = 'original', weighted = False)
     Gjour = self.RC.coCiteNetwork(nodeType = "journal", dropNonJournals = True)
     Gyear = self.RC.coCiteNetwork(nodeType = "year", fullInfo = True, count = False)
     Gcore = self.RC.coCiteNetwork(detailedCore = ['AF','AU', 'DE', 'ID', 'PY'], coreOnly = True)
     Gexplode = self.RC.coCiteNetwork(expandedCore = True, keyWords = 'a')
     self.assertIsInstance(Gdefault, nx.classes.graph.Graph)
     self.assertLessEqual(len(Gdefault.edges()), len(Gunwei.edges()))
     self.assertLessEqual(len(Gdefault.nodes()), len(Gunwei.nodes()))
     self.assertEqual(len(GauthsNoExtra.edges()), len(Gauths.edges()))
     self.assertEqual(len(GauthsNoExtra.nodes()), len(Gauths.nodes()) - 1 )
     self.assertTrue('weight' in Gdefault.edges(data = True)[0][2])
     self.assertTrue('info' in Gdefault.nodes(data = True)[0][1])
     self.assertTrue('fullCite' in Gdefault.nodes(data = True)[0][1])
     self.assertFalse('weight' in Gunwei.edges(data = True)[0][2])
     self.assertEqual(len(Gdefault.nodes()), 492)
     self.assertEqual(len(Gdefault.edges()), 12968)
     self.assertEqual(len(Gauths.nodes()), 323)
     self.assertEqual(len(Gauths.edges()), 6777)
     self.assertEqual(len(Gyear.nodes()), 91)
     self.assertEqual(len(Gyear.edges()), 1926)
     self.assertEqual(len(Gjour.nodes()), 85)
     self.assertEqual(len(Gjour.edges()), 1195)
     self.assertTrue('info' in Gjour.nodes(data=True)[0][1])
     self.assertTrue('info' in Gyear.nodes(data=True)[0][1])
     self.assertTrue('fullCite' in Gyear.nodes(data = True)[0][1])
     self.assertEqual(Gcore.node['Costadebeauregard O, 1975, CAN J PHYS']['info'], 'COSTADEBEAUREGARD O, COSTADEBEAUREGARD O')
     self.assertEqual(metaknowledge.graphStats(Gexplode), "The graph has 72 nodes, 365 edges, 0 isolates, 6 self loops, a density of 0.142801 and a transitivity of 0.528532")
 def test_coAuth(self):
     Gdefault = self.RC.coAuthNetwork()
     Gdetailed = self.RC.coAuthNetwork(count = False, weighted = False, detailedInfo = True, dropNonJournals = True)
     self.assertIsInstance(Gdefault, nx.classes.graph.Graph)
     self.assertEqual(len(Gdefault.nodes()), 45)
     self.assertEqual(len(Gdefault.edges()), 46)
     self.assertEqual(metaknowledge.graphStats(Gdetailed), 'The graph has 45 nodes, 46 edges, 9 isolates, 0 self loops, a density of 0.0464646 and a transitivity of 0.822581')
 def test_Cite(self):
     Gdefault = self.RC.citationNetwork(fullInfo = True, count = False)
     Ganon = self.RC.citationNetwork(dropAnon = False)
     Gauths = self.RC.citationNetwork(nodeType = "author", detailedCore = True)
     GauthsNoExtra = self.RC.citationNetwork(nodeType = "author", nodeInfo = False)
     Gunwei = self.RC.citationNetwork(nodeType = 'original', weighted = False)
     Gjour = self.RC.citationNetwork(nodeType = "author", dropNonJournals = True, nodeInfo = True, count = False)
     Gyear = self.RC.citationNetwork(nodeType = "year", nodeInfo = True)
     Gcore = self.RC.citationNetwork(detailedCore = True, coreOnly = False)
     Gexplode = self.RC.citationNetwork(expandedCore = True, keyWords = ['b', 'c'])
     self.assertIsInstance(Gdefault, nx.classes.digraph.DiGraph)
     self.assertLessEqual(len(Gdefault.edges()), len(Gunwei.edges()))
     self.assertLessEqual(len(Gdefault.nodes()), len(Gunwei.nodes()))
     self.assertEqual(len(GauthsNoExtra.edges()), len(Gauths.edges()))
     self.assertEqual(len(GauthsNoExtra.nodes()), len(Gauths.nodes()))
     self.assertTrue('weight' in Gdefault.edges(data = True)[0][2])
     self.assertTrue('info' in Gdefault.nodes(data = True)[0][1])
     self.assertFalse('weight' in Gunwei.edges(data = True)[0][2])
     self.assertEqual(len(Gdefault.nodes()), 509)
     self.assertEqual(len(Ganon.nodes()), 510)
     self.assertEqual(len(Gauths.nodes()), 326)
     self.assertEqual(len(Gdefault.edges()), 815)
     self.assertEqual(len(Ganon.edges()), 816)
     self.assertEqual(len(Gauths.edges()), 570)
     self.assertEqual(len(Gjour.edges()), 432)
     self.assertTrue('info' in Gjour.nodes(data=True)[0][1])
     self.assertTrue('info' in Gyear.nodes(data=True)[0][1])
     self.assertEqual(Gcore.node['Gilles H, 2002, OPT LETT']['info'], 'Gilles H, Simple technique for measuring the Goos-Hanchen effect with polarization modulation and a position-sensitive detector, OPTICS LETTERS, 27, 1421')
     self.assertEqual(metaknowledge.graphStats(Gexplode), "The graph has 19 nodes, 29 edges, 0 isolates, 3 self loops, a density of 0.0847953 and a transitivity of 0.132075")
예제 #11
0
 def test_oneMode(self):
     Gcr = self.RC.networkOneMode('CR')
     Gcite = self.RC.networkOneMode('citations',
                                    nodeCount=False,
                                    edgeWeight=False)
     GcoCit = self.RC.networkCoCitation()
     Gtit = self.RC.networkOneMode('title')
     stemFunc = lambda x: x[:-1]
     Gstem = self.RC.networkOneMode('keywords', stemmer=stemFunc)
     self.assertEqual(len(Gcite.edges()), len(Gcr.edges()))
     self.assertEqual(len(Gcite.nodes()), len(Gcr.nodes()))
     self.assertAlmostEqual(len(Gcite.nodes()),
                            len(GcoCit.nodes()),
                            delta=50)
     self.assertEqual(len(self.RC.networkOneMode('D2').nodes()), 0)
     self.assertEqual(len(Gtit.nodes()), 31)
     self.assertEqual(len(Gtit.edges()), 0)
     self.assertEqual(len(self.RC.networkOneMode('email').edges()), 3)
     self.assertEqual(len(self.RC.networkOneMode('UT').nodes()),
                      len(self.RC) - 1)
     self.assertEqual(
         metaknowledge.graphStats(Gstem, sentenceString=True),
         'The graph has 41 nodes, 142 edges, 2 isolates, 0 self loops, a density of 0.173171 and a transitivity of 0.854015'
     )
     self.assertIsInstance(list(Gstem.nodes())[0], str)
     with self.assertRaises(TypeError):
         G = self.RC.networkOneMode(b'Not a Tag')
         del G
 def test_dropNodeByCount(self):
     metaknowledge.dropNodesByCount(self.G, minCount=2, maxCount=5)
     self.assertEqual(
         metaknowledge.graphStats(self.G, sentenceString=True),
         "The graph has 106 nodes, 1214 edges, 0 isolates, 17 self loops, a density of 0.218149 and a transitivity of 0.751036"
     )
     self.assertTrue(self.G.node['Shih H, 1971, PHYS REV A']['count'] == 2)
예제 #13
0
 def test_NSF(self):
     GC = metaknowledge.GrantCollection("metaknowledge/tests/nsfTestFiles")
     G = GC.networkMultiMode(GC.tags())
     self.assertEqual(
         metaknowledge.graphStats(G, sentenceString=True),
         "The graph has 244 nodes, 2077 edges, 0 isolates, 19 self loops, a density of 0.0703974 and a transitivity of 0.497237"
     )
 def test_dropNodesByDegree(self):
     metaknowledge.dropNodesByDegree(self.G, minDegree=20, maxDegree=100)
     self.assertEqual(
         metaknowledge.graphStats(self.G, sentenceString=True),
         "The graph has 385 nodes, 5929 edges, 0 isolates, 11 self loops, a density of 0.0802083 and a transitivity of 0.954487"
     )
     self.assertTrue(self.G.edge['Mazur P, 1953, MEM ACAD ROY BELG']
                     ['Livens Gh, 1948, P CAMB PHILOS SOC']['weight'] == 1)
예제 #15
0
 def test_multiGraph(self):
     G = metaknowledge.diffusionGraph(self.RC, self.RC, labelEdgesBy='PY')
     metaknowledge.dropEdges(G, dropSelfLoops=True)
     #multigraphs have issues their edge counts are somewhat unpredictable
     self.assertEqual(
         metaknowledge.graphStats(G,
                                  stats=('nodes', 'isolates', 'loops'),
                                  sentenceString=True),
         'The graph has 42 nodes, 0 isolates and 0 self loops')
 def test_coAuth(self):
     Gdefault = self.RC.networkCoAuthor()
     if not disableJournChecking:
         Gdetailed = self.RC.networkCoAuthor(count = False, weighted = False, detailedInfo = True, dropNonJournals = True)
     self.assertIsInstance(Gdefault, nx.classes.graph.Graph)
     self.assertEqual(len(Gdefault.nodes()), 45)
     self.assertEqual(len(Gdefault.edges()), 46)
     if not disableJournChecking:
         self.assertEqual(metaknowledge.graphStats(Gdetailed, sentenceString = True), 'The graph has 45 nodes, 46 edges, 9 isolates, 0 self loops, a density of 0.0464646 and a transitivity of 0.822581')
 def test_dropEdges(self):
     metaknowledge.dropEdges(self.G,
                             minWeight=1,
                             maxWeight=3,
                             dropSelfLoops=True)
     self.assertEqual(
         metaknowledge.graphStats(self.G, sentenceString=True),
         "The graph has 493 nodes, 12711 edges, 0 isolates, 0 self loops, a density of 0.104809 and a transitivity of 0.588968"
     )
     self.assertTrue(self.G.edge['Imbert C, 1975, NOUV REV OPT']
                     ['Fainman Y, 1984, APPL OPTICS']['weight'] == 1)
예제 #18
0
    def test_Thresholds(self):
        with unittest.mock.patch('builtins.print'):
            with unittest.mock.patch('builtins.input', new_callable = MockInput) as m:
                m.calledVals = ['', '0']
                G = metaknowledge.bin.metaknowledgeCLI.getThresholds(None, self.G)
                self.assertEqual(G, self.G)
                self.assertEqual(len(m.calledVals), 0)

                m.calledVals = ['1', '2', '3', '1', '4', '5', '5', '0', '6', 'ten', '2', '0']
                G = metaknowledge.bin.metaknowledgeCLI.getThresholds(None, self.G)
                self.assertEqual(metaknowledge.graphStats(G, sentenceString = True), 'The graph has 2 nodes, 1 edges, 0 isolates, 0 self loops, a density of 1 and a transitivity of 0')
                self.assertEqual(len(m.calledVals), 0)
예제 #19
0
    def test_graphs(self):
        with unittest.mock.patch('builtins.print'):
            with unittest.mock.patch('builtins.input', new_callable = MockInput) as m:
                m.calledVals = ['1', 'NOT A TAG', 'AF']
                G = metaknowledge.bin.metaknowledgeCLI.getNetwork(None, self.RC)
                self.assertEqual(metaknowledge.graphStats(G, sentenceString = True), 'The graph has 45 nodes, 46 edges, 9 isolates, 0 self loops, a density of 0.0464646 and a transitivity of 0.822581')
                self.assertEqual(len(m.calledVals), 0)

                m.calledVals = ['2', 'AF', 'UT']
                G = metaknowledge.bin.metaknowledgeCLI.getNetwork(None, self.RC)
                self.assertEqual(metaknowledge.graphStats(G, sentenceString = True), 'The graph has 77 nodes, 66 edges, 0 isolates, 0 self loops, a density of 0.0225564 and a transitivity of 0')
                self.assertEqual(len(m.calledVals), 0)

                m.calledVals = ['3'] + list(self.RC.tags()) + ['']
                G = metaknowledge.bin.metaknowledgeCLI.getNetwork(None, self.RC)
                self.assertEqual(metaknowledge.graphStats(G, sentenceString = True), 'The graph has 1186 nodes, 38592 edges, 0 isolates, 56 self loops, a density of 0.0549192 and a transitivity of 0.295384')
                self.assertEqual(len(m.calledVals), 0)

                m.calledVals = ['4']
                G = metaknowledge.bin.metaknowledgeCLI.getNetwork(None, self.RC)
                self.assertEqual(metaknowledge.graphStats(G, sentenceString = True), 'The graph has 511 nodes, 817 edges, 0 isolates, 0 self loops, a density of 0.00313495 and a transitivity of 0.00600437')
                self.assertEqual(len(m.calledVals), 0)

                m.calledVals = ['5']
                G = metaknowledge.bin.metaknowledgeCLI.getNetwork(None, self.RC)
                self.assertEqual(metaknowledge.graphStats(G, sentenceString = True), 'The graph has 493 nodes, 13011 edges, 0 isolates, 22 self loops, a density of 0.107282 and a transitivity of 0.611431')
                self.assertEqual(len(m.calledVals), 0)

                m.calledVals = ['6']
                G = metaknowledge.bin.metaknowledgeCLI.getNetwork(None, self.RC)
                self.assertEqual(metaknowledge.graphStats(G, sentenceString = True), 'The graph has 45 nodes, 46 edges, 9 isolates, 0 self loops, a density of 0.0464646 and a transitivity of 0.822581')
                self.assertEqual(len(m.calledVals), 0)
예제 #20
0
 def test_coAuth(self):
     Gdefault = self.RC.networkCoAuthor()
     if not disableJournChecking:
         Gdetailed = self.RC.networkCoAuthor(count=False,
                                             weighted=False,
                                             detailedInfo=True,
                                             dropNonJournals=True)
     self.assertIsInstance(Gdefault, nx.classes.graph.Graph)
     self.assertEqual(len(Gdefault.nodes()), 45)
     self.assertEqual(len(Gdefault.edges()), 46)
     if not disableJournChecking:
         self.assertEqual(
             metaknowledge.graphStats(Gdetailed, sentenceString=True),
             'The graph has 45 nodes, 46 edges, 9 isolates, 0 self loops, a density of 0.0464646 and a transitivity of 0.822581'
         )
 def test_twoMode(self):
     self.RC.dropBadRecords()
     Gutti = self.RC.twoModeNetwork('UT', 'title', directed = True, recordType = False)
     Gafwc = self.RC.twoModeNetwork('AF', 'WC', nodeCount = False, edgeWeight = False)
     Gd2em = self.RC.twoModeNetwork('D2', 'email')
     Gemd2 = self.RC.twoModeNetwork('email', 'D2')
     Gstemm = self.RC.twoModeNetwork('title', 'title', stemmerTag1 = lambda x: x[:-1], stemmerTag2 = lambda x: x + 's')
     self.assertIsInstance(Gutti, nx.classes.digraph.DiGraph)
     self.assertIsInstance(Gafwc, nx.classes.graph.Graph)
     self.assertEqual(Gutti.edges('WOS:A1979GV55600001')[0][1][:31], "EXPERIMENTS IN PHENOMENOLOGICAL")
     self.assertEqual(len(Gutti.nodes()), 2 * len(self.RC) - 1)
     with self.assertRaises(TypeError):
         G = self.RC.oneModeNetwork('Not a Tag', 'TI')
         del G
     self.assertTrue(nx.is_isomorphic(Gd2em, Gemd2))
     self.assertEqual(metaknowledge.graphStats(Gstemm), 'The graph has 62 nodes, 31 edges, 0 isolates, 0 self loops, a density of 0.0163934 and a transitivity of 0')
     self.assertTrue('Optical properties of nanostructured thin filmss' in Gstemm)
 def test_oneMode(self):
     Gcr  = self.RC.oneModeNetwork('CR')
     Gcite = self.RC.oneModeNetwork('citations', nodeCount = False, edgeWeight = False)
     GcoCit = self.RC.coCiteNetwork()
     Gtit = self.RC.oneModeNetwork('title')
     stemFunc = lambda x: x[:-1]
     Gstem = self.RC.oneModeNetwork('keywords', stemmer = stemFunc)
     self.assertEqual(len(Gcite.edges()), len(Gcr.edges()))
     self.assertEqual(len(Gcite.nodes()), len(Gcr.nodes()))
     self.assertAlmostEqual(len(Gcite.nodes()), len(GcoCit.nodes()), delta = 50)
     self.assertEqual(len(self.RC.oneModeNetwork('D2').nodes()), 0)
     self.assertEqual(len(Gtit.nodes()), 31)
     self.assertEqual(len(Gtit.edges()), 0)
     self.assertEqual(len(self.RC.oneModeNetwork('email').edges()), 3)
     self.assertEqual(len(self.RC.oneModeNetwork('UT').nodes()), len(self.RC) - 1)
     self.assertEqual(metaknowledge.graphStats(Gstem), 'The graph has 41 nodes, 142 edges, 2 isolates, 0 self loops, a density of 0.173171 and a transitivity of 0.854015')
     self.assertIsInstance(Gstem.nodes()[0], str)
     with self.assertRaises(TypeError):
         G = self.RC.oneModeNetwork('Not a Tag')
         del G
예제 #23
0
 def test_diffusionGraph(self):
     G = metaknowledge.diffusionGraph(self.RC, self.RC)
     Gcr_ut = metaknowledge.diffusionGraph(self.RC, self.RC, sourceType = "CR", targetType = "UT")
     self.assertEqual(metaknowledge.graphStats(G), 'The graph has 33 nodes, 31 edges, 11 isolates, 0 self loops, a density of 0.0293561 and a transitivity of 0.127907')
     self.assertEqual(metaknowledge.graphStats(Gcr_ut), 'The graph has 525 nodes, 597 edges, 254 isolates, 0 self loops, a density of 0.00217012 and a transitivity of 0')
     self.assertEqual(G.edges(data = True).pop()[2]['weight'], 1)
 def test_nMode(self):
     G = self.RC.networkMultiMode(metaknowledge.WOS.tagToFullDict.keys())
     Gstem = self.RC.networkMultiMode(metaknowledge.WOS.tagToFullDict.keys(), stemmer = lambda x : x[0])
     self.assertEqual(metaknowledge.graphStats(G, sentenceString = True), 'The graph has 1186 nodes, 38592 edges, 0 isolates, 56 self loops, a density of 0.0549192 and a transitivity of 0.295384')
     self.assertEqual(metaknowledge.graphStats(Gstem, sentenceString = True), 'The graph has 50 nodes, 1015 edges, 0 isolates, 35 self loops, a density of 0.828571 and a transitivity of 0.855834')
예제 #25
0
 def test_nLevel(self):
     G = self.RC.networkMultiLevel(*tuple(self.RC.tags()))
     self.assertEqual(
         metaknowledge.graphStats(G, sentenceString=True),
         'The graph has 1187 nodes, 58731 edges, 0 isolates, 59 self loops, a density of 0.0834803 and a transitivity of 0.493814'
     )
예제 #26
0
 def test_multiGraph(self):
     G = metaknowledge.diffusionGraph(self.RC, self.RC, labelEdgesBy = 'PY')
     self.assertEqual(metaknowledge.graphStats(G, stats = ('nodes', 'edges', 'isolates', 'loops', 'density')), 'The graph has 33 nodes, 31 edges, 11 isolates, 0 self loops and a density of 0.0293561')
예제 #27
0
 def test_graphs(self):
     self.assertEqual(metaknowledge.graphStats(self.RC.networkMultiMode(self.RC.tags()), sentenceString = True), "The graph has 1928 nodes, 50890 edges, 0 isolates, 114 self loops, a density of 0.0273952 and a transitivity of 0.0815136")
예제 #28
0
 def test_networkBibCoupling(self):
     G = self.RC.networkBibCoupling()
     self.assertEqual(
         metaknowledge.graphStats(G, sentenceString=True),
         'The graph has 32 nodes, 304 edges, 1 isolates, 0 self loops, a density of 0.612903 and a transitivity of 0.836511'
     )
 def test_CoInstitution(self):
     G = self.GC.networkCoInvestigatorInstitution()
     self.assertEqual(metaknowledge.graphStats(G), 'Nodes: 641\nEdges: 2034\nIsolates: 79\nSelf loops: 0\nDensity: 0.00991615\nTransitivity: 0.273548')
예제 #30
0
import metaknowledge as mk
import networkx as nx
import matplotlib.pyplot as plt
import metaknowledge.contour.plotting as mkv

RC = mk.RecordCollection('./tmp/savedrecs.txt')

CoCitation = RC.networkCoCitation()

print(mk.graphStats(CoCitation, makeString=True))

# print(CoCitation.nodes(data = True)[0])

# print(CoCitation.edges(data = True)[0])

coCiteJournals = RC.networkCoCitation(nodeType='journal', dropNonJournals=True)
print(mk.graphStats(coCiteJournals))

nx.draw_spring(coCiteJournals)
 def test_dropNodeByCount(self):
     metaknowledge.dropNodesByCount(self.G, minCount = 2, maxCount = 5)
     self.assertEqual(metaknowledge.graphStats(self.G), "The graph has 105 nodes, 1198 edges, 0 isolates, 17 self loops, a density of 0.219414 and a transitivity of 0.753426")
     self.assertTrue(self.G.node['Shih H, 1971, PHYS REV A']['count'] == 2)
예제 #32
0
 def test_CoInstitution(self):
     G = self.GC.networkCoInvestigatorInstitution()
     self.assertEqual(
         metaknowledge.graphStats(G),
         'Nodes: 641\nEdges: 2034\nIsolates: 79\nSelf loops: 0\nDensity: 0.00991615\nTransitivity: 0.273548'
     )
 def test_dropNodesByDegree(self):
     metaknowledge.dropNodesByDegree(self.G, minDegree = 20, maxDegree = 100)
     self.assertEqual(metaknowledge.graphStats(self.G), "The graph has 384 nodes, 5902 edges, 0 isolates, 11 self loops, a density of 0.08026 and a transitivity of 0.954765")
     self.assertTrue(self.G.edge['Mazur P, 1953, MEM ACAD ROY BELG']['Livens Gh, 1948, P CAMB PHILOS SOC']['weight'] == 1)
예제 #34
0
 def test_graphs(self):
     self.assertEqual(
         metaknowledge.graphStats(self.RC.networkMultiMode(self.RC.tags()),
                                  sentenceString=True),
         "The graph has 1928 nodes, 50833 edges, 0 isolates, 114 self loops, a density of 0.0273952 and a transitivity of 0.0815136"
     )
예제 #35
0
 def test_graphs(self):
     self.assertEqual(metaknowledge.graphStats(self.RC.networkCoAuthor(), sentenceString = True), "The graph has 1798 nodes, 89244 edges, 36 isolates, 15 self loops, a density of 0.0552422 and a transitivity of 0.994673")
     self.assertEqual(metaknowledge.graphStats(self.RC.networkCitation(), sentenceString = True), "The graph has 10026 nodes, 10362 edges, 0 isolates, 0 self loops, a density of 0.000103094 and a transitivity of 0")
 def test_nLevel(self):
     G = self.RC.networkMultiLevel(*tuple(self.RC.tags()))
     self.assertEqual(metaknowledge.graphStats(G, sentenceString = True), 'The graph has 1187 nodes, 58761 edges, 0 isolates, 59 self loops, a density of 0.0834803 and a transitivity of 0.493814')
 def test_dropEdges(self):
     metaknowledge.dropEdges(self.G, minWeight = 1, maxWeight = 3, dropSelfLoops = True)
     self.assertEqual(metaknowledge.graphStats(self.G), "The graph has 492 nodes, 12660 edges, 0 isolates, 0 self loops, a density of 0.104813 and a transitivity of 0.58952")
     self.assertTrue(self.G.edge['Imbert C, 1975, NOUV REV OPT']['Fainman Y, 1984, APPL OPTICS']['weight'] == 1)
 def test_networkBibCoupling(self):
     G = self.RC.networkBibCoupling()
     self.assertEqual(metaknowledge.graphStats(G, sentenceString = True), 'The graph has 32 nodes, 304 edges, 1 isolates, 0 self loops, a density of 0.612903 and a transitivity of 0.836511')
예제 #39
0
 def test_NSF(self):
     GC = metaknowledge.GrantCollection("metaknowledge/tests/nsfTestFiles")
     G = GC.networkMultiMode(GC.tags())
     self.assertEqual(metaknowledge.graphStats(G, sentenceString = True), "The graph has 244 nodes, 2087 edges, 0 isolates, 19 self loops, a density of 0.0703974 and a transitivity of 0.497237")
예제 #40
0
print(RC.glimpse())

# ## Network Analysis
#
# Network analysis lets us see the relationships, distances and co-occurrences between the nodes in a network. Here's how we can conduct a network analysis of co-authors in this dataset.

# In[ ]:

# Generating the co-author network
coauth_net = RC.networkCoAuthor()
coauth_net

# In[ ]:

# Printing the network stats
print(mk.graphStats(coauth_net))

# There are 10104 nodes (authors) in the network who are connected by 15507 edges. Of these authors, 1111 are isolates (unconnected to others).
#
# Next, we will drop self-loops and any authors with fewer than 2 edges (co-authors). For our analysis we will extract the "giant component", which is the largest subgraph of connected nodes in a network graph. The giant component typically contains a significant proportion of the nodes in the network. We'll use Python's networkx package for this and subsequent tasks.

# In[ ]:

mk.dropEdges(coauth_net, minWeight=2, dropSelfLoops=True)
giant_coauth = max(nx.connected_component_subgraphs(coauth_net), key=len)
print(mk.graphStats(giant_coauth))

# We are left with 265 authors, all of whom have at least two co-authors. We can see the graph density has gone up because of our filtering criteria.
#
# Centrality is a key concept in network analysis. The degree, closeness, betweenness and eigenvector centralities tell us which nodes (authors) are the most important. These are calculated from the number of links to other nodes, the length of the paths to other nodes, the number of times the node acts as a bridge along the shortest path between other nodes, and the relative influence of the node, respectively.
#
예제 #41
0
 def test_multiGraph(self):
     G = metaknowledge.diffusionGraph(self.RC, self.RC, labelEdgesBy = 'PY')
     metaknowledge.dropEdges(G, dropSelfLoops = True)
     #multigraphs have issues their edge counts are somewhat unpredictable
     self.assertEqual(metaknowledge.graphStats(G, stats = ('nodes', 'isolates', 'loops'), sentenceString = True), 'The graph has 42 nodes, 0 isolates and 0 self loops')
 def test_nMode(self):
     G = self.RC.nModeNetwork(metaknowledge.tagProcessing.tagToFullDict.keys())
     Gstem = self.RC.nModeNetwork(metaknowledge.tagProcessing.tagToFullDict.keys(), stemmer = lambda x : x[0])
     self.assertEqual(metaknowledge.graphStats(G), 'The graph has 1186 nodes, 38592 edges, 0 isolates, 56 self loops, a density of 0.0549192 and a transitivity of 0.295384')
     self.assertEqual(metaknowledge.graphStats(Gstem), 'The graph has 50 nodes, 1015 edges, 0 isolates, 35 self loops, a density of 0.828571 and a transitivity of 0.855834')
예제 #43
0
 def test_diffusionGraph(self):
     G = metaknowledge.diffusionGraph(self.RC, self.RC)
     Gcr_ut = metaknowledge.diffusionGraph(self.RC, self.RC, sourceType = "CR", targetType = "UT")
     self.assertEqual(metaknowledge.graphStats(G, sentenceString = True), 'The graph has 42 nodes, 1569 edges, 0 isolates, 35 self loops, a density of 0.91115 and a transitivity of 0.894934')
     self.assertEqual(metaknowledge.graphStats(Gcr_ut, sentenceString = True), 'The graph has 528 nodes, 3591 edges, 246 isolates, 0 self loops, a density of 0.0129054 and a transitivity of 0')