def run(self):

        citationsPublications = {
            'Alice': (100, 10),
            'Bob': (80, 10),
            'Carol': (100, 100),
            'Dave': (10, 10),
            'Ed': (20, 5)

        }

        self.graph, authorMap, conference, citationsPublications = \
            SampleGraphUtility.constructSkewedCitationPublicationExample(
                introduceRandomness=False, citationsPublicationsParameter=citationsPublications
            )

        # Get the nodes we care about
        authors = [
            authorMap['Alice'],
            authorMap['Bob'],
            authorMap['Carol'],
            authorMap['Dave'],
            authorMap['Ed']
        ]

        # Total citation & publication counts
        self.output('\nCitation & Publication Counts')
        adjMatrixTable = texttable.Texttable()
        rows = [['Measure'] + [author.name for author in authors]]
        rows += [['Citations'] + [citationsPublications[author][0] for author in authors]]
        rows += [['Publications'] + [citationsPublications[author][1] for author in authors]]
        adjMatrixTable.add_rows(rows)
        self.output(adjMatrixTable.draw())

        # Output PathSim similarity scores
        pathSimStrategyPubs = NeighborSimStrategy(self.graph, [Conference, Paper, Author], symmetric=True)
        self.outputSimilarityScores(authorMap, authors, pathSimStrategyPubs, 'APCPA PathSim')
        pathSimStrategyCits = NeighborSimStrategy(self.graph, [Conference, Paper, Paper, Author])
        self.outputSimilarityScores(authorMap, authors, pathSimStrategyCits, 'APPCPPA PathSim')
        for w1, w2 in [(0.5, 0.5), (0.6, 0.4), (0.4, 0.6), (0.7, 0.3), (0.3, 0.7)]:
            combinedPathSimStrategy = AggregateSimilarityStrategy(
                self.graph, [pathSimStrategyPubs, pathSimStrategyCits], [w1, w2]
            )
            self.outputSimilarityScores(
                authorMap, authors, combinedPathSimStrategy, 'APCPA-APPCPPAA Pathsim (%1.1f,%1.1f)' % (w1, w2)
            )

        # Output ShapeSim strategy
        w = 1.0
        neighborPathShapeStrategy = VectorProductStrategy(
            self.graph, weight=w, omit=[], metaPath=[Conference, Paper, Paper, Author], symmetric=True
        )
        strategyTitle = 'APPCPPA %s ShapeSim (%1.2f weight)' % ('VectorProduct', w)
        self.outputSimilarityScores(authorMap, authors, neighborPathShapeStrategy, strategyTitle)
    def run(self):

        self.graph, authorMap, conference, citationsPublications = SampleGraphUtility.constructSkewedCitationPublicationExample(
            introduceRandomness=False
        )

        # Get the nodes we care about
        authors = [
            authorMap["Alice"],
            authorMap["Bob"],
            authorMap["Carol"],
            authorMap["Dave"],
            authorMap["Ed"],
            authorMap["Frank"],
        ]
        metaPathUtility = EdgeBasedMetaPathUtility()

        # Output adjacency matrices
        self.output("\nCPA Adjacency Matrix:")
        cpaadjMatrix, nodesIndex = metaPathUtility.getAdjacencyMatrixFromGraph(
            self.graph, [Conference, Paper, Author], project=True
        )
        adjMatrixTable = texttable.Texttable()
        rows = [["Conference"] + [author.name for author in authors]]
        rows += [[conference.name] + [cpaadjMatrix[nodesIndex[conference]][nodesIndex[author]] for author in authors]]
        adjMatrixTable.add_rows(rows)
        self.output(adjMatrixTable.draw())

        self.output("\nCPPA Adjacency Matrix:")
        cpaadjMatrix, nodesIndex = metaPathUtility.getAdjacencyMatrixFromGraph(
            self.graph, [Conference, Paper, Paper, Author], project=True
        )
        adjMatrixTable = texttable.Texttable()
        rows = [["Conference"] + [author.name for author in authors]]
        rows += [[conference.name] + [cpaadjMatrix[nodesIndex[conference]][nodesIndex[author]] for author in authors]]
        adjMatrixTable.add_rows(rows)
        self.output(adjMatrixTable.draw())

        # Total citation & publication counts
        self.output("\nCitation & Publication Counts")
        adjMatrixTable = texttable.Texttable()
        rows = [["Measure"] + [author.name for author in authors]]
        rows += [["Citations"] + [citationsPublications[author][0] for author in authors]]
        rows += [["Publications"] + [citationsPublications[author][1] for author in authors]]
        adjMatrixTable.add_rows(rows)
        self.output(adjMatrixTable.draw())

        # Output NeighborSim & PathSim similarity scores
        neighborSimStrategy = NeighborSimStrategy(self.graph, [Conference, Paper, Author], symmetric=True)
        self.outputSimilarityScores(authorMap, authors, neighborSimStrategy, "APCPA PathSim")
        neighborSimStrategy = NeighborSimStrategy(self.graph, [Conference, Paper, Paper, Author])
        self.outputSimilarityScores(authorMap, authors, neighborSimStrategy, "APPCPPA PathSim")

        # Omit extra duplicate entry in path, and weight at different levels of 'relative'
        for strategy, generalStrategyTitle in [
            (FlattenedMatrixStrategy, "FlatMat"),
            (VectorProductStrategy, "VectorProduct"),
        ]:
            for w in [1.0, 0.5, 0]:
                neighborPathShapeStrategy = strategy(
                    self.graph, weight=w, omit=[], metaPath=[Conference, Paper, Paper, Author], symmetric=True
                )
                strategyTitle = "APPCPPA %s ShapeSim (%1.2f weight)" % (generalStrategyTitle, w)
                self.outputSimilarityScores(authorMap, authors, neighborPathShapeStrategy, strategyTitle)
        w = 1.0
        neighborPathShapeStrategy = VectorProductStrategy(
            self.graph, weight=w, omit=[0], metaPath=[Conference, Paper, Paper, Author], symmetric=True
        )
        strategyTitle = "APPCPPA VectorProduct ShapeSim omitting CPC (%1.2f weight)" % w
        self.outputSimilarityScores(authorMap, authors, neighborPathShapeStrategy, strategyTitle)

        # Output recursive pathsim strategy score(s)
        recursivePathSimStrategy = RecursivePathSimStrategy(self.graph, [Conference, Paper, Paper, Author])
        self.outputSimilarityScores(authorMap, authors, recursivePathSimStrategy, "APPCPPA Recursive PathSim")
