Пример #1
0
 def newAuthor(self):
     username = raw_input("Author username? ")
     email = raw_input("Author email? ")
     data = {"designator": username, "email": email}
     r = self.session.post(lsrh.getAuthorURL(), data=json.dumps(data))
     self.author_id = lsrh.getIdFromResponse(r)
     print 'Set author to', self.author_id
Пример #2
0
 def setAuthor(self, author_id):
     r = self.session.get(lsrh.getAuthorURL(author_id), headers=self.headers)
     if r.status_code != 200: # if failure
         print 'Author id not found on remote server.'
         self.newAuthor()
     else:
         self.author_id = lsrh.getIdFromResponse(r)
         print 'Set author to', self.author_id
Пример #3
0
    def addTrainingScore(self, essay, scoreName='domain1_score'):
        if essay.essay_id not in self.trainingAnswerMap:
            raise LookupError("Essay hasn't been added to training answers yet.")
            return

        data = { "training_answer": lsrh.getTrainingAnswerURL(self.trainingAnswerMap[essay.essay_id]),
                 "label": str(essay.getScore(scoreName)) }
        r = self.session.post(lsrh.getHumanScoreURL(), data=json.dumps(data), headers=self.headers)
        self.trainingScoresMap[essay.essay_id] = lsrh.getIdFromResponse(r)
Пример #4
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)
Пример #5
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)
Пример #6
0
 def addTrainingAnswer(self, essay):
     data = {"corpus": lsrh.getCorpusURL(self.corpus_id), "text": essay.getText()}
     r = self.session.post(lsrh.getTrainingAnswerURL(), data=json.dumps(data))
     self.trainingAnswerMap[essay.essay_id] = lsrh.getIdFromResponse(r)