本文整理汇总了Python中Orange.widgets.settings.DomainContextHandler.filter_value方法的典型用法代码示例。如果您正苦于以下问题:Python DomainContextHandler.filter_value方法的具体用法?Python DomainContextHandler.filter_value怎么用?Python DomainContextHandler.filter_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Orange.widgets.settings.DomainContextHandler
的用法示例。
在下文中一共展示了DomainContextHandler.filter_value方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestDomainContextHandler
# 需要导入模块: from Orange.widgets.settings import DomainContextHandler [as 别名]
# 或者: from Orange.widgets.settings.DomainContextHandler import filter_value [as 别名]
#.........这里部分代码省略.........
(('c1', Continuous), ('d1', Discrete),
('d2', Discrete), ('d3', Discrete),
('c2', Continuous), ('d4', Discrete)))
self.assertEqual(widget.text, 'u')
self.assertEqual(widget.with_metas, [('d1', Discrete),
('d2', Discrete)])
def test_open_context_with_imperfect_match(self):
self.handler.bind(SimpleWidget)
context = self.create_context(None, dict(
text=('u', -2),
with_metas=[('d1', Discrete), ('d1', Continuous),
('c1', Continuous), ('c1', Discrete)],
if_selected=[('c1', Discrete), ('c1', Continuous),
('d1', Discrete), ('d1', Continuous)],
selected=[2],
))
self.handler.global_contexts = \
[Mock(values={}), context, Mock(values={})]
widget = SimpleWidget()
self.handler.initialize(widget)
self.handler.open_context(widget, self.args[0])
context = widget.current_context
self.assertEqual(context.attributes, self.args[1])
self.assertEqual(context.metas, self.args[2])
self.assertSequenceEqual(context.ordered_domain,
(('c1', Continuous), ('d1', Discrete),
('d2', Discrete), ('d3', Discrete),
('c2', Continuous), ('d4', Discrete)))
self.assertEqual(widget.text, 'u')
self.assertEqual(widget.with_metas, [('d1', Discrete),
('c1', Continuous)])
self.assertEqual(widget.if_selected, [('c1', Continuous),
('d1', Discrete)])
self.assertEqual(widget.selected, [1])
def test_open_context_with_no_match(self):
self.handler.bind(SimpleWidget)
widget = SimpleWidget()
self.handler.initialize(widget)
widget.text = 'u'
self.handler.open_context(widget, self.args[0])
self.assertEqual(widget.text, 'u')
self.assertEqual(widget.with_metas, [])
context = widget.current_context
self.assertEqual(context.attributes, self.args[1])
self.assertEqual(context.metas, self.args[2])
self.assertSequenceEqual(context.ordered_domain,
(('c1', Continuous), ('d1', Discrete),
('d2', Discrete), ('d3', Discrete),
('c2', Continuous), ('d4', Discrete)))
self.assertEqual(context.values['text'], ('u', -2))
def test_filter_value(self):
setting = ContextSetting([])
setting.name = "value"
def test_filter(before_value, after_value):
data = dict(value=before_value)
self.handler.filter_value(setting, data, *self.args)
self.assertEqual(data.get("value", None), after_value)
# filter list values
test_filter([], [])
# When list contains attributes asa tuple of (name, type),
# Attributes not present in domain should be filtered out
test_filter([("d1", Discrete), ("d1", Continuous),
("c1", Continuous), ("c1", Discrete)],
[("d1", Discrete), ("c1", Continuous)])
# All other values in list should remain
test_filter([0, [1, 2, 3], "abcd", 5.4], [0, [1, 2, 3], "abcd", 5.4])
def test_encode_setting(self):
setting = ContextSetting(None)
var = self.domain[0]
val = self.handler.encode_setting(None, setting, var)
self.assertEqual(val, (var.name, 100 + vartype(var)))
def test_decode_setting(self):
setting = ContextSetting(None)
var = self.domain[0]
val = self.handler.decode_setting(setting, (var.name, 100 + vartype(var)), self.domain)
self.assertIs(val, var)
def create_context(self, domain, values):
if not domain:
domain = Domain([])
context = self.handler.new_context(domain,
*self.handler.encode_domain(domain))
context.values = values
return context
示例2: TestDomainContextHandler
# 需要导入模块: from Orange.widgets.settings import DomainContextHandler [as 别名]
# 或者: from Orange.widgets.settings.DomainContextHandler import filter_value [as 别名]
#.........这里部分代码省略.........
with_metas=[('d1', Discrete), ('d1', Continuous),
('c1', Continuous), ('c1', Discrete)]
))
self.handler.global_contexts = \
[Mock(values={}), context, Mock(values={})]
widget = SimpleWidget()
self.handler.initialize(widget)
self.handler.open_context(widget, self.args[0])
context = widget.current_context
self.assertEqual(context.attributes, self.args[1])
self.assertEqual(context.metas, self.args[2])
self.assertEqual(widget.text, 'u')
self.assertEqual(widget.with_metas, [('d1', Discrete),
('c1', Continuous)])
def test_open_context_with_no_match(self):
self.handler.bind(SimpleWidget)
widget = SimpleWidget()
self.handler.initialize(widget)
widget.text = 'u'
self.handler.open_context(widget, self.args[0])
self.assertEqual(widget.text, 'u')
self.assertEqual(widget.with_metas, [])
context = widget.current_context
self.assertEqual(context.attributes, self.args[1])
self.assertEqual(context.metas, self.args[2])
self.assertEqual(context.values['text'], ('u', -2))
def test_filter_value(self):
setting = ContextSetting([])
setting.name = "value"
def test_filter(before_value, after_value):
data = dict(value=before_value)
self.handler.filter_value(setting, data, *self.args)
self.assertEqual(data.get("value", None), after_value)
# filter list values
test_filter([], [])
# When list contains attributes asa tuple of (name, type),
# Attributes not present in domain should be filtered out
test_filter([("d1", Discrete), ("d1", Continuous),
("c1", Continuous), ("c1", Discrete)],
[("d1", Discrete), ("c1", Continuous)])
# All other values in list should remain
test_filter([0, [1, 2, 3], "abcd", 5.4], [0, [1, 2, 3], "abcd", 5.4])
def test_encode_setting(self):
setting = ContextSetting(None)
var = self.domain[0]
val = self.handler.encode_setting(None, setting, var)
self.assertEqual(val, (var.name, 100 + vartype(var)))
# Should not crash on anonymous variables
var.name = ""
val = self.handler.encode_setting(None, setting, var)
self.assertEqual(val, (var.name, 100 + vartype(var)))
def test_encode_list_settings(self):
setting = ContextSetting(None)