Example #1
0
 def toStringOfTypes(self):
     string = ""
     for i in range(0, len(self.edges)):
         string += utils.getNodeType(self.nodes[i], self.graph) + ", "
         string += utils.getEdgeType(self.edges[i], self.graph) + ", "
     string += utils.getNodeType(self.nodes[len(self.nodes) - 1], self.graph)
     return string
Example #2
0
    def getDistanceFromOtherPath(self, other):
        distance = 0
        for i in range(0, len(self.edges)):
            if not utils.getEdgeType(self.edges[i], self.graph) == utils.getEdgeType(other.edges[i], self.graph):
                distance += 1

        for i in range(0, len(self.nodes)):
            if not utils.getNodeType(self.nodes[i], self.graph) == utils.getNodeType(other.nodes[i], self.graph):
                distance += 1

        return distance
Example #3
0
    def toStringOfSuperTypesNoEdges(self):
        string = ""
        superTypeDictionary = tp.SuperTypeDictionary()

        for i in range(0, len(self.edges)):
            string += superTypeDictionary.getSuperTypeFromType(utils.getNodeType(self.nodes[i], self.graph)) + ", "
            # string += utils.getEdgeType(self.edges[i], self.graph) + ', '
        string += superTypeDictionary.getSuperTypeFromType(
            utils.getNodeType(self.nodes[len(self.nodes) - 1], self.graph)
        )
        return string
Example #4
0
    def isSameType(self, other):
        if (not len(self.nodes) == len(other.nodes)) or (not len(self.edges) == len(other.edges)):
            return False

        for i in range(0, len(self.edges)):
            if not utils.getEdgeType(self.edges[i], self.graph) == utils.getEdgeType(other.edges[i], self.graph):
                return False

        for i in range(0, len(self.nodes)):
            if not utils.getNodeType(self.nodes[i], self.graph) == utils.getNodeType(other.nodes[i], self.graph):
                return False

        return True
Example #5
0
    def getSuperDistanceFromOtherPath(self, other):
        distance = 0
        superTypeDictionary = tp.SuperTypeDictionary()
        # for i in range(0, len(self.edges)):
        #     if not utils.getEdgeType(self.edges[i], self.graph) == utils.getEdgeType(other.edges[i], self.graph):
        #         distance += 1

        for i in range(0, len(self.nodes)):
            if not superTypeDictionary.getSuperTypeFromType(
                utils.getNodeType(self.nodes[i], self.graph)
            ) == superTypeDictionary.getSuperTypeFromType(utils.getNodeType(other.nodes[i], self.graph)):
                distance += 1

        return distance
    def collapseTargets(self):
        """
            Updates _matrix s.t. all cols of the same label get collapsed to a single col.
        """

        if self._targetsCollapsed:
            return

        self._targetsCollapsed = True

        targetTypes = utils.getNodesTypes(self._nodes, self._graph)
        newMatrix = []

        # Initialize newMatrix
        for i in range(0, len(self._matrix)):
            newRow = []
            for j in range(0, len(targetTypes)):
                newRow.append([])
            newMatrix.append(newRow)

        # Populate new matrix
        for i in range(0, len(self._matrix)):
            row = self._matrix[i]
            for j in range(0, len(row)):
                col = row[j]
                if len(col) > 0:
                    colType = utils.getNodeType(self._nodes[j], self._graph)
                    colIndex = targetTypes.index(colType)
                    newMatrix[i][colIndex] += col

        self._matrix = copy.deepcopy(newMatrix)
        self._colLabels = targetTypes
    def collapseSources(self):
        """
            Updates _matrix s.t. all rows of the same label get collapsed to a single row.
        """
        if self._sourcesCollapsed:
            return

        sourceTypes = utils.getNodesTypes(self._nodes, self._graph)
        newMatrix = []
        newCols = []
        for node in self._nodes:
            newCols.append(utils.getNodeId(node, self._graph))

        for sourceType in sourceTypes:
            newRow = [[] for node in self._nodes]
            for i in range(0, len(self._matrix)):
                rowType = utils.getNodeType(self._nodes[i], self._graph)
                row = self._matrix[i]
                if rowType == sourceType:
                    for j in range(0, len(row)):
                        col = row[j]
                        if len(col) > 0:
                            newRow[j] += col
            newMatrix.append(newRow)

        self._matrix = copy.deepcopy(newMatrix)
        self._colLabels = newCols
        self._rowLabels = sourceTypes
Example #8
0
    def isSameSuperType(self, other):
        if (not len(self.nodes) == len(other.nodes)) or (not len(self.edges) == len(other.edges)):
            return False

        for i in range(0, len(self.edges)):
            if not utils.getEdgeType(self.edges[i], self.graph) == utils.getEdgeType(other.edges[i], self.graph):
                return False

        superTypeDictionary = tp.SuperTypeDictionary()

        for i in range(0, len(self.nodes)):
            if not superTypeDictionary.getSuperTypeFromType(
                utils.getNodeType(self.nodes[i], self.graph)
            ) == superTypeDictionary.getSuperTypeFromType(utils.getNodeType(other.nodes[i], self.graph)):
                return False

        return True
Example #9
0
 def isInNetworkPath(self):
     seenNodes = {}
     for node in self.nodes:
         nodeType = utils.getNodeType(node, self.graph)
         if nodeType in seenNodes:
             return True
         else:
             seenNodes[nodeType] = 1
     return False
Example #10
0
def getProductElements(listArgumentType,
                       normResult, listResult, dictResult, firstParam):
    index = 0

    if firstParam:
        normResultTypes = [{firstParam}]
    else:
        normResultTypes = []
    for elem in normResult:
        if isinstance(elem, set):
            normResultTypes.append(elem)
        elif elem:
            normResultTypes.append(utils.getNodeType(elem))
        else:
            normResultTypes.append(listArgumentType[index])
            index += 1

    listResultTypes = []
    # DON'T set index = 0
    for elem in listResult:
        if elem:
            listResultTypes.append(utils.getNodeType(elem))
        else:
            listResultTypes.append(listArgumentType[index])
            index += 1
  
    kwKeys = []
    dictResultTypes = []
    for pair in dictResult.items():
        kwKeys.append(pair[0])
        dictResultTypes.append(utils.getNodeType(pair[1]))

    for elem in itertools.product(itertools.product(*normResultTypes),
                                  itertools.product(*listResultTypes),
                                  itertools.product(*dictResultTypes)):
        yield elem, kwKeys
Example #11
0
    def isInRegexTypeConstraints(self, nodeConstraintsRegexes, edgeConstraintsRegexes):

        for i in range(0, len(self.edges)):
            edge = self.edges[i]
            edgeType = utils.getEdgeType(edge, self.graph)
            if not utils.isRegexExactMatch(edgeConstraintsRegexes[i], edgeType):
                return False

        for i in range(0, len(self.nodes)):
            node = self.nodes[i]
            nodeType = utils.getNodeType(node, self.graph)
            if not utils.isRegexExactMatch(nodeConstraintsRegexes[i], nodeType):
                return False

        return True
Example #12
0
    def isInTypeConstraints(self, edgeConstraints, nodeConstraints):

        for i in range(0, len(self.edges)):
            edge = self.edges[i]
            edgeType = utils.getEdgeType(edge, self.graph)
            if edgeConstraints[i] != edgeType:
                return False

        for i in range(0, len(self.nodes)):
            node = self.nodes[i]
            nodeType = utils.getNodeType(node, self.graph)
            if nodeConstraints[i] != nodeType:
                return False

        return True