Exemplo n.º 1
0
def ineffectiveArcs(baseSetModelLinks, arcrole, arcqname=None):
    relationships = defaultdict(list)
    for modelLink in baseSetModelLinks:
        for linkChild in modelLink:
            if (isinstance(linkChild, ModelObject)
                    and linkChild.get("{http://www.w3.org/1999/xlink}type")
                    == "arc" and arcrole
                    == linkChild.get("{http://www.w3.org/1999/xlink}arcrole")
                    and (arcqname is None or arcqname == linkChild)):
                fromLabel = linkChild.get("{http://www.w3.org/1999/xlink}from")
                toLabel = linkChild.get("{http://www.w3.org/1999/xlink}to")
                for fromResource in modelLink.labeledResources[fromLabel]:
                    for toResource in modelLink.labeledResources[toLabel]:
                        modelRel = ModelDtsObject.ModelRelationship(
                            modelLink.modelDocument, linkChild,
                            fromResource.dereference(),
                            toResource.dereference())
                        relationships[modelRel.equivalenceKey].append(modelRel)
    # determine ineffective relationships
    ineffectives = []
    for equivalenceKey, relationship in relationships.items():
        #sort by priority, prohibited
        equivalentRels = [(modelRel.priority, modelRel.prohibitedUseSortKey, i)
                          for i, modelRel in enumerate(relationship)]
        priorRel = None
        for rel in sorted(equivalentRels):
            if rel[1] == 2:  # this rel is prohibited
                if priorRel is None:
                    ineffective = relationship[rel[2]]
                    ineffective.ineffectivity = _(
                        "prohibited arc (priority {0}) has no other arc to prohibit"
                    ).format(ineffective.priority)
                    ineffectives.append(ineffective)  # this rel ineffective
                elif priorRel[1] == 2:  # prior rel is prohibited
                    ineffective = relationship[priorRel[2]]
                    effective = relationship[rel[2]]
                    ineffective.ineffectivity = _(
                        "prohibited arc (priority {0}, {1} - {2}) has an equivalent prohibited arc (priority {3}, {4} - {5})\n"
                    ).format(ineffective.priority,
                             ineffective.modelDocument.basename,
                             ineffective.sourceline, effective.priority,
                             effective.modelDocument.basename,
                             effective.sourceline)
                    ineffectives.append(ineffective)
            else:
                if priorRel is not None and priorRel[1] != 2:
                    ineffective = relationship[priorRel[2]]
                    effective = relationship[rel[2]]
                    ineffective.ineffectivity = _(
                        "arc (priority {0}, {1} - {2}) is ineffective due to equivalent arc (priority {3}, {4} - {5})\n"
                    ).format(ineffective.priority,
                             ineffective.modelDocument.basename,
                             ineffective.sourceline, effective.priority,
                             effective.modelDocument.basename,
                             effective.sourceline)
                    ineffectives.append(ineffective)  # prior ineffective
            priorRel = rel
    return ineffectives
