From 0aacc7df0f106cbca991c2d7d0d86d5ec3abafad Mon Sep 17 00:00:00 2001 From: schneefux Date: Sat, 27 Sep 2014 14:41:02 +0200 Subject: Add method to get keyword phrases to vocabcompiler This way they can be used by other STT engines as well --- client/vocabcompiler.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'client/vocabcompiler.py') diff --git a/client/vocabcompiler.py b/client/vocabcompiler.py index c59bd6e..8edee6f 100644 --- a/client/vocabcompiler.py +++ b/client/vocabcompiler.py @@ -12,6 +12,8 @@ from abc import ABCMeta, abstractmethod, abstractproperty import g2p import brain +import jasperpath + try: import cmuclmtk except ImportError: @@ -333,6 +335,24 @@ def get_phrases_from_module(module): return module.WORDS if hasattr(module, 'WORDS') else [] +def get_keyword_phrases(): + """ + Gets the keyword phrases from the keywords file in the jasper data dir. + + Returns: + A list of keyword phrases. + """ + phrases = [] + + with open(jasperpath.data('keyword_phrases'), mode="r") as f: + for line in f: + phrase = line.strip() + if phrase: + phrases.append(phrase) + + return phrases + + def get_all_phrases(): """ Gets phrases from all modules. -- cgit v1.3.1