當前位置: 首頁>>代碼示例>>Python>>正文


Python Wit.get_intents方法代碼示例

本文整理匯總了Python中wit.Wit.get_intents方法的典型用法代碼示例。如果您正苦於以下問題:Python Wit.get_intents方法的具體用法?Python Wit.get_intents怎麽用?Python Wit.get_intents使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在wit.Wit的用法示例。


在下文中一共展示了Wit.get_intents方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from wit import Wit [as 別名]
# 或者: from wit.Wit import get_intents [as 別名]
class Intents:
    def __init__(self, lisa=None):
        self.lisa = lisa
        self.configuration = configuration
        mongo = MongoClient(host=self.configuration['database']['server'],
                            port=self.configuration['database']['port'])
        self.database = mongo.lisa
        self.wit = Wit(self.configuration['wit_token'])

    def list(self, jsonInput):
        intentstr = []
        listintents = self.wit.get_intents()
        for oIntent in oIntents.objects(enabled=True):
            for witintent in listintents:
                print witintent
                if witintent["name"] == oIntent.name and 'metadata' in witintent:
                    if witintent['metadata']:
                        metadata = json.loads(witintent['metadata'])
                        intentstr.append(metadata['tts'])

        return {"plugin": "Intents",
                "method": "list",
                "body": unicode(_('I can %(intentslist)s' % {'intentslist': ', '.join(intentstr)}))
        }
開發者ID:Acruxx,項目名稱:LISA,代碼行數:26,代碼來源:intents.py

示例2: LisaResource

# 需要導入模塊: from wit import Wit [as 別名]
# 或者: from wit.Wit import get_intents [as 別名]

#.........這裏部分代碼省略.........
            log.err()
            return self.create_response(request, { 'status' : 'failure' }, HttpNotModified)
        f = open(temp,"rb")
        combined_sound.append(f.read())
        f.close()
        os.remove(temp)
        self.log_throttled_access(request)
        return HttpResponse(''.join(combined_sound), content_type="audio/mpeg", mimetype="audio/mpeg")

    def engine_reload(self, request, **kwargs):
        self.method_check(request, allowed=['get'])
        self.is_authenticated(request)
        self.throttle_check(request)

        from tastypie.http import HttpAccepted, HttpNotModified

        try:
            LisaFactorySingleton.get().LisaReload()
        except:
            log.err()
            return self.create_response(request, { 'status' : 'failure' }, HttpNotModified)
        self.log_throttled_access(request)
        return self.create_response(request, { 'status': 'success', 'log': "L.I.S.A Engine reloaded"}, HttpAccepted)

    def witintents(self, request, **kwargs):
        self.method_check(request, allowed=['get'])
        self.is_authenticated(request)
        self.throttle_check(request)
        self.wit = Wit(configuration['wit_token'])

        from tastypie.http import HttpAccepted, HttpNotModified

        try:
            intents = self.wit.get_intents()
        except:
            log.err()
            return self.create_response(request, { 'status' : 'failure' }, HttpNotModified)
        self.log_throttled_access(request)
        return self.create_response(request, { 'status': 'success', 'intents': intents}, HttpAccepted)

    def scheduler_reload(self, request, **kwargs):
        self.method_check(request, allowed=['get'])
        self.is_authenticated(request)
        self.throttle_check(request)

        from tastypie.http import HttpAccepted, HttpNotModified

        try:
            LisaFactorySingleton.get().SchedReload()
        except:
            log.err()
            return self.create_response(request, { 'status' : 'failure' }, HttpNotModified)
        self.log_throttled_access(request)
        return self.create_response(request, {'status': 'success', 'log': 'L.I.S.A Task Scheduler reloaded'},
                                    HttpAccepted)

    def configuration(self, request, **kwargs):
        self.method_check(request, allowed=['get'])
        self.is_authenticated(request)
        self.throttle_check(request)

        from tastypie.http import HttpAccepted, HttpNotModified

        self.log_throttled_access(request)
        copyconfiguration = configuration
        copyconfiguration['database'] = None
開發者ID:baiyishr,項目名稱:LISA,代碼行數:70,代碼來源:apilisa.py

