Exemplo n.º 1
0
    def addAnswer(self, text):
        data = { "author": lsrh.getAuthorURL(self.author_id),
                 "prompt": lsrh.getPromptURL(self.prompt_id),
                 "text": text }

        r = self.session.post(lsrh.getAnswerURL(), data=json.dumps(data))
        lsrh.checkStatus(r, (201,), "Failed to upload answer.")
Exemplo n.º 2
0
    def addAnswerSet(self, trained_models = [], tags = []):
        data = { "prompt": lsrh.getPromptURL(self.prompt_id),
                 "trained_models": [lsrh.getTrainedModelURL(t) for t in trained_models] if len(trained_models) > 0 else [], 
                 "tags": tags }

        r = self.session.post(lsrh.getAnswerSetURL(), data=json.dumps(data))
        lsrh.checkStatus(r, (201,), "Failed to create answer set.")

        self.answer_set_id = lsrh.getIdFromResponse(r)
Exemplo n.º 3
0
    def newCorpus(self, prompt_id):
        description = raw_input("Description of corpus? ")
        data = {"prompt": lsrh.getPromptURL(prompt_id), "description": description}
        r = self.session.post(lsrh.getCorpusURL(), data=json.dumps(data), headers=self.headers)
        lsrh.checkStatus(r, (201,), "Prompt id not found on remote server, or description was illegal.")

        self.prompt_id = prompt_id
        self.corpus_id = lsrh.getIdFromResponse(r)

        print 'New corpus with id {} for prompt {}'.format(self.corpus_id, self.prompt_id)
Exemplo n.º 4
0
    def uploadAnswerSet(self, fname):
        if self.answer_set_id == None:
            self.addAnswerSet()

        r = self.uploadToS3('answerset', fname)

        soup = bsoup(r.content)
        key = soup.find('key').get_text()

        data2 = {'prompt': lsrh.getPromptURL(self.prompt_id), 'answer_set': lsrh.getAnswerSetURL(self.answer_set_id), 's3_key': key, 'content_type': 'text/csv'}

        # create and start upload task
        r2 = self.session.post(lsrh.getAnswerSetUploadTaskURL(), data=json.dumps(data2))
        answerUploadTaskData = r2.json()
        r3 = self.session.post(answerUploadTaskData["process"])

        lsrh.checkStatus(r3, (200, 202), "Queueing of answerset upload task failed.")

        r4 = self.waitForTask(answerUploadTaskData["url"], "answer set upload task")
        return r4.json()["answer_set"]
Exemplo n.º 5
0
    def getPrompt(self, prompt_id):
        r = self.session.get(lsrh.getPromptURL(prompt_id))
        lsrh.checkStatus(r, (201,), "Prompt id not found on remote server")

        return r