コード例 #1
0
    def readRule(self):

        tree = ET.parse(self._path + self._filename)
        root = tree.getroot()

        #Get our rewrite rule name
        ruleName = root.attrib.get('name')
        applyonce = (root.attrib.get('applyonce') == "true")

        socialConditionFilename = root.find('socialcondition').text + ".xml"
        socialConditionLoader = XMLSocialGraphReader(self._path +
                                                     socialConditionFilename)
        socialCondition = socialConditionLoader.readGraph()

        storyConditionFilename = root.find('storycondition').text + ".xml"
        storyConditionLoader = XMLStoryGraphReader(socialCondition, self._path,
                                                   storyConditionFilename)
        storyCondition = storyConditionLoader.readGraph()

        storyModificationFilename = root.find(
            'storymodification').text + ".xml"
        storyModificationLoader = XMLStoryGraphReader(
            socialCondition, self._path, storyModificationFilename)
        storyModification = storyModificationLoader.readGraph()

        return RewriteRule(storyCondition, socialCondition, storyModification,
                           None, ruleName, applyonce)
コード例 #2
0
    def readTestLayout(self):

        layout = TestLayout()

        tree = ET.parse(self._filename)
        root = tree.getroot()

        layout.set_name(root.attrib.get('name'))
        layout.set_save_output(root.attrib['save_output'] == 'True')

        socialgraph = root.find('socialgraph').text
        filename = self._path_to_data + "SocialGraphs/" + socialgraph + '.xml'
        reader = XMLSocialGraphReader(filename)
        layout.set_social_graph(reader.readGraph())

        initializationrules = root.find('initializationrules')

        for rule in initializationrules.iter('initializationrule'):
            name = rule.text
            filename = self._path_to_data + "Rules/InitializationRules/" + name + "/"
            reader = XMLInitializationRuleReader(filename, name + ".xml")
            layout.add_initialization_rule(reader.readInitRule())

        rewriterules = root.find('rewriterules')

        for rule in rewriterules.iter('rewriterule'):
            name = rule.text
            filename = self._path_to_data + "Rules/RewriteRules/" + name + "/"
            reader = XMLRewriteRuleReader(filename, name + ".xml")
            layout.add_rewrite_rule(reader.readRule())

        analyze_metrics = root.find('metricstoanalyze')

        for metric in analyze_metrics.iter('metric'):
            layout.add_metric_to_analyze(metric.attrib.get('name'))

        optimize_metrics = root.find('metricstooptimize')

        for metric in optimize_metrics.iter('metric'):
            layout.add_metric_to_optimize(
                [metric.attrib.get('name'),
                 int(metric.attrib.get('weight'))])

        layout.set_number_of_stories_to_generate(
            int(root.find('numstoriestogenerate').text))
        layout.set_max_number_of_rewrites(
            int(root.find('maxnumberofrewrites').text))

        return layout