예제 #3
0
    def run(self):

        citationsPublications = {
            'Alice': (100, 10),
            'Bob': (80, 10),
            'Carol': (100, 100),
            'Dave': (10, 10),
            'Ed': (20, 5)
        }

        self.graph, authorMap, conference, citationsPublications = \
            SampleGraphUtility.constructSkewedCitationPublicationExample(
                introduceRandomness=False, citationsPublicationsParameter=citationsPublications
            )

        # Get the nodes we care about
        authors = [
            authorMap['Alice'], authorMap['Bob'], authorMap['Carol'],
            authorMap['Dave'], authorMap['Ed']
        ]

        # Total citation & publication counts
        self.output('\nCitation & Publication Counts')
        adjMatrixTable = texttable.Texttable()
        rows = [['Measure'] + [author.name for author in authors]]
        rows += [['Citations'] +
                 [citationsPublications[author][0] for author in authors]]
        rows += [['Publications'] +
                 [citationsPublications[author][1] for author in authors]]
        adjMatrixTable.add_rows(rows)
        self.output(adjMatrixTable.draw())

        # Output PathSim similarity scores
        pathSimStrategyPubs = NeighborSimStrategy(self.graph,
                                                  [Conference, Paper, Author],
                                                  symmetric=True)
        self.outputSimilarityScores(authorMap, authors, pathSimStrategyPubs,
                                    'APCPA PathSim')
        pathSimStrategyCits = NeighborSimStrategy(
            self.graph, [Conference, Paper, Paper, Author])
        self.outputSimilarityScores(authorMap, authors, pathSimStrategyCits,
                                    'APPCPPA PathSim')
        for w1, w2 in [(0.5, 0.5), (0.6, 0.4), (0.4, 0.6), (0.7, 0.3),
                       (0.3, 0.7)]:
            combinedPathSimStrategy = AggregateSimilarityStrategy(
                self.graph, [pathSimStrategyPubs, pathSimStrategyCits],
                [w1, w2])
            self.outputSimilarityScores(
                authorMap, authors, combinedPathSimStrategy,
                'APCPA-APPCPPAA Pathsim (%1.1f,%1.1f)' % (w1, w2))

        # Output ShapeSim strategy
        w = 1.0
        neighborPathShapeStrategy = VectorProductStrategy(
            self.graph,
            weight=w,
            omit=[],
            metaPath=[Conference, Paper, Paper, Author],
            symmetric=True)
        strategyTitle = 'APPCPPA %s ShapeSim (%1.2f weight)' % (
            'VectorProduct', w)
        self.outputSimilarityScores(authorMap, authors,
                                    neighborPathShapeStrategy, strategyTitle)
    def run(self):

        self.graph, authorMap, conference, citationsPublications = \
            SampleGraphUtility.constructSkewedCitationPublicationExample(introduceRandomness=False)

        # Get the nodes we care about
        authors = [
            authorMap['Alice'],
            authorMap['Bob'],
            authorMap['Carol'],
            authorMap['Dave'],
            authorMap['Ed'],
            authorMap['Frank']
        ]
        metaPathUtility = EdgeBasedMetaPathUtility()

        # Output adjacency matrices
        self.output('\nCPA Adjacency Matrix:')
        cpaadjMatrix, nodesIndex = metaPathUtility.getAdjacencyMatrixFromGraph(
            self.graph, [Conference, Paper, Author], project=True
        )
        adjMatrixTable = texttable.Texttable()
        rows = [['Conference'] + [author.name for author in authors]]
        rows += [[conference.name] + [cpaadjMatrix[nodesIndex[conference]][nodesIndex[author]] for author in authors]]
        adjMatrixTable.add_rows(rows)
        self.output(adjMatrixTable.draw())

        self.output('\nCPPA Adjacency Matrix:')
        cpaadjMatrix, nodesIndex = metaPathUtility.getAdjacencyMatrixFromGraph(
            self.graph, [Conference, Paper, Paper, Author], project=True
        )
        adjMatrixTable = texttable.Texttable()
        rows = [['Conference'] + [author.name for author in authors]]
        rows += [[conference.name] + [cpaadjMatrix[nodesIndex[conference]][nodesIndex[author]] for author in authors]]
        adjMatrixTable.add_rows(rows)
        self.output(adjMatrixTable.draw())

        # Total citation & publication counts
        self.output('\nCitation & Publication Counts')
        adjMatrixTable = texttable.Texttable()
        rows = [['Measure'] + [author.name for author in authors]]
        rows += [['Citations'] + [citationsPublications[author][0] for author in authors]]
        rows += [['Publications'] + [citationsPublications[author][1] for author in authors]]
        adjMatrixTable.add_rows(rows)
        self.output(adjMatrixTable.draw())

        # Output NeighborSim & PathSim similarity scores
        neighborSimStrategy = NeighborSimStrategy(self.graph, [Conference, Paper, Author], symmetric=True)
        self.outputSimilarityScores(authorMap, authors, neighborSimStrategy, 'APCPA PathSim')
        neighborSimStrategy = NeighborSimStrategy(self.graph, [Conference, Paper, Paper, Author])
        self.outputSimilarityScores(authorMap, authors, neighborSimStrategy, 'APPCPPA PathSim')

        # Omit extra duplicate entry in path, and weight at different levels of 'relative'
        for strategy, generalStrategyTitle in [(FlattenedMatrixStrategy, 'FlatMat'), (VectorProductStrategy, 'VectorProduct')]:
            for w in [1.0, 0.5, 0]:
                neighborPathShapeStrategy = strategy(
                    self.graph, weight=w, omit=[], metaPath=[Conference, Paper, Paper, Author], symmetric=True
                )
                strategyTitle = 'APPCPPA %s ShapeSim (%1.2f weight)' % (generalStrategyTitle, w)
                self.outputSimilarityScores(authorMap, authors, neighborPathShapeStrategy, strategyTitle)
        w = 1.0
        neighborPathShapeStrategy = VectorProductStrategy(
            self.graph, weight=w, omit=[0], metaPath=[Conference, Paper, Paper, Author], symmetric=True
        )
        strategyTitle = 'APPCPPA VectorProduct ShapeSim omitting CPC (%1.2f weight)' % w
        self.outputSimilarityScores(authorMap, authors, neighborPathShapeStrategy, strategyTitle)

        # Output recursive pathsim strategy score(s)
        recursivePathSimStrategy = RecursivePathSimStrategy(self.graph, [Conference, Paper, Paper, Author])
        self.outputSimilarityScores(authorMap, authors, recursivePathSimStrategy, 'APPCPPA Recursive PathSim')