def init_IS_from_DB(self):
        self.reset_IS()

        if self.bk_is_private_agenda != "":
            # for elem in self.bk_is_private_agenda.split(';'):
            #     self.IS.private.agenda.push(elem)
            self.IS.private.agenda = trindikit.stack(pickle.loads(
                self.bk_is_private_agenda),
                                                     fixedType=object)
        if self.bk_is_private_plan != "":
            # for elem in self.bk_is_private_plan.split(';'):
            #     self.IS.private.plan.push(elem)
            self.IS.private.plan = trindikit.stack(pickle.loads(
                self.bk_is_private_plan),
                                                   fixedType=object)
        if self.bk_is_private_bel != "":
            # self.IS.private.bel = set(self.bk_is_private_bel.split(';'))
            self.IS.private.bel = set(pickle.loads(self.bk_is_private_bel))
        if self.bk_is_shared_com != "":
            # self.IS.shared.com = set(self.bk_is_shared_com.split(';'))
            self.IS.shared.com = set(pickle.loads(self.bk_is_shared_com))
        if self.bk_is_shared_qud != "":
            self.IS.shared.qud = trindikit.stackset(pickle.loads(
                self.bk_is_shared_qud),
                                                    fixedType=object)
            # for elem in self.bk_is_shared_qud.split(';'):
            #     self.IS.shared.qud.push(elem)
        self.IS.shared.lu.speaker = trindikit.Speaker.USR if self.bk_is_shared_lu_speaker == "USR" else trindikit.Speaker.SYS
        if self.bk_is_shared_lu_moves != "":
            self.IS.shared.lu.moves = set(
                pickle.loads(self.bk_is_shared_lu_moves))
예제 #2
0
 def reset_IS(self):
     self.IS = record(private = record(agenda = stack(),
                                       plan   = stack(),
                                       bel    = set()),
                      shared  = record(com    = set(),
                                       qud    = stackset(),
                                       lu     = record(speaker = Speaker,
                                                       moves   = set())))
 def reset_IS(self):
     self.IS = trindikit.record(
         private=trindikit.record(agenda=trindikit.stack(),
                                  plan=trindikit.stack(),
                                  bel=set()),
         shared=trindikit.record(
             com=set(),
             qud=trindikit.stackset(),
             lu=trindikit.record(speaker=trindikit.Speaker, moves=set())))
예제 #4
0
    def pload_IS(self, filename):
        # asdf = ConsultDB("?x.penis(x)") #equal to ConsultDB(Question("?x.penis(x)"))
        if p.exists(filename):
            with open(filename, 'rb') as f:
                tmp_dict = pickle.load(f)

                self.IS = record(private = record(agenda = stack(tmp_dict["private"]["agenda"]),
                                                  plan   = stack(tmp_dict["private"]["plan"], PlanConstructor),
                                                  # TODO: warum ist das beim normalen initialisieren ein PlanConstructor?
                                                  bel    = set(tmp_dict["private"]["bel"])),
                                 shared  = record(com    = set(tmp_dict["shared"]["com"]),
                                                  qud    = stackset(tmp_dict["shared"]["qud"], object),
                                                  lu     = record(speaker = Speaker.USR,
                                                                  moves   = set(tmp_dict["shared"]["lu"]["moves"]))))
        else:
            self.reset_IS()
 def find_neighbours_of_variables(self):
     tmp = [(v, k) for k, v in self.variablepath.items()]
     # for key,val in tmp:
     #     print(key, "->", val)
     # okay, hier muss man sich vorher und nachher tmp printen um zu gucken was passiert... tatsache ist, es wird geschaut
     # wovon die variablen benachbart sein können.
     whattoreplace = list(self.variables.items())
     while len(whattoreplace) > 0:
         innerkey, innerval = whattoreplace[0]
         for key, val in tmp:
             if val == innerkey:
                 tmp.append((key, innerval))
                 whattoreplace.append((key, innerval))
             elif " " in val:
                 reconstr = []
                 for i in val.split(" "):
                     reconstr.append(i if i != innerkey else innerval)
                 if " ".join(reconstr) != val:
                     tmp.append((key, " ".join(reconstr)))
                     whattoreplace.append((key, " ".join(reconstr)))
         del whattoreplace[0]
     # for key,val in tmp:
     #     print(key, "->", val)
     neighbours = set()
     for _, val in tmp:
         if " " in val:
             pos = val.split(" ")
             for i in range(len(pos)):
                 if pos[i] in self.variables.values():
                     if i > 0:
                         neighbours.add((pos[i - 1], "r", pos[i]))
                     if i < len(pos) - 1:
                         neighbours.add((pos[i + 1], "l", pos[i]))
     return list(neighbours)
    def preprocess_grammar(self, grammarFilename):
        preprocessed = ''
        self.longstrings = {}
        self.variables = {}
        self.variablepath = {}
        self.all_sents = set()
        with open(grammarFilename, "r", encoding="utf-8") as f:
            lines = [line for line in f]
        for i in range(len(lines)):
            lines[i] = self.line_ops(lines[i], self.variablepath,
                                     self.all_sents)
            lines[i] = self.incorporate_optionals(lines[i])
            lines[i] = self.find_longstrings(lines[i])
            #other line-operations here (on line)
        for i in list(self.all_sents):
            # print(self.preprocess_input(i+" something").split())
            # print(self.partial_parse()) #TODO - sobald das partial-parsen einduetig nur die wirklich möglichen returned (sobald ich darin die phrase-structure-teile drin hab) dann auch die richtigen nutzen um hier wann ist {semester} vorzusclhagen #asdf
            pass

        preprocessed = "\n".join(lines)
        #other overall operations here (on preprocessed)
        for key, val in self.longstrings.items():
            preprocessed = preprocessed.replace("'" + key + "'",
                                                "'" + val + "'")

        return preprocessed
 def __init__(self, preds0, preds1, preds2, sorts, converters):
     self.preds0 = set(preds0)  # return
     self.preds1 = dict(preds1)  # city, day-of, ...
     self.preds2 = dict(preds2) if preds2 else None
     self.sorts = dict(sorts)  # {'city': ('paris', 'london', 'berlin')}
     self.inds = dict(
         (ind, sort) for sort in self.sorts for ind in self.sorts[sort]
     )  # {'berlin': 'city', 'train': 'means', 'today': 'day', 'tuesday': 'day', ...}
     self.converters = converters  #welche funktionen nötig sind um aus strings "sorts" zu machen
     self.plans = {}
