def get_sentence(naf: KafNafParser, term: Cterm) -> int: tokens = [ naf.get_token(tid) for tid in naf.get_dict_tokens_for_termid(term.get_id()) ] sent = {t.get_sent() for t in tokens} if len(sent) != 1: raise Exception( f"Term {term.get_id}:{term.get_lemma()} did not map to single sentence: {sent}" ) return sent.pop()
def get_word(naf: KafNafParser, term: Cterm) -> str: """Get the word(s) belonging to a term, joining them if there's more than one""" tokenids = naf.get_dict_tokens_for_termid(term.get_id()) tokens = sort_tokens(naf.get_token(tid) for tid in tokenids) return " ".join(t.get_text() for t in tokens)