Exemplo n.º 2
0
def ineffectiveArcs(baseSetModelLinks, arcrole, arcqname=None):
    hashEquivalentRels = defaultdict(list)
    for modelLink in baseSetModelLinks:
        for linkChild in modelLink:
            if (isinstance(linkChild, (ModelObject, PrototypeObject))
                    and linkChild.get("{http://www.w3.org/1999/xlink}type")
                    == "arc" and arcrole
                    == linkChild.get("{http://www.w3.org/1999/xlink}arcrole")
                    and (arcqname is None or arcqname == linkChild)):
                fromLabel = linkChild.get("{http://www.w3.org/1999/xlink}from")
                toLabel = linkChild.get("{http://www.w3.org/1999/xlink}to")
                for fromResource in modelLink.labeledResources[fromLabel]:
                    for toResource in modelLink.labeledResources[toLabel]:
                        modelRel = ModelDtsObject.ModelRelationship(
                            modelLink.modelDocument, linkChild,
                            fromResource.dereference(),
                            toResource.dereference())
                        hashEquivalentRels[modelRel.equivalenceHash].append(
                            modelRel)
    # determine ineffective relationships
    ineffectives = []
    keyEquivalentRels = defaultdict(list)
    for hashEquivRelList in hashEquivalentRels.values():
        # separate into relationships that are key-equivalent
        if len(hashEquivRelList) == 1:
            if hashEquivRelList[0].prohibitedUseSortKey == 2:
                ineffective = hashEquivRelList[0]
                ineffective.ineffectivity = _(
                    "prohibited arc (priority {0}) has no other arc to prohibit"
                ).format(ineffective.priority)
                ineffectives.append(ineffective)  # this rel ineffective
        else:
            # index by equivalenceKey instead
            for modelRel in hashEquivRelList:
                keyEquivalentRels[modelRel.equivalenceKey].append(modelRel)
            for keyEquivRelList in keyEquivalentRels.values():
                #sort by priority, prohibited
                equivalentRels = [
                    (modelRel.priority, modelRel.prohibitedUseSortKey, i)
                    for i, modelRel in enumerate(keyEquivRelList)
                ]
                priorRel = None
                for rel in sorted(equivalentRels):
                    if rel[1] == 2:  # this rel is prohibited
                        if priorRel is None:
                            ineffective = keyEquivRelList[rel[2]]
                            ineffective.ineffectivity = _(
                                "prohibited arc (priority {0}) has no other arc to prohibit"
                            ).format(ineffective.priority)
                            ineffectives.append(
                                ineffective)  # this rel ineffective
                        elif priorRel[1] == 2:  # prior rel is prohibited
                            ineffective = keyEquivRelList[priorRel[2]]
                            effective = keyEquivRelList[rel[2]]
                            ineffective.ineffectivity = _(
                                "prohibited arc (priority {0}, {1} - {2}) has an equivalent prohibited arc (priority {3}, {4} - {5})\n"
                            ).format(ineffective.priority,
                                     ineffective.modelDocument.basename,
                                     ineffective.sourceline,
                                     effective.priority,
                                     effective.modelDocument.basename,
                                     effective.sourceline)
                            ineffectives.append(ineffective)
                    else:
                        if priorRel is not None and priorRel[1] != 2:
                            ineffective = keyEquivRelList[priorRel[2]]
                            effective = keyEquivRelList[rel[2]]
                            ineffective.ineffectivity = _(
                                "arc (priority {0}, {1} - {2}) is ineffective due to equivalent arc (priority {3}, {4} - {5})\n"
                            ).format(ineffective.priority,
                                     ineffective.modelDocument.basename,
                                     ineffective.sourceline,
                                     effective.priority,
                                     effective.modelDocument.basename,
                                     effective.sourceline)
                            ineffectives.append(
                                ineffective)  # prior ineffective
                    priorRel = rel
            keyEquivalentRels.clear()
    return ineffectives
