当前位置: 首页>>代码示例>>Python>>正文


Python DomainContextHandler.bind方法代码示例

本文整理汇总了Python中Orange.widgets.settings.DomainContextHandler.bind方法的典型用法代码示例。如果您正苦于以下问题:Python DomainContextHandler.bind方法的具体用法?Python DomainContextHandler.bind怎么用?Python DomainContextHandler.bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Orange.widgets.settings.DomainContextHandler的用法示例。


在下文中一共展示了DomainContextHandler.bind方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DomainContextSettingsHandlerTests

# 需要导入模块: from Orange.widgets.settings import DomainContextHandler [as 别名]
# 或者: from Orange.widgets.settings.DomainContextHandler import bind [as 别名]
class DomainContextSettingsHandlerTests(unittest.TestCase):
    def setUp(self):
        self.handler = DomainContextHandler(attributes_in_res=True,
                                            metas_in_res=True)
        self.handler.read_defaults = lambda: None  # Disable reading settings from disk
        self.handler.bind(MockWidget)
        self.widget = MockWidget()
        encoded_attributes, encoded_metas = self.handler.encode_domain(domain)
        self.widget.current_context.attributes = encoded_attributes
        self.widget.current_context.metas = encoded_metas
        self.handler.initialize(self.widget)
        self.handler.initialize(self.widget.subprovider)
        self.handler.open_context(self.widget, domain)

    def test_settings_from_widget(self):
        widget = self.widget
        widget.ordinary_setting = VALUE
        widget.string_setting = VALUE
        widget.list_setting = [1, 2, 3]
        widget.dict_setting = {1: 2}
        widget.continuous_setting = CONTINOUS_ATTR
        widget.discrete_setting = DISCRETE_ATTR_ABC
        widget.class_setting = DISCRETE_CLASS_GHI
        widget.excluded_meta_setting = DISCRETE_META_JKL
        widget.meta_setting = DISCRETE_META_JKL

        self.handler.settings_from_widget(widget)

        values = widget.current_context.values
        self.assertEqual((VALUE, UNKNOWN_TYPE), values['ordinary_setting'])
        self.assertEqual((VALUE, UNKNOWN_TYPE), values['string_setting'])
        self.assertEqual([1, 2, 3], values['list_setting'])
        self.assertEqual(({1: 2}, UNKNOWN_TYPE), values['dict_setting'])
        self.assertEqual((CONTINOUS_ATTR, Continuous), values['continuous_setting'])
        self.assertEqual((DISCRETE_ATTR_ABC, Discrete), values['discrete_setting'])
        self.assertEqual((DISCRETE_CLASS_GHI, Discrete), values['class_setting'])
        self.assertEqual((DISCRETE_META_JKL, UNKNOWN_TYPE), values['excluded_meta_setting'])
        self.assertEqual((DISCRETE_META_JKL, Discrete), values['meta_setting'])

    def test_settings_to_widget(self):
        self.widget.current_context.values = dict(
            string_setting=(VALUE, -2),
            continuous_setting=(CONTINOUS_ATTR, Continuous),
            discrete_setting=(DISCRETE_ATTR_ABC, Discrete),
            list_setting=[1, 2, 3],
            attr_list_setting=[DISCRETE_ATTR_ABC, DISCRETE_CLASS_GHI],
            selection1=[0],
            attr_tuple_list_setting=[(DISCRETE_META_JKL, Discrete),
                                     (CONTINUOUS_META, Continuous)],
            selection2=[1],
        )

        self.handler.settings_to_widget(self.widget)

        self.assertEqual(self.widget.string_setting, VALUE)
        self.assertEqual(self.widget.continuous_setting, CONTINOUS_ATTR)
        self.assertEqual(self.widget.discrete_setting, DISCRETE_ATTR_ABC)
        self.assertEqual(self.widget.list_setting, [1, 2, 3])
        self.assertEqual(self.widget.attr_list_setting, [DISCRETE_ATTR_ABC, DISCRETE_CLASS_GHI])
        self.assertEqual(self.widget.attr_tuple_list_setting,
                         [DISCRETE_META_JKL, CONTINUOUS_META])
        self.assertEqual(self.widget.selection1, [0])
        self.assertEqual(self.widget.selection2, [1])

    def test_settings_to_widget_filters_selections(self):
        self.widget.current_context.values = dict(
            attr_list_setting=[DISCRETE_META_JKL, DISCRETE_ATTR_ABC,
                               CONTINUOUS_META, DISCRETE_CLASS_GHI],
            selection1=[1, 2],
        )

        self.handler.settings_to_widget(self.widget)

        self.assertEqual(self.widget.attr_list_setting, [DISCRETE_ATTR_ABC, DISCRETE_CLASS_GHI])
        self.assertEqual(self.widget.selection1, [0])

    def test_perfect_match_returns_2(self):
        attrs, metas = self.handler.encode_domain(domain)
        mock_context = Mock(attributes=attrs, metas=metas, values={})

        self.assertEqual(self.match(mock_context), 2.)

    def test_match_when_nothing_to_match_returns_point_1(self):
        attrs, metas = self.handler.encode_domain(domain)
        mock_context = Mock(values={})

        self.assertEqual(self.match(mock_context), 0.1)

    def test_match_if_all_values_match_returns_1(self):
        mock_context = Mock(values=dict(
            discrete_setting=(DISCRETE_ATTR_ABC, Discrete),
            required_setting=(DISCRETE_ATTR_ABC, Discrete),
        ))

        self.assertEqual(self.match(mock_context), 1.)

    def test_match_if_all_list_values_match_returns_1(self):
        mock_context = Mock(values=dict(
            discrete_setting=("df1", Discrete)
        ))
