RAPP Platform  v0.6.0
RAPP Platform is a collection of ROS nodes and back-end processes that aim to deliver ready-to-use generic services to robots
 All Classes Namespaces Files Functions Variables Macros
greek_english_support.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 #Copyright 2015 RAPP
5 
6 #Licensed under the Apache License, Version 2.0 (the "License");
7 #you may not use this file except in compliance with the License.
8 #You may obtain a copy of the License at
9 
10  #http://www.apache.org/licenses/LICENSE-2.0
11 
12 #Unless required by applicable law or agreed to in writing, software
13 #distributed under the License is distributed on an "AS IS" BASIS,
14 #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #See the License for the specific language governing permissions and
16 #limitations under the License.
17 
18 # Authors: Athanassios Kintsakis, Aris Thallas, Manos Tsardoulias
19 # contact: akintsakis@issel.ee.auth.gr, aris.thallas@{iti.gr, gmail.com}, etsardou@iti.gr
20 
21 
22 import re
23 
24 from english_support import *
25 from greek_support import *
26 
27 ## @class GreekSupport
28 # @brief Allows the creation of configuration files for Greek Sphinx speech recognition
29 #
30 # Also supports multilanguage words (English/Greek) by utilizing
31 # english_support.EnglishSupport
33 
34  ## Performs initializations
35  def __init__(self):
36 
37  # Initialize LanguageSupport
38  super(GreekEnglishSupport, self).__init__()
39 
40  # TODO: Split the rapp_sphinx4_java_libraries package into libraries and
41  # language models
42  # NOTE: This does not exist yet
43  #self._greek_dictionary = self._language_models_url + \
44  #"/englishPack/cmudict-en-us.dict"
45 
46 
47  ## Separates English from Greek words
48  #
49  # @param words [list::string] The set of words to be identified
50  # @param grammar [list::string] The Sphinx grammar parameter
51  # @param sentences [list::string] The Sphinx sentences parameter
52  #
53  # @return english_words [list::string] The set of English words
54  # @return english_grammar [list::string] The set of English grammar
55  # @return english_sentences [list::string] The set of English sentences
56  # @return greek_words [list::string] The set of Greek words
57  # @return greek_grammar [list::string] The set of Greek words
58  # @return greek_sentences [list::string] The set of Greek words
59  def _separateEngGrWords(self, words, grammar, sentences):
60 
61  english_words = []
62  english_grammar = []
63  english_sentences = []
64  greek_words = []
65  greek_grammar = []
66  greek_sentences = []
67 
68  for word in words:
69  if re.match('[a-zA-Z\-]', word):
70  RappUtilities.rapp_print( "English word: " + str(word) )
71  english_words.append( word )
72  else:
73  RappUtilities.rapp_print( "Greek word: " + str(word) )
74  greek_words.append( word )
75 
76  for word in grammar:
77  if re.match('[a-zA-Z\-]', word):
78  RappUtilities.rapp_print( "English grammar: " + str(word) )
79  english_grammar.append( word )
80  else:
81  RappUtilities.rapp_print( "Greek grammar: " + str(word) )
82  greek_grammar.append( word )
83 
84  for word in sentences:
85  if re.match('[a-zA-Z\-]', word):
86  RappUtilities.rapp_print( "English sentence: " + str(word) )
87  english_sentences.append( word )
88  else:
89  RappUtilities.rapp_print( "Greek sentence: " + str(word) )
90  greek_sentences.append( word )
91 
92  return [ english_words, english_grammar, english_sentences, greek_words, \
93  greek_grammar, greek_sentences ]
94 
95  ## Computes the Limited Greek/English Configuration
96  #
97  # @param words [list::string] The set of words to be identified
98  # @param grammar [list::string] The Sphinx grammar parameter
99  # @param sentences [list::string] The Sphinx sentences parameter
100  #
101  # @return limited_sphinx_configuration [dictionary] The Limited Greek/English configuration
102  # @return englified_to_greek_dict [dictionary] A dictionary to transform the englified greek words to actual greek words
103  def getLimitedVocebularyConfiguration(self, words, grammar, sentences):
104 
105  # Separate English from Greek words
106  [ english_words, english_grammar, english_sentences, \
107  greek_words, greek_grammar, greek_sentences ] = \
108  self._separateEngGrWords( words, grammar, sentences )
109 
110  # Get phonemes for Greek words and dictionary for Englified->Greek mapping
111  [englified_phonems_dict, englified_to_greek_dict] = \
112  self._transformWords( greek_words )
113 
114  # Append english words to Englified->Greek mapping dictionary
115  for word in english_words:
116  englified_to_greek_dict.update( {word: word} )
117 
118  # Get phonemes for English words
119  english_phonem_dict = self._english_support.getWordPhonemes( english_words )
120 
121  # Englify Greek grammar and sentences
122  englified_grammar = self._englify_words(greek_grammar)
123  englified_sentences = self._englify_words(greek_sentences)
124 
125 
126  # Join English and Greek processed files
127  final_phoneme_dict = english_phonem_dict
128  final_phoneme_dict.update(englified_phonems_dict)
129  final_sentences = englified_sentences + english_sentences
130  final_grammar = english_grammar + englified_grammar
131 
132  try:
133  limited_sphinx_configuration = \
134  self._vocabulary.createConfigurationFiles( \
135  final_phoneme_dict, final_grammar, final_sentences \
136  )
137  except RappError as e:
138  raise RappError(e.value)
139 
140  return [limited_sphinx_configuration, englified_to_greek_dict]
def getLimitedVocebularyConfiguration
Computes the Limited Greek/English Configuration.
Allows the creation of configuration files for Greek Sphinx speech recognition.
Allows the creation of configuration files for English Sphinx speech recognition. ...
def _transformWords
Transforms the Greek words into phonemes for the Sphinx configuration.