def predict(self, word_seq, n): """ Predicts the tag sequence of a word sequence 'word_seq' using 'n'-gram model. ---- input word_seq: a list of word strings to predict the tag sequence n: either 2 (bigram) or 3 (trigram) returns a list of tag strings of the tag sequence predicted """ seq_size = len(word_seq) if seq_size <= 0: return [] dynamic_table = DynamicTable() for c in xrange(0,seq_size): next_col = self.get_next_column(dynamic_table, n, c, word_seq[c]) dynamic_table.update(next_col) last_c = seq_size - 1 last_col = dynamic_table.probs[last_c] last_best_tag = max(last_col, key=last_col.get) return dynamic_table.full_path(last_c, last_best_tag)