示例#1
0
    def add_function(self, annotation_status_list):
        """
        make type of fist sentenece to be function on single and disagree documents
        :param st_dic:
        :return:
        """
        single_add_first = 0
        disagree_add_first = 0
        for status in annotation_status_list:
            if status["sentence_index"] == 0 and status["vote_count"] == 1:
                single_add_first = single_add_first + 1
                sentence_text_annotation = DocumentSentenceTextAnnotation(
                    status["doc_id"], status["sentence_index"], 1,
                    "AnnotationRobot")
                sentence_text_annotation.find_or_create(self.session)
            if status["sentence_index"] == 0 and status[
                    "vote_count"] > 1 and status["agree_rate"] < 0.66:
                disagree_add_first = disagree_add_first + 1
                sentence_text_annotation = DocumentSentenceTextAnnotation(
                    status["doc_id"], status["sentence_index"], 1,
                    "AnnotationRobot")
                sentence_text_annotation.find_or_create(self.session)

        print("single first sentence to be function :", single_add_first)
        print("disagree first sentence to be function :", disagree_add_first)
示例#2
0
    def add_directive(self, annotation_status_list):
        """
        match keywords to make type of sentence to be directive on single and disagree documents
        :param st_dic:
        :return:
        """
        single_add_directive = 0
        disagree_add_directive = 0
        for status in annotation_status_list:
            if status["sentence_index"] != 0 and status[
                    "vote_count"] == 1 and self.directive_match(
                        status["text"]) == True:
                single_add_directive = single_add_directive + 1
                sentence_text_annotation = DocumentSentenceTextAnnotation(
                    status["doc_id"], status["sentence_index"], 2,
                    "AnnotationRobot2")
                sentence_text_annotation.find_or_create(self.session)
            if status["sentence_index"] != 0 and status[
                    "vote_count"] > 1 and status[
                        "agree_rate"] < 0.66 and self.directive_match(
                            status["text"]) == True:
                disagree_add_directive = disagree_add_directive + 1
                sentence_text_annotation = DocumentSentenceTextAnnotation(
                    status["doc_id"], status["sentence_index"], 2,
                    "AnnotationRobot3")
                sentence_text_annotation.find_or_create(self.session)

        print("single sentences to be directive :", single_add_directive)
        print("disagree sentences to be directive :", disagree_add_directive)
示例#3
0
def save_sentence_annotation():
    session = EngineFactory.create_session()
    if not request.json:
        return "fail"
    j = request.json
    for each in j:
        if 'doc_id' not in each and "sentence_index" not in each and "type" not in each and "username" not in each:
            return "fail"
        doc_id = each["doc_id"]
        sentence_index = each["sentence_index"]
        type = each["type"]
        username = each["username"]
        sentence_text_annotation = DocumentSentenceTextAnnotation(
            doc_id, sentence_index, type, username)
        sentence_text_annotation.find_or_create(session, autocommit=False)
        if sentence_text_annotation.type != type:
            sentence_text_annotation.type = type
    session.commit()
    return "save successful"