Exemplo n.º 3
0
    def __init__(self,
                 modelXbrl,
                 arcrole,
                 linkrole=None,
                 linkqname=None,
                 arcqname=None,
                 includeProhibits=False):
        self.isChanged = False
        self.modelXbrl = modelXbrl
        self.arcrole = arcrole  # may be str, tuple or frozenset
        self.linkrole = linkrole  # may be str, tuple or frozenset
        self.linkqname = linkqname
        self.arcqname = arcqname

        relationshipSetKey = (arcrole, linkrole, linkqname, arcqname,
                              includeProhibits)

        # base sets does not care about the #includeProhibits
        if isinstance(arcrole,
                      (str, NoneType)) and isinstance(linkrole,
                                                      (str, NoneType)):
            modelLinks = self.modelXbrl.baseSets.get(
                (arcrole, linkrole, linkqname, arcqname), [])
        else:  # arcrole is a set of arcroles
            modelLinks = []
            for ar in (arcrole, ) if isinstance(arcrole,
                                                (str, NoneType)) else arcrole:
                for lr in (linkrole, ) if isinstance(linkrole,
                                                     (str,
                                                      NoneType)) else linkrole:
                    modelLinks.extend(
                        self.modelXbrl.baseSets.get(
                            (ar, lr, linkqname, arcqname), []))

        # gather arcs
        relationships = {}
        isDimensionRel = self.arcrole == "XBRL-dimensions"  # all dimensional relationship arcroles
        isFormulaRel = self.arcrole == "XBRL-formulae"  # all formula relationship arcroles
        isTableRenderingRel = self.arcrole == "Table-rendering"
        isFootnoteRel = self.arcrole == "XBRL-footnotes"  # all footnote relationship arcroles
        if not isinstance(arcrole, (tuple, frozenset)):
            arcrole = (arcrole, )

        for modelLink in modelLinks:
            arcs = []
            linkEltQname = modelLink.qname
            for linkChild in modelLink:
                linkChildArcrole = linkChild.get(
                    "{http://www.w3.org/1999/xlink}arcrole")
                if linkChild.get("{http://www.w3.org/1999/xlink}type"
                                 ) == "arc" and linkChildArcrole:
                    if isFootnoteRel:  # arcrole is fact-footnote or other custom footnote relationship
                        arcs.append(linkChild)
                    elif isDimensionRel:
                        if XbrlConst.isDimensionArcrole(linkChildArcrole):
                            arcs.append(linkChild)
                    elif isFormulaRel:
                        if XbrlConst.isFormulaArcrole(linkChildArcrole):
                            arcs.append(linkChild)
                    elif isTableRenderingRel:
                        if XbrlConst.isTableRenderingArcrole(linkChildArcrole):
                            arcs.append(linkChild)
                    elif (linkChildArcrole in arcrole
                          and (arcqname is None or arcqname == linkChild.qname)
                          and
                          (linkqname is None or linkqname == linkEltQname)):
                        arcs.append(linkChild)

            # build network
            for arcElement in arcs:
                fromLabel = arcElement.get(
                    "{http://www.w3.org/1999/xlink}from")
                toLabel = arcElement.get("{http://www.w3.org/1999/xlink}to")
                for fromResource in modelLink.labeledResources[fromLabel]:
                    for toResource in modelLink.labeledResources[toLabel]:
                        if isinstance(
                                fromResource,
                            (ModelResource, LocPrototype)) and isinstance(
                                toResource, (ModelResource, LocPrototype)):
                            modelRel = ModelDtsObject.ModelRelationship(
                                modelLink.modelDocument, arcElement,
                                fromResource.dereference(),
                                toResource.dereference())
                            modelRelEquivalenceHash = modelRel.equivalenceHash
                            if modelRelEquivalenceHash not in relationships:
                                relationships[
                                    modelRelEquivalenceHash] = modelRel
                            else:  # use equivalenceKey instead of hash
                                otherRel = relationships[
                                    modelRelEquivalenceHash]
                                if otherRel is not USING_EQUIVALENCE_KEY:  # move equivalentRel to use key instead of hasn
                                    if modelRel.isIdenticalTo(otherRel):
                                        continue  # skip identical arc
                                    relationships[
                                        otherRel.equivalenceKey] = otherRel
                                    relationships[
                                        modelRelEquivalenceHash] = USING_EQUIVALENCE_KEY
                                modelRelEquivalenceKey = modelRel.equivalenceKey  # this is a complex tuple to compute, get once for below
                                if modelRelEquivalenceKey not in relationships or \
                                   modelRel.priorityOver(relationships[modelRelEquivalenceKey]):
                                    relationships[
                                        modelRelEquivalenceKey] = modelRel

        #reduce effective arcs and order relationships...
        self.modelRelationshipsFrom = None
        self.modelRelationshipsTo = None
        self.modelConceptRoots = None
        self.modellinkRoleUris = None
        orderRels = defaultdict(list)
        for modelRel in relationships.values():
            if (modelRel is not USING_EQUIVALENCE_KEY
                    and (includeProhibits or not modelRel.isProhibited)):
                orderRels[modelRel.order].append(modelRel)
        self.modelRelationships = [
            modelRel for order in sorted(orderRels.keys())
            for modelRel in orderRels[order]
        ]
        modelXbrl.relationshipSets[relationshipSetKey] = self
