def load_from_arpa_str(self, arpa_str):
        """
        Initialize N-gram model by reading an ARPA language model string.

        Parameters
        ----------
        arpa_str : str
            A string in ARPA language model file format
        """
        data_found = False
        end_found = False
        in_ngram_block = 0
        for i, line in enumerate(arpa_str.split("\n")):
            if not end_found:
                if not data_found:
                    if "\\data\\" in line:
                        data_found = True
                else:
                    if in_ngram_block == 0:
                        if line.startswith("ngram"):
                            ngram_type, count = line.split("=")
                            _, n = ngram_type.split(" ")
                            n = int(n)
                            self.ngrams[n] = {'data': {},
                                              'count': count}
                        elif line.startswith("\\"):
                            n = int(line.split("-")[0][1:])
                            in_ngram_block = n
                        else:
                            continue  # Empty line
                    elif in_ngram_block > 0:
                        if "\\end\\" in line:
                            end_found = True
                        elif line.startswith("\\"):
                            n = int(line.split("-")[0][1:])
                            in_ngram_block = n
                        elif len(line) <= 1:
                            continue
                        else:
                            data = line.split("\t")
                            probability = Decimal(data[0])
                            ngram = data[1:]
                            if len(ngram) != n:
                                raise Exception(("ARPA language file is "
                                                 "inconsistant. Line %i has "
                                                 "only %i items, but should "
                                                 "have %i items.") %
                                                (i, len(ngram), n))
                            rest = ngram
                            append_to = self.ngrams[n]['data']
                            while len(rest) > 1:
                                first, rest = rest[0], rest[1:]
                                if first not in append_to:
                                    append_to[first] = {}
                                append_to = append_to[first]
                            if rest[0] in append_to:
                                raise Exception(("Duplicate entry for "
                                                 "ngram %s") % ngram)
                            append_to[rest[0]] = probability
            else:
                if line.startswith("info: "):
                    logging.info(line[6:])
Initialize N-gram model by reading an ARPA language model string.

        Parameters
        ----------
        arpa_str : str
            A string in ARPA language model file format