本文整理汇总了Python中operator.and_方法的典型用法代码示例。如果您正苦于以下问题:Python operator.and_方法的具体用法?Python operator.and_怎么用?Python operator.and_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类operator
的用法示例。
在下文中一共展示了operator.and_方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: interpret_multi_sents
# 需要导入模块: import operator [as 别名]
# 或者: from operator import and_ [as 别名]
def interpret_multi_sents(self, inputs, discourse_ids=None, question=False, verbose=False):
"""
Use Boxer to give a first order representation.
:param inputs: list of list of str Input discourses to parse
:param occur_index: bool Should predicates be occurrence indexed?
:param discourse_ids: list of str Identifiers to be inserted to each occurrence-indexed predicate.
:return: ``drt.DrtExpression``
"""
if discourse_ids is not None:
assert len(inputs) == len(discourse_ids)
assert reduce(operator.and_, (id is not None for id in discourse_ids))
use_disc_id = True
else:
discourse_ids = list(map(str, range(len(inputs))))
use_disc_id = False
candc_out = self._call_candc(inputs, discourse_ids, question, verbose=verbose)
boxer_out = self._call_boxer(candc_out, verbose=verbose)
# if 'ERROR: input file contains no ccg/2 terms.' in boxer_out:
# raise UnparseableInputException('Could not parse with candc: "%s"' % input_str)
drs_dict = self._parse_to_drs_dict(boxer_out, use_disc_id)
return [drs_dict.get(id, None) for id in discourse_ids]
示例2: unify_nsplits
# 需要导入模块: import operator [as 别名]
# 或者: from operator import and_ [as 别名]
def unify_nsplits(*tensor_axes):
tensor_splits = [dict((a, split) for a, split in zip(axes, t.nsplits) if split != (1,))
for t, axes in tensor_axes if t.nsplits]
common_axes = reduce(operator.and_, [set(ts.keys()) for ts in tensor_splits]) if tensor_splits else set()
axes_unified_splits = dict((ax, decide_unify_split(*(t[ax] for t in tensor_splits)))
for ax in common_axes)
if len(common_axes) == 0:
return tuple(t[0] for t in tensor_axes)
res = []
for t, axes in tensor_axes:
new_chunk = dict((i, axes_unified_splits[ax]) for ax, i in zip(axes, range(t.ndim))
if ax in axes_unified_splits)
res.append(t.rechunk(new_chunk)._inplace_tile())
return tuple(res)
示例3: _convert_req
# 需要导入模块: import operator [as 别名]
# 或者: from operator import and_ [as 别名]
def _convert_req(req_dict):
if not getattr(req_dict, "items", None):
return _convert_specifier(req_dict)
req_dict = dict(req_dict)
if "version" in req_dict:
req_dict["version"] = _convert_specifier(req_dict["version"])
markers = []
if "markers" in req_dict:
markers.append(Marker(req_dict.pop("markers")))
if "python" in req_dict:
markers.append(
Marker(_convert_python(req_dict.pop("python")).as_marker_string())
)
if markers:
req_dict["marker"] = str(functools.reduce(operator.and_, markers)).replace(
'"', "'"
)
if "rev" in req_dict or "branch" in req_dict or "tag" in req_dict:
req_dict["ref"] = req_dict.pop(
"rev", req_dict.pop("tag", req_dict.pop("branch", None))
)
return req_dict
示例4: add_globals
# 需要导入模块: import operator [as 别名]
# 或者: from operator import and_ [as 别名]
def add_globals(self):
"Add some Scheme standard procedures."
import math, cmath, operator as op
from functools import reduce
self.update(vars(math))
self.update(vars(cmath))
self.update({
'+':op.add, '-':op.sub, '*':op.mul, '/':op.itruediv, 'níl':op.not_, 'agus':op.and_,
'>':op.gt, '<':op.lt, '>=':op.ge, '<=':op.le, '=':op.eq, 'mod':op.mod,
'frmh':cmath.sqrt, 'dearbhluach':abs, 'uas':max, 'íos':min,
'cothrom_le?':op.eq, 'ionann?':op.is_, 'fad':len, 'cons':cons,
'ceann':lambda x:x[0], 'tóin':lambda x:x[1:], 'iarcheangail':op.add,
'liosta':lambda *x:list(x), 'liosta?': lambda x:isa(x,list),
'folamh?':lambda x: x == [], 'adamh?':lambda x: not((isa(x, list)) or (x == None)),
'boole?':lambda x: isa(x, bool), 'scag':lambda f, x: list(filter(f, x)),
'cuir_le':lambda proc,l: proc(*l), 'mapáil':lambda p, x: list(map(p, x)),
'lódáil':lambda fn: load(fn), 'léigh':lambda f: f.read(),
'oscail_comhad_ionchuir':open,'dún_comhad_ionchuir':lambda p: p.file.close(),
'oscail_comhad_aschur':lambda f:open(f,'w'), 'dún_comhad_aschur':lambda p: p.close(),
'dac?':lambda x:x is eof_object, 'luacháil':lambda x: evaluate(x),
'scríobh':lambda x,port=sys.stdout:port.write(to_string(x) + '\n')})
return self
示例5: compile_query
# 需要导入模块: import operator [as 别名]
# 或者: from operator import and_ [as 别名]
def compile_query(query):
"""Compile each expression in query recursively."""
if isinstance(query, dict):
expressions = []
for key, value in query.items():
if key.startswith('$'):
if key not in query_funcs:
raise AttributeError('Invalid operator: {}'.format(key))
expressions.append(query_funcs[key](value))
else:
expressions.append(filter_query(key, value))
if len(expressions) > 1:
return boolean_operator_query(operator.and_)(expressions)
else:
return (
expressions[0]
if len(expressions)
else lambda query_function: query_function(None, None)
)
else:
return query
示例6: _reduced_filter
# 需要导入模块: import operator [as 别名]
# 或者: from operator import and_ [as 别名]
def _reduced_filter(self) -> t.Optional[Predicate]:
"""Before evaluation, sum up all filter predicates into a single one"""
return None if self._is_trivial else reduce(and_, self._filters)
# lazy queries
示例7: testAnd
# 需要导入模块: import operator [as 别名]
# 或者: from operator import and_ [as 别名]
def testAnd(self):
self.binaryCheck(operator.and_)
示例8: __init__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import and_ [as 别名]
def __init__(self, left: CriteriaType, right: CriteriaType):
super().__init__(left, right, operator.and_, "&")
示例9: combine_readings
# 需要导入模块: import operator [as 别名]
# 或者: from operator import and_ [as 别名]
def combine_readings(self, readings):
""":see: ReadingCommand.combine_readings()"""
return reduce(and_, readings)
示例10: __eq__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import and_ [as 别名]
def __eq__(self, other):
return self.__class__ == other.__class__ and \
self.refs == other.refs and \
len(self.conds) == len(other.conds) and \
reduce(operator.and_, (c1==c2 for c1,c2 in zip(self.conds, other.conds))) and \
self.consequent == other.consequent
示例11: __init__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import and_ [as 别名]
def __init__(self):
def defined(node, incoming):
gen = ast_.get_updated(node.value)
return gen, frozenset()
super(Defined, self).__init__('defined', defined, operator.and_)
示例12: __eq__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import and_ [as 别名]
def __eq__(self, other):
expressions = [(self.model_class._meta.fields[field] == value)
for field, value in zip(self.field_names, other)]
return reduce(operator.and_, expressions)
示例13: _add_query_clauses
# 需要导入模块: import operator [as 别名]
# 或者: from operator import and_ [as 别名]
def _add_query_clauses(self, initial, expressions, conjunction=None):
reduced = reduce(operator.and_, expressions)
if initial is None:
return reduced
conjunction = conjunction or operator.and_
return conjunction(initial, reduced)
示例14: filter
# 需要导入模块: import operator [as 别名]
# 或者: from operator import and_ [as 别名]
def filter(self, *args, **kwargs):
# normalize args and kwargs into a new expression
dq_node = Node()
if args:
dq_node &= reduce(operator.and_, [a.clone() for a in args])
if kwargs:
dq_node &= DQ(**kwargs)
# dq_node should now be an Expression, lhs = Node(), rhs = ...
q = deque([dq_node])
dq_joins = set()
while q:
curr = q.popleft()
if not isinstance(curr, Expression):
continue
for side, piece in (('lhs', curr.lhs), ('rhs', curr.rhs)):
if isinstance(piece, DQ):
query, joins = self.convert_dict_to_node(piece.query)
dq_joins.update(joins)
expression = reduce(operator.and_, query)
# Apply values from the DQ object.
expression._negated = piece._negated
expression._alias = piece._alias
setattr(curr, side, expression)
else:
q.append(piece)
dq_node = dq_node.rhs
query = self.clone()
for field in dq_joins:
if isinstance(field, ForeignKeyField):
lm, rm = field.model_class, field.rel_model
field_obj = field
elif isinstance(field, ReverseRelationDescriptor):
lm, rm = field.field.rel_model, field.rel_model
field_obj = field.field
query = query.ensure_join(lm, rm, field_obj)
return query.where(dq_node)
示例15: _apply_where
# 需要导入模块: import operator [as 别名]
# 或者: from operator import and_ [as 别名]
def _apply_where(self, query, filters, conjunction=None):
conjunction = conjunction or operator.and_
if filters:
expressions = [
(self.model_class._meta.fields[column] == value)
for column, value in filters.items()]
query = query.where(reduce(conjunction, expressions))
return query