Beispiel #1
0
    def record_cognitive_test_performance(self, user, test, score):
        files = {}
        payload = {'user': user, 'test_instance': test, 'score': score}
        url = self.serviceUrl_['record_cognitive_test_performance']

        returnData = CloudInterface.callService(url, payload, files,
                                                self.auth_)
        return returnData
Beispiel #2
0
    def cognitive_test_chooser(self, user, testType):
        files = {}
        payload = {'user': user, 'test_type': testType}
        url = self.serviceUrl_['cognitive_test_chooser']

        returnData = CloudInterface.callService(url, payload, files,
                                                self.auth_)
        return returnData
Beispiel #3
0
    def ontology_superclasses_of(self, query):
        payload = {
            'query': query,
        }
        files = {}
        url = self.serviceUrl_['ontology_superclasses_of']

        returnData = CloudInterface.callService(url, payload, files, self.auth_)
        return returnData
Beispiel #4
0
    def face_detection(self, fileUri):
        fileName = self.__appendRandStr(fileUri)
        files = {'file_uri': (fileName, open(fileUri, 'rb'))}
        payload = {}
        url = self.serviceUrl_['face_detection']

        returnData = CloudInterface.callService(url, payload, files,
                                                self.auth_)
        return returnData
Beispiel #5
0
    def cognitive_test_chooser(self, user, testType):
        files = {}
        payload = {
            'user': user,
            'test_type': testType
        }
        url = self.serviceUrl_['cognitive_test_chooser']

        returnData = CloudInterface.callService(url, payload, files, self.auth_)
        return returnData
Beispiel #6
0
    def face_detection(self, fileUri):
        fileName = self.__appendRandStr(fileUri)
        files = {
            'file_uri': (fileName, open(fileUri, 'rb'))
        }
        payload = {}
        url = self.serviceUrl_['face_detection']

        returnData = CloudInterface.callService(url, payload, files, self.auth_)
        return returnData
Beispiel #7
0
    def detect_objects(self, fileUri, limit):
        fileName = self.__appendRandStr(fileUri)
        # -- Files to be added into to poset request
        files = {'file_uri': (fileName, open(fileUri, 'rb'))}
        payload = {'limit': int(limit)}
        url = self.serviceUrl_['detect_objects']

        returnData = CloudInterface.callService(url, payload, files,
                                                self.auth_)
        return returnData
Beispiel #8
0
    def ontology_superclasses_of(self, query):
        payload = {
            'query': query,
        }
        files = {}
        url = self.serviceUrl_['ontology_superclasses_of']

        returnData = CloudInterface.callService(url, payload, files,
                                                self.auth_)
        return returnData
Beispiel #9
0
    def set_noise_profile(self, fileUri, audio_file_type, user):
        fileName = self.__appendRandStr(fileUri)
        # -- Craft the data payload for the post request
        payload = {'user': user, 'audio_source': audio_file_type}
        # -- Files to be added into to poset request
        files = {'file_uri': (fileName, open(fileUri, 'rb'))}
        url = self.serviceUrl_['set_noise_profile']

        returnData = CloudInterface.callService(url, payload, files,
                                                self.auth_)
        return returnData
Beispiel #10
0
    def record_cognitive_test_performance(self, user, test, score):
        files = {}
        payload = {
            'user': user,
            'test_instance': test,
            'score': score
        }
        url = self.serviceUrl_['record_cognitive_test_performance']

        returnData = CloudInterface.callService(url, payload, files, self.auth_)
        return returnData
Beispiel #11
0
    def detect_objects(self, fileUri, limit):
        fileName = self.__appendRandStr(fileUri)
        # -- Files to be added into to poset request
        files = {
            'file_uri': (fileName, open(fileUri, 'rb'))
        }
        payload = {
            'limit': int(limit)
        }
        url = self.serviceUrl_['detect_objects']

        returnData = CloudInterface.callService(url, payload, files, self.auth_)
        return returnData
Beispiel #12
0
    def available_services(self):

        ##
        #   There seems to be an error with Hop-server on empty payload post
        #   requests. The use of the dummyVar into the payload field resolves
        #   the bug.
        #   TODO Report this bug to HOP developers/maintainers
        ##
        payload = {'dummyVar': ''}
        files = {}
        url = self.serviceUrl_['available_services']

        returnData = CloudInterface.callService(url, payload, files,
                                                self.auth_)
        return returnData
Beispiel #13
0
    def ontology_is_subsuperclass_of(self, parent_class, child_class, recursive):
        rec = False
        if recursive != None:
            rec = recursive

        payload = {
            'parent_class': parent_class,
            'child_class': child_class,
            'recursive': rec
        }
        files = {}
        url = self.serviceUrl_['ontology_is_subsuperclass_of']

        returnData = CloudInterface.callService(url, payload, files, self.auth_)
        return returnData
Beispiel #14
0
    def set_noise_profile(self, fileUri, audio_file_type, user):
        fileName = self.__appendRandStr(fileUri)
        # -- Craft the data payload for the post request
        payload = {
            'user': user,
            'audio_source': audio_file_type
        }
        # -- Files to be added into to poset request
        files = {
            'file_uri': (fileName, open(fileUri, 'rb'))
        }
        url = self.serviceUrl_['set_noise_profile']

        returnData = CloudInterface.callService(url, payload, files, self.auth_)
        return returnData