Exemplo n.º 4
0
    def __init__(self,
                 modelXbrl,
                 arcrole,
                 linkrole=None,
                 linkqname=None,
                 arcqname=None,
                 includeProhibits=False):
        self.isChanged = False
        self.modelXbrl = modelXbrl
        self.arcrole = arcrole
        self.linkrole = linkrole
        self.linkqname = linkqname
        self.arcqname = arcqname

        baseSetKey = (arcrole, linkrole, linkqname, arcqname)
        relationshipSetKey = (arcrole, linkrole, linkqname, arcqname,
                              includeProhibits)

        # base sets does not care about the #includeProhibits
        if baseSetKey in self.modelXbrl.baseSets:
            modelLinks = self.modelXbrl.baseSets[baseSetKey]
        else:
            modelLinks = []

        # gather arcs
        relationships = {}
        isDimensionRel = self.arcrole == "XBRL-dimensions"  # all dimensional relationship arcroles
        isFormulaRel = self.arcrole == "XBRL-formulae"  # all formula relationship arcroles
        isTableRenderingRel = self.arcrole == "Table-rendering"
        isFootnoteRel = self.arcrole == "XBRL-footnotes"  # all footnote relationship arcroles

        for modelLink in modelLinks:
            arcs = []
            linkEltQname = modelLink.qname
            for linkChild in modelLink:
                linkChildArcrole = linkChild.get(
                    "{http://www.w3.org/1999/xlink}arcrole")
                if linkChild.get("{http://www.w3.org/1999/xlink}type"
                                 ) == "arc" and linkChildArcrole:
                    linkChildQname = linkChild
                    if isFootnoteRel:
                        arcs.append(linkChild)
                    elif isDimensionRel:
                        if XbrlConst.isDimensionArcrole(linkChildArcrole):
                            arcs.append(linkChild)
                    elif isFormulaRel:
                        if XbrlConst.isFormulaArcrole(linkChildArcrole):
                            arcs.append(linkChild)
                    elif isTableRenderingRel:
                        if XbrlConst.isTableRenderingArcrole(linkChildArcrole):
                            arcs.append(linkChild)
                    elif arcrole == linkChildArcrole and \
                         (arcqname is None or arcqname == linkChildQname) and \
                         (linkqname is None or linkqname == linkEltQname):
                        arcs.append(linkChild)

            # build network
            for arcElement in arcs:
                arcrole = arcElement.get(
                    "{http://www.w3.org/1999/xlink}arcrole")
                fromLabel = arcElement.get(
                    "{http://www.w3.org/1999/xlink}from")
                toLabel = arcElement.get("{http://www.w3.org/1999/xlink}to")
                for fromResource in modelLink.labeledResources[fromLabel]:
                    for toResource in modelLink.labeledResources[toLabel]:
                        if isinstance(fromResource,
                                      ModelResource) and isinstance(
                                          toResource, ModelResource):
                            modelRel = ModelDtsObject.ModelRelationship(
                                modelLink.modelDocument, arcElement,
                                fromResource.dereference(),
                                toResource.dereference())
                            modelRelEquivalenceKey = modelRel.equivalenceKey  # this is a complex tuple to compute, get once for below
                            if modelRelEquivalenceKey not in relationships or \
                               modelRel.priorityOver(relationships[modelRelEquivalenceKey]):
                                relationships[
                                    modelRelEquivalenceKey] = modelRel

        #reduce effective arcs and order relationships...
        self.modelRelationshipsFrom = None
        self.modelRelationshipsTo = None
        self.modelConceptRoots = None
        self.modellinkRoleUris = None
        orderRels = defaultdict(list)
        for modelRel in relationships.values():
            if includeProhibits or not modelRel.isProhibited:
                orderRels[modelRel.order].append(modelRel)
        self.modelRelationships = [
            modelRel for order in sorted(orderRels.keys())
            for modelRel in orderRels[order]
        ]
        modelXbrl.relationshipSets[relationshipSetKey] = self