def demo_one_sentence(): # 文章 passage = EssayPassage() passage.passage = 'I am a students.' passage.title = 'title' passage.score = 5 passage.id = '1' passage.reviewerId = 3 passage.content = 'I am a students.' # 处理文章 essayprepare.processPassage(passage) extractor = FeatherExtractor() lf = extractor.extractLangFeather(passage) passage.lf = lf cf = extractor.extractContentFeather(passage) sf = extractor.extractStructureFeather(passage) print 'OK'
def do_task(task): newpassage = EssayPassage() newpassage.passage = task['input']['content'] newpassage.orderId = task['id'] newpassage.score = 0 newpassage.processStatus = 0 try: essayprepare.processPassage(newpassage, fn_prepare_progress) fe = extractor.FeatherExtractor() lf = fe.extractLangFeather(newpassage) newpassage.lf = lf cf = fe.extractContentFeather(newpassage) newpassage.cf = cf sf = fe.extractStructureFeather(newpassage) newpassage.sf = sf newpassage.score = rater.rate_by_params(newpassage)[0] except: task['progress'] = -2 task['status'] = 'TUTERR' task['output'] = "" task['simple_output'] = "" task['detail_output'] = "" commit_task(task) return # 生成最终结果 output = {} passage = {} passage['score'] = newpassage.score passage['token_count'] = lf.tokenCount passage['word_count'] = lf.wordCount passage['word_type_count'] = lf.wordTypeCount passage['word_lemma_count'] = lf.wordLemmaCount passage['word_stem_count'] = lf.wordStemCount passage['average_word_length'] = lf.wordLengthAverage passage['average_sentence_length'] = lf.sentenceLengthAverage passage['overly_use_word_count'] = lf.overlyUseWordCount passage['paragraph_count'] = len(newpassage.paragraphs) passage['sentence_count'] = newpassage.sentenceCount passage['sentences'] = [] for para in newpassage.paragraphs: for sent in para.sentences: sentence = {} sentence['no'] = sent.sentenceNo sentence['para_no'] = para.paragraphNo sentence['original'] = sent.sentence sentence['score'] = 0 spell_errors = [] fs = [] for token in sent.tokens: if token.isSpellError: fs.append('<ESP>' + token.token + '</ESP>') spell_error = {} spell_error['token'] = token.token spell_error['lemma'] = token.lemma spell_error['suggest'] = token.candidates spell_error['start_at'] = token.startAt spell_error['end_at'] = token.endAt spell_errors.append(spell_error) else: fs.append(token.token) sentence['spell_errors'] = spell_errors sentence['marked'] = ' '.join(fs) sentence['lt_result'] = sent.ltCheckResults sentence['lg_result'] = sent.lgCheckResults sentence['links'] = [] passage['sentences'].append(sentence) output['passage'] = passage task['progress'] = 100 task['status'] = 'DONE' task['output'] = json.dumps(output) task['simple_output'] = json.dumps(output) task['detail_output'] = json.dumps(generate_detail_output(newpassage)) commit_task(task)