Ejemplo n.º 1
0
    def __addScentNodesUpTo(self, conn, prevEndTimestamp, newEndTimestamp):
        # Inserts nodes into the graph up to a given timestamp in the database
        # provided by the conn.
        print '\tProcessing scent. Adding scent-related nodes...'
        
        c = conn.cursor()
        # if self.VERBOSE_BUILD:
        #     print "\tExecuting scent query from ", self.endTimestamp, "to", newEndTimestamp
        c.execute(self.SCENT_QUERY, [prevEndTimestamp, newEndTimestamp])
        
        for row in c:
            action, target, referrer = \
                row['action'], self.langHelper.fixSlashes(row['target']), \
                self.langHelper.fixSlashes(row['referrer'])
            
            # Note that these can return None if the relation is undefined
            targetNodeType = NodeType.getTargetNodeType(action, target)
            referrerNodeType = NodeType.getReferrerNodeType(action, referrer, self.langHelper)

            # Case 1: target and referrer contain either FQNs or file paths, so
            # create a  node for every target and referrer. Each of these nodes then
            # gets an edge to each of the words within the FQN or path, excluding
            # stop words. These words are not stemmed.
            if action in ('Package', 'Imports', 'Extends', 'Implements',
                          'Method declaration', 'Constructor invocation',
                          'Method invocation', 'Variable declaration',
                          'Variable type'):
                for word in self.__getWordNodes_splitNoStem(target):
                    self._addEdge(target, word, targetNodeType, NodeType.WORD, EdgeType.CONTAINS)
        
                for word in self.__getWordNodes_splitNoStem(referrer):
                    self._addEdge(referrer, word, referrerNodeType, NodeType.WORD, EdgeType.CONTAINS)
        
            # Case 2: These actions have code content within them. In this case we
            # want to add an edge from the FQN node in target to the code content in
            # referrer. The FQNs should already exist because of step 1. Words are
            # added in two ways. In the first pass, the complete word is added,
            # camelCase intact without stemming. In the second pass, the camel case
            # is split, the resulting words are stemmed and those are added to the
            # FQN node.
            elif action in ('Constructor invocation scent',
                            'Method declaration scent',
                            'Method invocation scent'):
                for word in self.__getWordNodes_splitNoStem(referrer):
                    self._addEdge(target, word, targetNodeType, NodeType.WORD, EdgeType.CONTAINS)
                    
                for word in self.getWordNodes_splitCamelAndStem(referrer):
                    self._addEdge(target, word, targetNodeType, NodeType.WORD, EdgeType.CONTAINS)
        c.close()
        
        print '\tDone adding scent-related nodes.'
        self.__printGraphStats()
Ejemplo n.º 2
0
    def __addTopologyNodesUpTo(self, conn, prevEndTimestamp, newEndTimestamp):
        # Build the graph according to the code structure recorded by PFIG. See
        # each section of the build for details.
    
        print "\tProcessing topology. Adding location nodes to the graph..."
    
        c = conn.cursor()
        c.execute(self.TOPOLOGY_QUERY, [prevEndTimestamp, newEndTimestamp])
    
        for row in c:
            action, target, referrer, = \
            row['action'], self.langHelper.fixSlashes(row['target']), \
            self.langHelper.fixSlashes(row['referrer'])
            targetNodeType = NodeType.getTargetNodeType(action, target)
            referrerNodeType = NodeType.getReferrerNodeType(action, referrer, self.langHelper)

            self.updateTopology(action, target, referrer, targetNodeType, referrerNodeType)

        c.close
    
        print "\tDone processing topology."
        self.__printGraphStats()