本文整理汇总了Python中nltk.sem.logic.is_indvar函数的典型用法代码示例。如果您正苦于以下问题:Python is_indvar函数的具体用法?Python is_indvar怎么用?Python is_indvar使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_indvar函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, domain, assign=None):
dict.__init__(self)
self.domain = domain
if assign:
for (var, val) in assign:
assert val in self.domain,\
"'%s' is not in the domain: %s" % (val, self.domain)
assert is_indvar(var),\
"Wrong format for an Individual Variable: '%s'" % var
self[var] = val
self._addvariant()
示例2: clausify
def clausify(expression):
"""
Skolemize, clausify, and standardize the variables apart.
"""
clause_list = []
for clause in _clausify(skolemize(expression)):
for free in clause.free():
if is_indvar(free.name):
newvar = VariableExpression(unique_variable())
clause = clause.replace(free, newvar)
clause_list.append(clause)
return clause_list
示例3: add
def add(self, var, val):
"""
Add a new variable-value pair to the assignment, and update
``self.variant``.
"""
assert val in self.domain,\
"%s is not in the domain %s" % (val, self.domain)
assert is_indvar(var),\
"Wrong format for an Individual Variable: '%s'" % var
self[var] = val
self._addvariant()
return self
示例4: DrtVariableExpression
def DrtVariableExpression(variable):
"""
This is a factory method that instantiates and returns a subtype of
``DrtAbstractVariableExpression`` appropriate for the given variable.
"""
if is_indvar(variable.name):
return DrtIndividualVariableExpression(variable)
elif is_funcvar(variable.name):
return DrtFunctionVariableExpression(variable)
elif is_eventvar(variable.name):
return DrtEventVariableExpression(variable)
else:
return DrtConstantExpression(variable)
示例5: _convert2val
def _convert2val(self, valuation_str):
"""
Transform the output file into an NLTK-style Valuation.
:return: A model if one is generated; None otherwise.
:rtype: sem.Valuation
"""
valuation_standard_format = self._transform_output(valuation_str, 'standard')
val = []
for line in valuation_standard_format.splitlines(False):
l = line.strip()
if l.startswith('interpretation'):
# find the number of entities in the model
num_entities = int(l[l.index('(') + 1 : l.index(',')].strip())
elif l.startswith('function') and l.find('_') == -1:
# replace the integer identifier with a corresponding alphabetic character
name = l[l.index('(') + 1 : l.index(',')].strip()
if is_indvar(name):
name = name.upper()
value = int(l[l.index('[') + 1 : l.index(']')].strip())
val.append((name, MaceCommand._make_model_var(value)))
elif l.startswith('relation'):
l = l[l.index('(') + 1 :]
if '(' in l:
# relation is not nullary
name = l[: l.index('(')].strip()
values = [
int(v.strip())
for v in l[l.index('[') + 1 : l.index(']')].split(',')
]
val.append(
(name, MaceCommand._make_relation_set(num_entities, values))
)
else:
# relation is nullary
name = l[: l.index(',')].strip()
value = int(l[l.index('[') + 1 : l.index(']')].strip())
val.append((name, value == 1))
return Valuation(val)
示例6: _order_ref_strings
def _order_ref_strings(self, refs):
strings = ["%s" % ref for ref in refs]
ind_vars = []
func_vars = []
event_vars = []
other_vars = []
for s in strings:
if is_indvar(s):
ind_vars.append(s)
elif is_funcvar(s):
func_vars.append(s)
elif is_eventvar(s):
event_vars.append(s)
else:
other_vars.append(s)
return sorted(other_vars) + \
sorted(event_vars, key=lambda v: int([v[2:],-1][len(v[2:]) == 0])) + \
sorted(func_vars, key=lambda v: (v[0], int([v[1:],-1][len(v[1:])==0]))) + \
sorted(ind_vars, key=lambda v: (v[0], int([v[1:],-1][len(v[1:])==0])))