# Path: cam/sgnmt/predictors/core.py
# class UnboundedVocabularyPredictor(Predictor):
#     """Predictors under this class implement models with very large 
#     target vocabularies, for which it is too inefficient to list the 
#     entire posterior. Instead, they are evaluated only for a given list
#     of target words. This list is usually created by taking all non-zero
#     probability words from the bounded vocabulary predictors. An 
#     example of a unbounded vocabulary predictor is the ngram predictor:
#     Instead of listing the entire ngram vocabulary, we run srilm only
#     on the words which are possible according other predictor (e.g. fst
#     or nmt). This is realized by introducing the ``trgt_words``
#     argument to ``predict_next``. """
# 
#     def __init__(self):
#         """ Initializes ``current_sen_id`` with 0. """
#         super(UnboundedVocabularyPredictor, self).__init__()
# 
#     @abstractmethod
#     def predict_next(self, trgt_words):
#         """Like in ``Predictor``, returns the predictive distribution
#         over target words given the predictor state. Note 
#         that the prediction itself can change the state of the 
#         predictor. For example, the neural predictor updates the 
#         decoder network state and its attention to predict the next 
#         word. Two calls of ``predict_next()`` must be separated by a 
#         ``consume()`` call.
#         
#         Args:
#             trgt_words (list): List of target word ids.
#         
#         Returns:
#             dictionary,array,list. Word log probabilities for the next 
#             target token. All ids which are not set are assumed to have
#             probability ``get_unk_probability()``. The returned set should
#             not contain any ids which are not in ``trgt_words``, but it
#             does not have to score all of them
#         """
#         raise NotImplementedError
# 
# Path: cam/sgnmt/utils.py
# GO_ID = 1
# EOS_ID = 2
# UNK_ID = 0
# NOTAPPLICABLE_ID = 3
# NEG_INF = float("-inf")
# INF = float("inf")
# EPS_P = 0.00001
#     GO_ID = 0
#     EOS_ID = 2
#     UNK_ID = 3
#     GO_ID = 2 # Usually not used
#     EOS_ID = 1
#     UNK_ID = 3 # Don't rely on this: UNK not standardized in T2T
# TMP_FILENAME = '/tmp/sgnmt.%s.fst' % os.getpid()
# MESSAGE_TYPE_DEFAULT = 1
# MESSAGE_TYPE_POSTERIOR = 2
# MESSAGE_TYPE_FULL_HYPO = 3
# def switch_to_fairseq_indexing():
# def switch_to_t2t_indexing():
# def log_sum_tropical_semiring(vals):
# def log_sum_log_semiring(vals):
# def oov_to_unk(seq, vocab_size, unk_idx=None):
# def argmax_n(arr, n):
# def argmax(arr):
# def common_viewkeys(obj):
# def common_iterable(obj):
# def common_get(obj, key, default):
# def common_contains(obj, key):
# def w2f(fstweight):
# def load_fst(path):
# def get_path(tmpl, sub = 1):
# def split_comma(s, func=None):
#     def notify(self, message, message_type = MESSAGE_TYPE_DEFAULT):
#     def __init__(self):
#     def add_observer(self, observer):
#     def notify_observers(self, message, message_type = MESSAGE_TYPE_DEFAULT):
# class Observer(object):
# class Observable(object):


from cam.sgnmt.predictors.core import UnboundedVocabularyPredictor
from cam.sgnmt import utils
import math
    import kenlm
