def checkDefinitionNodeRules(val, table, parent, arcrole, xpathContext):
    for rel in val.modelXbrl.relationshipSet(arcrole).fromModelObject(parent):
        axis = rel.toModelObject
        if axis is not None:
            if isinstance(axis, ModelFilterDefinitionNode):
                checkFilterAspectModel(val, table, axis.filterRelationships, xpathContext)
                #if not checkFilterAspectModel(val, table, axis.filterRelationships, xpathContext):
                    # this removed after 2013-01-06 PWD
                    #val.modelXbrl.error("xbrlte:axisFilterCoversNoAspects",
                    #    _("FilterAxis %(xlinkLabel)s does not cover any aspects."),
                    #    modelObject=axis, xlinkLabel=axis.xlinkLabel)
            else:
                if isinstance(axis, ModelRuleDefinitionNode):
                    # check dimension elements
                    for eltName, dim, badUsageErr in (("explicitDimension", "explicit", "xbrlfe:badUsageOfExplicitDimensionRule"),
                                                      ("typedDimension", "typed", "xbrlfe:badUsageOfTypedDimensionRule")):
                        for dimElt in XmlUtil.descendants(axis, XbrlConst.formula, eltName):
                            dimQname = qname(dimElt, dimElt.get("dimension"))
                            dimConcept = val.modelXbrl.qnameConcepts.get(dimQname)
                            if dimQname and (dimConcept is None or (not dimConcept.isExplicitDimension if dim == "explicit" else not dimConcept.isTypedDimension)):
                                val.modelXbrl.error(badUsageErr,
                                    _("RuleAxis %(xlinkLabel)s dimension attribute %(dimension)s on the %(dimensionType)s dimension rule contains a QName that does not identify an (dimensionType)s dimension."),
                                    modelObject=axis, xlinkLabel=axis.xlinkLabel, dimensionType=dim, dimension=dimQname,
                                    messageCodes=("xbrlfe:badUsageOfExplicitDimensionRule", "xbrlfe:badUsageOfTypedDimensionRule"))
                            memQname = axis.evaluateRule(None, dimQname)
                            if dimConcept.isExplicitDimension and memQname is not None and memQname not in val.modelXbrl.qnameConcepts:  
                                val.modelXbrl.info("table:info",
                                                   _("RuleAxis rule %(xlinkLabel)s contains a member QName %(memQname)s which is not in the DTS."),
                                                   modelObject=axis, xlinkLabel=axis.xlinkLabel, memQname=memQname)
                    
                    # check aspect model expectations
                    if table.aspectModel == "non-dimensional":
                        unexpectedElts = XmlUtil.descendants(axis, XbrlConst.formula, ("explicitDimension", "typedDimension"))
                        if unexpectedElts:
                            val.modelXbrl.error("xbrlte:axisAspectModelMismatch",
                                _("RuleAxis %(xlinkLabel)s aspect model, %(aspectModel)s, includes an rule for aspect not defined in this aspect model: %(undefinedAspects)s"),
                                modelObject=axis, xlinkLabel=axis.xlinkLabel, aspectModel=table.aspectModel, undefinedAspects=", ".join([elt.localName for elt in unexpectedElts]))
            
                    # check source qnames
                    for sourceElt in ([axis] + 
                                     XmlUtil.descendants(axis, XbrlConst.formula, "*", "source","*")):
                        if sourceElt.get("source") is not None:
                            qnSource = qname(sourceElt, sourceElt.get("source"), noPrefixIsNoNamespace=True)
                            val.modelXbrl.info("table:info",
                                               _("RuleAxis rule %(xlinkLabel)s contains a @source attribute %(qnSource)s which is not applicable to table rule axes."),
                                               modelObject=axis, xlinkLabel=axis.xlinkLabel, qnSource=qnSource)
                    conceptQname = axis.evaluateRule(None, Aspect.CONCEPT)
                    if conceptQname and conceptQname not in val.modelXbrl.qnameConcepts:  
                        val.modelXbrl.info("table:info",
                                           _("RuleAxis rule %(xlinkLabel)s contains a concept QName %(conceptQname)s which is not in the DTS."),
                                           modelObject=axis, xlinkLabel=axis.xlinkLabel, conceptQname=conceptQname)
                        
                elif isinstance(axis, ModelRelationshipDefinitionNode):
                    for qnameAttr in ("relationshipSourceQname", "arcQname", "linkQname", "dimensionQname"):
                        eltQname = axis.get(qnameAttr)
                        if eltQname and eltQname not in val.modelXbrl.qnameConcepts:  
                            val.modelXbrl.info("table:info",
                                               _("%(axis)s rule %(xlinkLabel)s contains a %(qnameAttr)s QName %(qname)s which is not in the DTS."),
                                               modelObject=axis, axis=axis.localName.title(), xlinkLabel=axis.xlinkLabel, 
                                               qnameAttr=qnameAttr, qname=eltQname)
                checkDefinitionNodeRules(val, table, axis, (XbrlConst.tableBreakdownTree, XbrlConst.tableBreakdownTreeMMDD, XbrlConst.tableBreakdownTree201305, XbrlConst.tableDefinitionNodeSubtree201301, XbrlConst.tableAxisSubtree2011), xpathContext)
dataset/ETHPy150Open Arelle/Arelle/arelle/ValidateFormula.py/checkDefinitionNodeRules/original