#.........这里部分代码省略.........
开发者ID:jujuefengliu,项目名称:orange3,代码行数:103,代码来源:test_settings.py

示例2: TestDomainContextHandler

# 需要导入模块: from Orange.widgets.settings import DomainContextHandler [as 别名]
# 或者: from Orange.widgets.settings.DomainContextHandler import bind [as 别名]
class TestDomainContextHandler(TestCase):
    def setUp(self):
        self.domain = Domain(
            attributes=[ContinuousVariable('c1'),
                        DiscreteVariable('d1', values='abc'),
                        DiscreteVariable('d2', values='def')],
            class_vars=[DiscreteVariable('d3', values='ghi')],
            metas=[ContinuousVariable('c2'),
                   DiscreteVariable('d4', values='jkl')]
        )
        self.args = (self.domain,
                     {'c1': Continuous - 100, 'd1': Discrete - 100,
                      'd2': Discrete - 100, 'd3': Discrete - 100},
                     {'c2': Continuous - 100, 'd4': Discrete - 100, })
        self.handler = DomainContextHandler()
        self.handler.read_defaults = lambda: None

    def test_encode_domain_with_match_none(self):
        handler = DomainContextHandler(
            match_values=DomainContextHandler.MATCH_VALUES_NONE)

        encoded_attributes, encoded_metas = handler.encode_domain(self.domain)

        self.assertEqual(encoded_attributes,
                         {'c1': Continuous - 100, 'd1': Discrete - 100,
                          'd2': Discrete - 100, 'd3': Discrete - 100})
        self.assertEqual(encoded_metas,
                         {'c2': Continuous - 100, 'd4': Discrete - 100, })

    def test_encode_domain_with_match_class(self):
        handler = DomainContextHandler(
            match_values=DomainContextHandler.MATCH_VALUES_CLASS)

        encoded_attributes, encoded_metas = handler.encode_domain(self.domain)

        self.assertEqual(encoded_attributes,
                         {'c1': Continuous - 100, 'd1': Discrete - 100,
                          'd2': Discrete - 100,
                          'd3': list('ghi')})
        self.assertEqual(encoded_metas,
                         {'c2': Continuous - 100, 'd4': Discrete - 100})

    def test_encode_domain_with_match_all(self):
        handler = DomainContextHandler(
            match_values=DomainContextHandler.MATCH_VALUES_ALL)

        encoded_attributes, encoded_metas = handler.encode_domain(self.domain)

        self.assertEqual(encoded_attributes,
                         {'c1': Continuous - 100, 'd1': list('abc'),
                          'd2': list('def'), 'd3': list('ghi')})
        self.assertEqual(encoded_metas,
                         {'c2': Continuous - 100, 'd4': list('jkl')})

    def test_match_returns_2_on_perfect_match(self):
        context = Mock(
            attributes=self.args[1], metas=self.args[2], values={})
        self.assertEqual(2., self.handler.match(context, *self.args))

    def test_match_returns_1_if_everything_matches(self):
        self.handler.bind(SimpleWidget)

        # Attributes in values
        context = Mock(values=dict(
            with_metas=('d1', Discrete),
            required=('d1', Discrete)))
        self.assertEqual(1., self.handler.match(context, *self.args))

        # Metas in values
        context = Mock(values=dict(
            with_metas=('d4', Discrete),
            required=('d1', Discrete)))
        self.assertEqual(1., self.handler.match(context, *self.args))

        # Attributes in lists
        context = Mock(values=dict(
            with_metas=[("d1", Discrete)]
        ))
        self.assertEqual(1., self.handler.match(context, *self.args))

        # Metas in lists
        context = Mock(values=dict(
            with_metas=[("d4", Discrete)]
        ))
        self.assertEqual(1., self.handler.match(context, *self.args))

    def test_match_returns_point_1_when_nothing_to_match(self):
        self.handler.bind(SimpleWidget)

        context = Mock(values={})
        self.assertEqual(0.1, self.handler.match(context, *self.args))

    def test_match_returns_zero_on_incompatible_context(self):
        self.handler.bind(SimpleWidget)

        # required
        context = Mock(values=dict(required=('u', Discrete),
                                   with_metas=('d1', Discrete)))
        self.assertEqual(0, self.handler.match(context, *self.args))

