Пример #1
0
This file contains useful functions used throughout the application.
'''
import re, math, chardet, bingtrans, enchant, itertools  #!@UnresolvedImport
import twitter_text  #!@UnresolvedImport
import AlchemyAPI  #!@UnresolvedImport
import numpy
from matplotlib.dates import date2num  #!@UnresolvedImport
from lxml import etree  #!@UnresolvedImport
from StringIO import StringIO
from nltk.stem.porter import PorterStemmer  #!@UnresolvedImport

###########################################
# GLOBALS                                #
###########################################
d = enchant.Dict("en_US")
bingtrans.set_app_id('5521E4A630094D968D49B39B6511A0A76CB025E1')
alchemyObj = AlchemyAPI.AlchemyAPI()
alchemyObj.setAPIKey("d7605e69dd3d2d7a032f11272d9b000e77d43545")
ignorewords = set(['rt', 'via', 'jan25', 'egypt', 'cairo', '25jan', "s", ":)", ":(", ":p", "25"\
                '(' , ')', '<', '>', '#', '@', '?', '!', '.', ',', '=', '|', \
                '&', ':', '+', '\'', '\'ve',"m", 're', '-', '"', '."', '...', '..', '--', '[', ']' ])


def strip_url(text):
    #return re.compile(r'(\w+:\/\/\S+)').sub('', text)
    #return re.compile(r"""((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|(([^\s()<>]+|(([^\s()<>]+)))*))+(?:(([^\s()<>]+|(([‌​^\s()<>]+)))*)|[^\s`!()[]{};:'".,<>?«»“”‘’]))""", re.DOTALL).sub('',text)
    urls = extract_urls(text)
    for url in urls:
        text = ' '.join(re.sub(url['url'], " ", text).split())
    return text
#!/usr/bin/python
# -*- coding: utf-8 -*-
#Author: SNXRaven (Jonathon Nickols)
# This requires that you have installed bingtrans module from: https://github.com/bahn/bingtrans
# This requires that you get your own api key from: http://www.bing.com/developers/
# rewritten/fixed by cytec

import bingtrans
from plugin import *
bing_api_key = APIKeyForAPI("bing")
bingtrans.set_app_id(bing_api_key)

res = {
	'command': {
		'en-US': u'Translate (?P<transword>[^^]+) from (?P<fromlang>[\w]+) to (?P<tolang>[\w]+)',
		'de-DE': u'(Übersetze|Übersetzer|Übersetzen|Translate) (?P<transword>[^^]+) von (?P<fromlang>[\w]+) (nach|in|zu) (?P<tolang>[\w]+)'
	},
	'answer': {
		'en-US': u'Here is your {0} translation for {1}:\n',
		'de-DE': u'Hier ist deine {0} Übersetzung für {1}:\n'
	},
	'languageCodes': {
		'en-US': {
			u'english': 'en',
			u'spanish': 'sp',
			u'french': 'fr',
			u'italian': 'it',
			u'finnish': 'fi',
			u'greek': 'el',
			u'arabic': 'ar',
			u'czech': 'cs',
Пример #3
0
#!/usr/bin/python
# -*- coding: utf-8 -*-
#Author: SNXRaven (Jonathon Nickols)
# This requires that you have installed bingtrans module from: https://github.com/bahn/bingtrans
# This requires that you get your own api key from: http://www.bing.com/developers/

import bingtrans
import re


from plugin import *
bing_api_key = APIKeyForAPI("bing")
bingtrans.set_app_id(e546c8d521f84d419a89dd48c3bf228d)
class bing_translate(Plugin):
    
    @register("de-DE", "(Übersetze [a-zA-Z0-9]+)")
    def snx_translate(self, speech, language):
        match = re.match(u"Translate (.*\D.*) from (english|spanish|french|italian|estonian|finnish|Greek|Arabic|czech|dutch|hebrew|russian|polish|portuguese|romanian|swedish|turkish|indonesian|hungarian) to (english|spanish|french|italian|estonian|finnish|greek|arabic|czech|dutch|hebrew|russian|polish|portuguese|romanian|swedish|turkish|indonesian|hungarian)", speech, re.IGNORECASE)
        text = match.group(1)
        lang1 = match.group(2).replace('english', 'en').replace('spanish', 'es').replace('french', 'fr').replace('italian','it').replace('estonian','et').replace('finnish','fi').replace('greek','el').replace('arabic','ar').replace('czech' ,'cs').replace('dutch' ,'nl').replace('hebrew' ,'he').replace('russian' ,'ru').replace('polish' ,'pl').replace('portuguese' ,'pt').replace('romanian' ,'ro').replace('swedish' ,'sv').replace('turkish' ,'tr').replace('indonesian' ,'id').replace('hungarian' ,'id')
        lang2 = match.group(3).replace('english', 'en').replace('spanish', 'es').replace('french', 'fr').replace('italian','it').replace('estonian','et').replace('finnish','fi').replace('greek','el').replace('arabic','ar').replace('czech' ,'cs').replace('dutch' ,'nl').replace('hebrew' ,'he').replace('russian' ,'ru').replace('polish' ,'pl').replace('portuguese' ,'pt').replace('romanian' ,'ro').replace('swedish' ,'sv').replace('turkish' ,'tr').replace('indonesian' ,'id').replace('hungarian' ,'id')
        self.say("Hier ist deine übersetzung:\n")
        self.say(bingtrans.translate(text, lang1, lang2), ' ')
        self.complete_request()

  
Пример #4
0
This file contains useful functions used throughout the application.
"""
import re, math, chardet, bingtrans, enchant, itertools  #!@UnresolvedImport
import twitter_text  #!@UnresolvedImport
import AlchemyAPI  #!@UnresolvedImport
import numpy
from matplotlib.dates import date2num  #!@UnresolvedImport
from lxml import etree  #!@UnresolvedImport
from StringIO import StringIO
from nltk.stem.porter import PorterStemmer  #!@UnresolvedImport

###########################################
# GLOBALS                                #
###########################################
d = enchant.Dict("en_US")
bingtrans.set_app_id("5521E4A630094D968D49B39B6511A0A76CB025E1")
alchemyObj = AlchemyAPI.AlchemyAPI()
alchemyObj.setAPIKey("d7605e69dd3d2d7a032f11272d9b000e77d43545")
ignorewords = set(
    [
        "rt",
        "via",
        "jan25",
        "egypt",
        "cairo",
        "25jan",
        "s",
        ":)",
        ":(",
        ":p",
        "25" "(",
Пример #5
0
 def testBingTranslate(self):   
     bingtrans.set_app_id('5521E4A630094D968D49B39B6511A0A76CB025E1')  # you can get your AppID at: http://www.bing.com/developers/
     result = bingtrans.translate("هذا هو الاختبار", 'ar', 'en') 
     self.assertEqual("This is a test", result)            
Пример #6
0
 def testBingTranslate(self):
     bingtrans.set_app_id(
         '5521E4A630094D968D49B39B6511A0A76CB025E1'
     )  # you can get your AppID at: http://www.bing.com/developers/
     result = bingtrans.translate("هذا هو الاختبار", 'ar', 'en')
     self.assertEqual("This is a test", result)
Пример #7
0
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import bingtrans
import polib
import os,sys

BING_KEY = 'AE4F2D9144A988C235A23DF694F664D9357B2916'
languages = {"arabic": "ar", "czech": "cs","danish": "da",
"german": "de","english": "en","estonian": "et","finnish": "fi",
"french": "fr","dutch": "nl","greek": "el","hebrew": "he","hungarian": "hu","indonesian": "id",
"italian": "it","japanese": "ja","korean": "ko","lithuanian":"lt",
"latvian": "lv","norwegian": "no","polish": "pl","portuguese": "pt","romanian": "ro","spanish": "es","russian": "ru",
"slovak": "sk","slovene": "sl","swedish": "sv","thai": "th","turkish": "tr","ukranian": "uk","vietnamese": "vi","simplified chinese": "zh-CHS"} #,"traditional chinese": "zh-CHT"}

#languages = {"simplified chinese": "zh-CHS"}
bingtrans.set_app_id(BING_KEY)

for lang in languages.values():
    lang = lang[:2]
    ##return false;os.system("pybabel init -D musicfilmcomedy -i locale/musicfilmcomedy.pot -d locale/ -l "+lang)

    #return False
    po = polib.pofile('locale/%s/LC_MESSAGES/musicfilmcomedy.po' % lang)
    for a in po.untranslated_entries():
        print a.msgid
        a.msgstr = bingtrans.translate(a.msgid, 'en', lang if lang != 'zh' else 'zh-CHS').replace("% s", "%s")
        print a.msgstr
    po.save('locale/%s/LC_MESSAGES/musicfilmcomedy.po' % lang)
    po.save_as_mofile('locale/%s/LC_MESSAGES/musicfilmcomedy.mo' % lang)