示例#1
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)
示例#2
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)
 def test_get_annotation_by_index(self):
     session = EngineFactory.create_session()
     annotation = DocumentSentenceTextAnnotation.get_annotation_count_by_index(
         session, 1, 1)
     expected = -1
     print annotation
     self.assertEqual(expected, annotation)
    def create_or_update_sentence(self, sentence_id, sentence_text,
                                  sentence_type_code):
        graph = self.get_graph_instance()
        sentence_node = self.find_sentence_node_by_sentence_id(sentence_id)
        property_dict = {
            "sentence_id":
            sentence_id,
            "sentence_text":
            sentence_text,
            "sentence_type_code":
            sentence_type_code,
            "sentence_type_string":
            DocumentSentenceTextAnnotation.get_type_string(sentence_type_code)
        }
        if sentence_node == None:
            builder = NodeBuilder()

            builder = builder.add_entity_label().add_sentence_label(
            ).add_property(**property_dict)

            node = builder.build()
            graph.create(node)
        else:
            for k, v in property_dict.items():
                sentence_node[k] = v
            graph.push(sentence_node)
示例#5
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"
示例#6
0
def get_annotation_by_index():
    if not request.json:
        return "fail"
    j = request.json
    if 'doc_id' not in j and "sentence_id" not in j:
        return "fail"
    doc_id = j["doc_id"]
    sentence_id = j["sentence_id"]
    sentence_annotation = DocumentSentenceTextAnnotation.get_annotation_by_index(
        api_entity_session, doc_id, sentence_id)
    if sentence_annotation:
        return jsonify({"annotation_type": sentence_annotation})
    else:
        return jsonify({"annotation_type": -1})