#.........这里部分代码省略.........
开发者ID:PrimozGodec,项目名称:orange3,代码行数:103,代码来源:test_domain_context_handler.py

示例3: TestDomainContextHandler

# 需要导入模块: from Orange.widgets.settings import DomainContextHandler [as 别名]
# 或者: from Orange.widgets.settings.DomainContextHandler import bind [as 别名]
class TestDomainContextHandler(TestCase):
    def setUp(self):
        self.domain = Domain(
            attributes=[ContinuousVariable('c1'),
                        DiscreteVariable('d1', values='abc'),
                        DiscreteVariable('d2', values='def')],
            class_vars=[DiscreteVariable('d3', values='ghi')],
            metas=[ContinuousVariable('c2'),
                   DiscreteVariable('d4', values='jkl')]
        )
        self.args = (self.domain,
                     {'c1': Continuous, 'd1': Discrete,
                      'd2': Discrete, 'd3': Discrete},
                     {'c2': Continuous, 'd4': Discrete, })
        self.handler = DomainContextHandler(metas_in_res=True)
        self.handler.read_defaults = lambda: None

    def test_encode_domain_with_match_none(self):
        handler = DomainContextHandler(
            match_values=DomainContextHandler.MATCH_VALUES_NONE,
            metas_in_res=True)

        encoded_attributes, encoded_metas = handler.encode_domain(self.domain)

        self.assertEqual(encoded_attributes,
                         {'c1': Continuous, 'd1': Discrete,
                          'd2': Discrete, 'd3': Discrete})
        self.assertEqual(encoded_metas, {'c2': Continuous, 'd4': Discrete, })

    def test_encode_domain_with_match_class(self):
        handler = DomainContextHandler(
            match_values=DomainContextHandler.MATCH_VALUES_CLASS,
            metas_in_res=True)

        encoded_attributes, encoded_metas = handler.encode_domain(self.domain)

        self.assertEqual(encoded_attributes,
                         {'c1': Continuous, 'd1': Discrete, 'd2': Discrete,
                          'd3': list('ghi')})
        self.assertEqual(encoded_metas, {'c2': Continuous, 'd4': Discrete})

    def test_encode_domain_with_match_all(self):
        handler = DomainContextHandler(
            match_values=DomainContextHandler.MATCH_VALUES_ALL,
            metas_in_res=True)

        encoded_attributes, encoded_metas = handler.encode_domain(self.domain)

        self.assertEqual(encoded_attributes,
                         {'c1': Continuous, 'd1': list('abc'),
                          'd2': list('def'), 'd3': list('ghi')})
        self.assertEqual(encoded_metas,
                         {'c2': Continuous, 'd4': list('jkl')})

    def test_encode_domain_with_false_attributes_in_res(self):
        handler = DomainContextHandler(attributes_in_res=False,
                                       metas_in_res=True)

        encoded_attributes, encoded_metas = handler.encode_domain(self.domain)

        self.assertEqual(encoded_attributes, {})
        self.assertEqual(encoded_metas, {'c2': Continuous, 'd4': Discrete})

    def test_encode_domain_with_false_metas_in_res(self):
        handler = DomainContextHandler(attributes_in_res=True,
                                       metas_in_res=False)

        encoded_attributes, encoded_metas = handler.encode_domain(self.domain)

        self.assertEqual(encoded_attributes,
                         {'c1': Continuous, 'd1': Discrete,
                          'd2': Discrete, 'd3': Discrete})
        self.assertEqual(encoded_metas, {})

    def test_match_returns_2_on_perfect_match(self):
        context = Mock(
            attributes=self.args[1], metas=self.args[2], values={})
        self.assertEqual(2., self.handler.match(context, *self.args))

    def test_match_returns_1_if_everything_matches(self):
        self.handler.bind(SimpleWidget)

        # Attributes in values
        context = Mock(values=dict(
            with_metas=('d1', Discrete),
            required=('d1', Discrete)))
        self.assertEqual(1., self.handler.match(context, *self.args))

        # Metas in values
        context = Mock(values=dict(
            with_metas=('d4', Discrete),
            required=('d1', Discrete)))
        self.assertEqual(1., self.handler.match(context, *self.args))

        # Attributes in lists
        context = Mock(values=dict(
            with_metas=[("d1", Discrete)]
        ))
        self.assertEqual(1., self.handler.match(context, *self.args))

