def _check_consistency(self, threads, show=False, verbose=False): results = [] for tid in sorted(threads): assumptions = [ reading for (rid, reading) in self.expand_threads(tid, threads=threads) ] assumptions = list( map( self._reading_command.to_fol, self._reading_command.process_thread(assumptions), )) if assumptions: assumptions += self._background # if Mace4 finds a model, it always seems to find it quickly mb = MaceCommand(None, assumptions, max_models=20) modelfound = mb.build_model() else: modelfound = False results.append((tid, modelfound)) if show: spacer(80) print("Model for Discourse Thread %s" % tid) spacer(80) if verbose: for a in assumptions: print(a) spacer(80) if modelfound: print(mb.model(format="cooked")) else: print("No model found!\n") return results
def _check_consistency(self, threads, show=False, verbose=False): results = [] for tid in sorted(threads): assumptions = [reading for (rid, reading) in self.expand_threads(tid, threads=threads)] assumptions = map(self._reading_command.to_fol, self._reading_command.process_thread(assumptions)) if assumptions: assumptions += self._background # if Mace4 finds a model, it always seems to find it quickly mb = MaceCommand(None, assumptions, max_models=20) modelfound = mb.build_model() else: modelfound = False results.append((tid, modelfound)) if show: spacer(80) print("Model for Discourse Thread %s" % tid) spacer(80) if verbose: for a in assumptions: print(a) spacer(80) if modelfound: print(mb.model(format='cooked')) else: print("No model found!\n") return results
def _model(self, valuation_str, verbose=False): """ Transform the output file into an NLTK-style Valuation. @return: A model if one is generated; None otherwise. @rtype: L{nltk.sem.Valuation} """ valuation_standard_format = self._transform_output( valuation_str, 'standard', verbose) 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)
def _model(self, valuation_str, verbose=False): """ Transform the output file into an NLTK-style Valuation. @return: A model if one is generated; None otherwise. @rtype: L{nltk.sem.Valuation} """ valuation_standard_format = self._transform_output(valuation_str, 'standard', verbose) 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)