Beispiel #15
0
    def available_services(self):

        ##
        #   There seems to be an error with Hop-server on empty payload post
        #   requests. The use of the dummyVar into the payload field resolves
        #   the bug.
        #   TODO Report this bug to HOP developers/maintainers
        ##
        payload = {
            'dummyVar': ''
        }
        files = {}
        url = self.serviceUrl_['available_services']

        returnData = CloudInterface.callService(url, payload, files, self.auth_)
        return returnData
Beispiel #16
0
    def ontology_is_subsuperclass_of(self, parent_class, child_class,
                                     recursive):
        rec = False
        if recursive != None:
            rec = recursive

        payload = {
            'parent_class': parent_class,
            'child_class': child_class,
            'recursive': rec
        }
        files = {}
        url = self.serviceUrl_['ontology_is_subsuperclass_of']

        returnData = CloudInterface.callService(url, payload, files,
                                                self.auth_)
        return returnData
Beispiel #17
0
    def speech_detection_google(self, fileUri, audio_source, user, language):

        # -- Craft the data payload for the post request
        payload = {
            'audio_source': audio_source,
            'user': user,
            'language': language
        }

        fileName = self.__appendRandStr(fileUri)
        # -- Files to be added into to post request
        files = {'file_uri': (fileName, open(fileUri, 'rb'))}
        url = self.serviceUrl_['speech_detection_google']

        returnData = CloudInterface.callService(url, payload, files,
                                                self.auth_)
        return returnData
Beispiel #18
0
    def speech_detection_google(self, fileUri, audio_source, user, language):

        # -- Craft the data payload for the post request
        payload = {
            'audio_source': audio_source,
            'user': user,
            'language': language
        }

        fileName = self.__appendRandStr(fileUri)
        # -- Files to be added into to post request
        files = {
            'file_uri': (fileName, open(fileUri, 'rb'))
        }
        url = self.serviceUrl_['speech_detection_google']

        returnData = CloudInterface.callService(url, payload, files, self.auth_)
        return returnData
Beispiel #19
0
    def text_to_speech(self, text, language, dest):
        files = {}
        payload = {
            'text': text,
            'language': language
        }
        url = self.serviceUrl_['text_to_speech']

        response = CloudInterface.callService(url, payload, files, self.auth_)
        returnData = {}
        ## Parse response error field.
        if response['error']:
            returnData['error'] = response['error']
            return returnData
        else:
            try:
                ## Decode base64 encoded payload
                audioRawData = base64.b64decode(response['payload'])
            except Exception as e:
                returnData['error'] = 'Failed to base64.decode payload data'
                print e
                return returnData
            finally:
                pass
        returnData['error'] = ''
        ## Parse dest parameter.
        if not dest:
            returnData['audioData'] = audioRawData
            returnData['basename'] = response['basename']
            #returnData['mime'] = magic.from_buffer(returnData['audioData'],
            #                                       mime=True)
        else:
            try:
                ## Write audio data to given destination file path.
                with open(dest, 'wb') as f1:
                    f1.write(audioRawData)
            except Exception as e:
                returnData['error'] = \
                    'Failed to write data at destination file [%s]' % dest
            finally:
                pass
        return returnData
Beispiel #20
0
    def speech_detection_sphinx4(self, language, audio_source, words, \
                                 sentences, grammar, fileUri, user):

        # -- Craft the data payload for the post request
        payload = {
            'language': language,
            'audio_source': audio_source,
            'words': json.dumps(words),
            'sentences': json.dumps(sentences),
            'grammar': json.dumps(grammar),
            'user': user
        }

        fileName = self.__appendRandStr(fileUri)
        # -- Files to be added into to post request
        files = {'file_uri': (fileName, open(fileUri, 'rb'))}
        url = self.serviceUrl_['speech_detection_sphinx4']

        returnData = CloudInterface.callService(url, payload, files,
                                                self.auth_)
        return returnData
Beispiel #21
0
    def speech_detection_sphinx4(self, language, audio_source, words, \
                                 sentences, grammar, fileUri, user):

        # -- Craft the data payload for the post request
        payload = {
            'language':language,
            'audio_source':audio_source,
            'words':json.dumps(words),
            'sentences':json.dumps(sentences),
            'grammar':json.dumps(grammar),
            'user': user
        }

        fileName = self.__appendRandStr(fileUri)
        # -- Files to be added into to post request
        files = {
            'file_uri': (fileName, open(fileUri, 'rb'))
        }
        url = self.serviceUrl_['speech_detection_sphinx4']

        returnData = CloudInterface.callService(url, payload, files, self.auth_)
        return returnData
Beispiel #22
0
    def text_to_speech(self, text, language, dest):
        files = {}
        payload = {'text': text, 'language': language}
        url = self.serviceUrl_['text_to_speech']

        response = CloudInterface.callService(url, payload, files, self.auth_)
        returnData = {}
        ## Parse response error field.
        if response['error']:
            returnData['error'] = response['error']
            return returnData
        else:
            try:
                ## Decode base64 encoded payload
                audioRawData = base64.b64decode(response['payload'])
            except Exception as e:
                returnData['error'] = 'Failed to base64.decode payload data'
                print e
                return returnData
            finally:
                pass
        returnData['error'] = ''
        ## Parse dest parameter.
        if not dest:
            returnData['audioData'] = audioRawData
            returnData['basename'] = response['basename']
            #returnData['mime'] = magic.from_buffer(returnData['audioData'],
            #                                       mime=True)
        else:
            try:
                ## Write audio data to given destination file path.
                with open(dest, 'wb') as f1:
                    f1.write(audioRawData)
            except Exception as e:
                returnData['error'] = \
                    'Failed to write data at destination file [%s]' % dest
            finally:
                pass
        return returnData