def powerset(L, fixedLen=False, incShuffles=True):
    pset = set()
    for n in range(len(L) + 1):
        for sset in itertools.combinations(L, n):
            pset.add(sset)
    if fixedLen:
        pset = [i for i in pset if len(i) == fixedLen]
    if not incShuffles:
        return pset
    else:
        return flatten([list(itertools.permutations(i)) for i in pset])
 def reset_MIVS(self):
     """Initialise the MIVS. To be called from self.init()."""
     self.INPUT = trindikit.value(str)
     self.LATEST_SPEAKER = trindikit.value(
         trindikit.Speaker
     )  #initializing it with "Speaker" means that it can only take Speaker.USR or Speaker.SYS
     self.LATEST_MOVES = set(
     )  #sind die NEXT_MOVES von einer Iteration vorher
     self.NEXT_MOVES = trindikit.stack(trindikit.Move)
     self.OUTPUT = trindikit.value(str)
     self.PROGRAM_STATE = trindikit.value(
         trindikit.ProgramState)  #see above
     self.PROGRAM_STATE.set(trindikit.ProgramState.RUN)
 def init_MIVS_from_DB(self):
     self.reset_MIVS()
     self.INPUT.set(self.bk_mivs_input)
     self.LATEST_SPEAKER.set(
         trindikit.Speaker.USR if self.bk_mivs_latest_speaker ==
         "USR" else trindikit.Speaker.SYS)
     if self.bk_mivs_latest_moves != "":
         # self.LATEST_MOVES = set(self.bk_mivs_latest_moves.split(';'))
         self.LATEST_MOVES = trindikit.set(
             pickle.loads(self.bk_mivs_latest_moves))
     if self.bk_mivs_next_moves != "":
         self.NEXT_MOVES = trindikit.stack(pickle.loads(
             self.bk_mivs_next_moves),
                                           fixedType=trindikit.Move)
         # for elem in self.bk_mivs_next_moves.split(';'):
         #     self.NEXT_MOVES.push(elem)
     self.OUTPUT.set(self.bk_mivs_output)
     self.PROGRAM_STATE.set(trindikit.ProgramState.RUN
                            )  #must run, other stuff would be bullshit
 def interpret(self,
               input,
               IS,
               DOMAIN,
               NEXT_MOVES,
               APICONNECTOR,
               anyString=False,
               moves=None):  #überschreibe ich nochmal in studip
     """Parse an input string into a dialogue move or a set of moves."""
     try:
         return self.parseString(input, IS, DOMAIN, NEXT_MOVES)
     except:
         pass
     try:
         if not all(i.isnumeric() for i in input): return eval(input)
     except:
         pass
     if anyString:
         return Answer(ShortAns(input))
     return set([])