示例3: LisaResource

# 需要導入模塊: from wit import Wit [as 別名]
# 或者: from wit.Wit import get_intents [as 別名]

#.........這裏部分代碼省略.........
                            temp_string = temp_string + part
                            if len(temp_string) > 80:
                                temp_array.append(temp_string)
                                temp_string = ""
                            #append final part
                        temp_array.append(temp_string)
                        combined_text.extend(temp_array)
                #download chunks and write them to the output file
            for idx, val in enumerate(combined_text):
                headers = {"Host":"translate.google.com",
                           "Referer":"http://translate.google.com/",
                           "User-Agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.63 Safari/537.36"}
                r = requests.get("http://translate.google.com/translate_tts?tl=%s&q=%s&total=%s&idx=%s" % (str(lang[0]), val, len(combined_text), idx),
                                 headers=headers)

                combined_sound.append(r.content)
        except:
            log.err()
            return self.create_response(request, { 'status' : 'failure' }, HttpNotModified)
        self.log_throttled_access(request)
        return HttpResponse(''.join(combined_sound), content_type="audio/mpeg", mimetype="audio/mpeg")

    def tts_pico(self, request, **kwargs):
        import uuid
        self.method_check(request, allowed=['post', 'get'])
        self.is_authenticated(request)
        self.throttle_check(request)
        message = request.POST.get("message")
        lang = request.POST.getlist("lang")


        from tastypie.http import HttpAccepted, HttpNotModified
        from django.http import HttpResponse
        from subprocess import call, Popen
        combined_sound = []
        temp = dir_path + "/tmp/" + str(uuid.uuid4()) + ".wav"
        language = str(lang[0])+'-'+str(lang[0]).upper()
        command = ['pico2wave', '-w', temp, '-l', language, '--', message]
        try:
            call(command)
            #combined_sound.append(content)
        except OSError:
            log.err()
            return self.create_response(request, { 'status' : 'failure' }, HttpNotModified)
        f = open(temp,"rb")
        combined_sound.append(f.read())
        f.close()
        os.remove(temp)
        self.log_throttled_access(request)
        return HttpResponse(''.join(combined_sound), content_type="audio/mpeg", mimetype="audio/mpeg")

    def engine_reload(self, request, **kwargs):
        self.method_check(request, allowed=['get'])
        self.is_authenticated(request)
        self.throttle_check(request)

        from tastypie.http import HttpAccepted, HttpNotModified

        try:
            ClientFactory.LisaReload()
        except:
            log.err()
            return self.create_response(request, { 'status' : 'failure' }, HttpNotModified)
        self.log_throttled_access(request)
        return self.create_response(request, { 'status': 'success', 'log': "Demonstrator Engine reloaded"}, HttpAccepted)

    def intents(self, request, **kwargs):
        self.method_check(request, allowed=['get'])
        self.is_authenticated(request)
        self.throttle_check(request)
        self.wit = Wit(self.configuration['wit_token'])

        from tastypie.http import HttpAccepted, HttpNotModified

        try:
            intents = self.wit.get_intents()
        except:
            log.err()
            return self.create_response(request, { 'status' : 'failure' }, HttpNotModified)
        self.log_throttled_access(request)
        return self.create_response(request, { 'status': 'success', 'intents': intents}, HttpAccepted)

    def scheduler_reload(self, request, **kwargs):
        self.method_check(request, allowed=['get'])
        self.is_authenticated(request)
        self.throttle_check(request)

        from tastypie.http import HttpAccepted, HttpNotModified

        try:
            ClientFactory.SchedReload()
        except:
            log.err()
            return self.create_response(request, { 'status' : 'failure' }, HttpNotModified)
        self.log_throttled_access(request)
        return self.create_response(request, { 'status': 'success', 'log': "Demonstrator Task Scheduler reloaded"},
                                    HttpAccepted)

    def get_object_list(self, request):
        return [Lisa()]
開發者ID:gdumee,項目名稱:LISA,代碼行數:104,代碼來源:api.py


注:本文中的wit.Wit.get_intents方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。