Esempio n. 1
0
    def load_from_tag(self, mn_tag, properties_to_include=None, properties_to_ignore=None, nodeclasses_to_include=None,
                      nodeclasses_to_ignore=None, networks_to_include=None, networks_to_ignore=None):
        """
        Parses the content of an lxml _Element containing a Meta-Network and loads the contents
        :param mn_tag: An lxml _Element containing a Dynamic Meta-Network
        :param properties_to_include: a list of nodeclass properties that should be included
        :param properties_to_ignore: a list of nodeclass properties that should be ignored
        :param nodeclasses_to_include: a list of nodeclasses that should be included
        :param nodeclasses_to_ignore: a list of nodeclasses that should be ignored
        :param networks_to_include: a list of networks that should be included
        :param networks_to_ignore: a list of networks that should be ignored
        :type mn_tag: An lxml _Element containing a DynamicMetaNetwork
        :type properties_to_include: list
        :type properties_to_ignore: list
        :type nodeclasses_to_include: list
        :type nodeclasses_to_ignore: list
        :type networks_to_include: list
        :type networks_to_ignore: list
        :raise TypeError: if dnn isn't a BeautifulSoup Tag
        """
        prop_inclusion_test = dmlpu.validate_and_get_inclusion_test(
            (properties_to_include, 'properties_to_include'),
            (properties_to_ignore, 'properties_to_ignore'))
        nodeclass_inclusion_test = dmlpu.validate_and_get_inclusion_test(
            (nodeclasses_to_include, 'nodeclasses_to_include'),
            (nodeclasses_to_ignore, 'nodeclasses_to_ignore'))
        network_inclusion_test = dmlpu.validate_and_get_inclusion_test(
            (networks_to_include, 'networks_to_include'),
            (networks_to_ignore, 'networks_to_ignore'))

        for attrib_key in mn_tag.attrib:
            self.attributes[attrib_key] = dmlpu.format_prop(mn_tag.attrib[attrib_key])

        properties_tag = mn_tag.find('properties')
        if properties_tag is not None:
            for prop in properties_tag.iterfind('property'):
                self.properties[prop.attrib['id']] = dmlpu.format_prop(prop.attrib['value'])

        ##TODO: deal with sources tag in Automap output

        self.propertyIdentities = \
            dmlpu.get_property_identities_dict(mn_tag.find('propertyIdentities'), prop_inclusion_test)

        self.__node_tree = dmlpu.get_nodeclass_dict(mn_tag.find('nodes'), prop_inclusion_test, nodeclass_inclusion_test)

        for nk_tag in mn_tag.find('networks').iterfind('network'):
            if not network_inclusion_test(nk_tag.attrib['id']):
                continue

            self._parse_and_add_graph_tag(nk_tag)
Esempio n. 2
0
    def load_from_tag(self, mn_tag, properties_to_include=None, properties_to_ignore=None, nodeclasses_to_include=None,
                      nodeclasses_to_ignore=None, networks_to_include=None, networks_to_ignore=None):
        """
        Parses the content of an :class:`lxml._Element` containing a meta-network and loads the contents

        :param lxml._Element mn_tag: A tag containing a dynamic meta-network
        :param list properties_to_include: a list of nodeclass properties that should be included
        :param list properties_to_ignore: a list of nodeclass properties that should be ignored
        :param list nodeclasses_to_include: a list of nodeclasses that should be included
        :param list nodeclasses_to_ignore: a list of nodeclasses that should be ignored
        :param list networks_to_include: a list of networks that should be included
        :param list networks_to_ignore: a list of networks that should be ignored
        """
        prop_inclusion_test = dmlpu.validate_and_get_inclusion_test(
            (properties_to_include, 'properties_to_include'),
            (properties_to_ignore, 'properties_to_ignore'))
        nodeclass_inclusion_test = dmlpu.validate_and_get_inclusion_test(
            (nodeclasses_to_include, 'nodeclasses_to_include'),
            (nodeclasses_to_ignore, 'nodeclasses_to_ignore'))
        network_inclusion_test = dmlpu.validate_and_get_inclusion_test(
            (networks_to_include, 'networks_to_include'),
            (networks_to_ignore, 'networks_to_ignore'))

        for attrib_key in mn_tag.attrib:
            self.attributes[attrib_key] = dmlpu.format_prop(mn_tag.attrib[attrib_key])

        properties_tag = mn_tag.find('properties')
        if properties_tag is not None:
            for prop in properties_tag.iterfind('property'):
                self.properties[prop.attrib['id']] = dmlpu.format_prop(prop.attrib['value'])

        # TODO: Deal with source tag in AutoMap output.

        self.propertyIdentities = \
            dmlpu.get_property_identities_dict(mn_tag.find('propertyIdentities'), prop_inclusion_test)

        self.__node_tree = dmlpu.get_nodeclass_dict(mn_tag.find('nodes'), prop_inclusion_test, nodeclass_inclusion_test)

        for nk_tag in mn_tag.find('networks').iterfind('network'):
            if not network_inclusion_test(nk_tag.attrib['id']):
                continue

            self._parse_and_add_graph_tag(nk_tag)