#.........这里部分代码省略.........
开发者ID:RachitKansal,项目名称:orange3,代码行数:103,代码来源:test_domain_context_handler.py

示例4: DomainContextHandlerTestCase

# 需要导入模块: from Orange.widgets.settings import DomainContextHandler [as 别名]
# 或者: from Orange.widgets.settings.DomainContextHandler import bind [as 别名]
class DomainContextHandlerTestCase(TestCase):
    def setUp(self):
        self.domain = Domain(
            attributes=[ContinuousVariable('c1'),
                        DiscreteVariable('d1', values='abc'),
                        DiscreteVariable('d2', values='def')],
            class_vars=[DiscreteVariable('d3', values='ghi')],
            metas=[ContinuousVariable('c2'),
                   DiscreteVariable('d4', values='jkl')]
        )
        self.args = (self.domain,
                     {'c1': Continuous, 'd1': Discrete,
                      'd2': Discrete, 'd3': Discrete},
                     {'c2': Continuous, 'd4': Discrete, })
        self.handler = DomainContextHandler(metas_in_res=True)
        self.handler.read_defaults = lambda: None

    def test_encode_domain_with_match_none(self):
        handler = DomainContextHandler(
            match_values=DomainContextHandler.MATCH_VALUES_NONE,
            metas_in_res=True)

        encoded_attributes, encoded_metas = handler.encode_domain(self.domain)

        self.assertEqual(encoded_attributes,
                         {'c1': Continuous, 'd1': Discrete,
                          'd2': Discrete, 'd3': Discrete})
        self.assertEqual(encoded_metas, {'c2': Continuous, 'd4': Discrete, })

    def test_encode_domain_with_match_class(self):
        handler = DomainContextHandler(
            match_values=DomainContextHandler.MATCH_VALUES_CLASS,
            metas_in_res=True)

        encoded_attributes, encoded_metas = handler.encode_domain(self.domain)

        self.assertEqual(encoded_attributes,
                         {'c1': Continuous, 'd1': Discrete, 'd2': Discrete,
                          'd3': list('ghi')})
        self.assertEqual(encoded_metas, {'c2': Continuous, 'd4': Discrete})

    def test_encode_domain_with_match_all(self):
        handler = DomainContextHandler(
            match_values=DomainContextHandler.MATCH_VALUES_ALL,
            metas_in_res=True)

        encoded_attributes, encoded_metas = handler.encode_domain(self.domain)

        self.assertEqual(encoded_attributes,
                         {'c1': Continuous, 'd1': list('abc'),
                          'd2': list('def'), 'd3': list('ghi')})
        self.assertEqual(encoded_metas,
                         {'c2': Continuous, 'd4': list('jkl')})

    def test_encode_domain_with_false_attributes_in_res(self):
        handler = DomainContextHandler(attributes_in_res=False,
                                       metas_in_res=True)

        encoded_attributes, encoded_metas = handler.encode_domain(self.domain)

        self.assertEqual(encoded_attributes, {})
        self.assertEqual(encoded_metas, {'c2': Continuous, 'd4': Discrete})

    def test_encode_domain_with_false_metas_in_res(self):
        handler = DomainContextHandler(attributes_in_res=True,
                                       metas_in_res=False)

        encoded_attributes, encoded_metas = handler.encode_domain(self.domain)

        self.assertEqual(encoded_attributes,
                         {'c1': Continuous, 'd1': Discrete,
                          'd2': Discrete, 'd3': Discrete})
        self.assertEqual(encoded_metas, {})

    def test_match_returns_2_on_perfect_match(self):
        context = Mock(
            attributes=self.args[1], metas=self.args[2], values={})
        self.assertEqual(2., self.handler.match(context, *self.args))

    def test_match_returns_1_if_everything_matches(self):
        self.handler.bind(SimpleWidget)

        # Attributes in values
        context = Mock(values=dict(
            with_metas=('d1', Discrete),
            required=('d1', Discrete)))
        self.assertEqual(1., self.handler.match(context, *self.args))

        # Metas in values
        context = Mock(values=dict(
            with_metas=('d4', Discrete),
            required=('d1', Discrete)))
        self.assertEqual(1., self.handler.match(context, *self.args))

        # Attributes in lists
        context = Mock(values=dict(
            with_metas=[("d1", Discrete)]
        ))
        self.assertEqual(1., self.handler.match(context, *self.args))

#.........这里部分代码省略.........
开发者ID:675801717,项目名称:orange3,代码行数:103,代码来源:test_domain_context_handler.py


注:本文中的Orange.widgets.settings.DomainContextHandler.bind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。