def lookup_sentence()

in rtfm/featurizer.py [0:0]


    def lookup_sentence(self, sent, vocab, max_len=10, eos='pad', pad='pad'):
        if isinstance(sent, list):
            words = sent[:max_len-1] + [eos]
            length = len(words)
            if len(words) < max_len:
                words += [pad] * (max_len - len(words))
            return vocab.word2index([w.strip() for w in words]), length
        else:
            sent = sent.lower()
            key = sent, max_len
            if key not in self._cache:
                words = revtok.tokenize(sent)[:max_len-1] + [eos]
                length = len(words)
                if len(words) < max_len:
                    words += [pad] * (max_len - len(words))
                self._cache[key] = vocab.word2index([w.strip() for w in words]), length
                while len(self._cache) > self.max_cache:
                    keys = list(self._cache.keys())
                    del self._cache[random.choice(keys)]
            return self._cache[key]