# -*- coding: utf-8 -*-
# coding=utf-8
# Copyright 2019 The SGNMT Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""This module contains predictors for n-gram (Kneser-Ney) language
modeling. This is a ``UnboundedVocabularyPredictor`` as the vocabulary
size ngram models normally do not permit complete enumeration of the
posterior.
"""


try:
    # Requires kenlm
except ImportError:
    pass # Deal with it in decode.py



# Path: cam/sgnmt/predictors/core.py
# class UnboundedVocabularyPredictor(Predictor):
#     """Predictors under this class implement models with very large 
#     target vocabularies, for which it is too inefficient to list the 
#     entire posterior. Instead, they are evaluated only for a given list
#     of target words. This list is usually created by taking all non-zero
#     probability words from the bounded vocabulary predictors. An 
#     example of a unbounded vocabulary predictor is the ngram predictor:
#     Instead of listing the entire ngram vocabulary, we run srilm only
#     on the words which are possible according other predictor (e.g. fst
#     or nmt). This is realized by introducing the ``trgt_words``
#     argument to ``predict_next``. """
# 
#     def __init__(self):
#         """ Initializes ``current_sen_id`` with 0. """
#         super(UnboundedVocabularyPredictor, self).__init__()
# 
#     @abstractmethod
#     def predict_next(self, trgt_words):
#         """Like in ``Predictor``, returns the predictive distribution
#         over target words given the predictor state. Note 
#         that the prediction itself can change the state of the 
#         predictor. For example, the neural predictor updates the 
#         decoder network state and its attention to predict the next 
#         word. Two calls of ``predict_next()`` must be separated by a 
#         ``consume()`` call.
#         
#         Args:
#             trgt_words (list): List of target word ids.
#         
#         Returns:
#             dictionary,array,list. Word log probabilities for the next 
#             target token. All ids which are not set are assumed to have
#             probability ``get_unk_probability()``. The returned set should
#             not contain any ids which are not in ``trgt_words``, but it
#             does not have to score all of them
#         """
#         raise NotImplementedError
# 
# Path: cam/sgnmt/utils.py
# GO_ID = 1
# EOS_ID = 2
# UNK_ID = 0
# NOTAPPLICABLE_ID = 3
# NEG_INF = float("-inf")
# INF = float("inf")
# EPS_P = 0.00001
#     GO_ID = 0
#     EOS_ID = 2
#     UNK_ID = 3
#     GO_ID = 2 # Usually not used
#     EOS_ID = 1
#     UNK_ID = 3 # Don't rely on this: UNK not standardized in T2T
# TMP_FILENAME = '/tmp/sgnmt.%s.fst' % os.getpid()
# MESSAGE_TYPE_DEFAULT = 1
# MESSAGE_TYPE_POSTERIOR = 2
# MESSAGE_TYPE_FULL_HYPO = 3
# def switch_to_fairseq_indexing():
# def switch_to_t2t_indexing():
# def log_sum_tropical_semiring(vals):
# def log_sum_log_semiring(vals):
# def oov_to_unk(seq, vocab_size, unk_idx=None):
# def argmax_n(arr, n):
# def argmax(arr):
# def common_viewkeys(obj):
# def common_iterable(obj):
# def common_get(obj, key, default):
# def common_contains(obj, key):
# def w2f(fstweight):
# def load_fst(path):
# def get_path(tmpl, sub = 1):
# def split_comma(s, func=None):
#     def notify(self, message, message_type = MESSAGE_TYPE_DEFAULT):
#     def __init__(self):
#     def add_observer(self, observer):
#     def notify_observers(self, message, message_type = MESSAGE_TYPE_DEFAULT):
# class Observer(object):
# class Observable(object):


# Path: cam/sgnmt/predictors/ngram.py
from cam.sgnmt.predictors.core import UnboundedVocabularyPredictor
from cam.sgnmt import utils
import math
    import kenlm

# -*- coding: utf-8 -*-
# coding=utf-8
# Copyright 2019 The SGNMT Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""This module contains predictors for n-gram (Kneser-Ney) language
modeling. This is a ``UnboundedVocabularyPredictor`` as the vocabulary
size ngram models normally do not permit complete enumeration of the
posterior.
"""


try:
    # Requires kenlm
except ImportError:
    pass # Deal with it in decode.py



class KenLMPredictor(UnboundedVocabularyPredictor):