Exemplo n.º 1
0
def test_clarification_comment():
    question = {
        "OwnerUserId":
        "1",
        "Comments": [{
            "Id": "1",
            "Text": "is this a question? some unrelated text.",
            "UserId": "2",
            "CreationDate": "2010-07-22T07:00:00.000",
        }, {
            "Id": "2",
            "Text": "yes, this is indeed a question!",
            "UserId": "1",
            "CreationDate": "2010-07-22T08:00:00.000",
        }, {
            "Id": "3",
            "Text": "another comment!",
            "UserId": "1",
            "CreationDate": "2010-07-22T08:01:00.000",
        }]
    }

    cq = ClarificationQuestion("is this a question ?",
                               parse_time("2010-07-22T07:00:00.000"),
                               entity_id="1")
    cc = annotator._clarification_comment(question, cq)

    assert cc.entity_id == "2"
    assert cc.text == 'yes , this is indeed a question !'
    assert cc.creation_date == parse_time("2010-07-22T08:00:00.000")
Exemplo n.º 2
0
def test_clarification():
    question = {
        "OwnerUserId":
        "1",
        "Comments": [{
            "Id": "1",
            "Text": "is this a question? some unrelated text.",
            "UserId": "2",
            "CreationDate": "2010-07-22T07:00:00.000",
        }, {
            "Id": "2",
            "Text": "yes this is my question",
            "UserId": "1",
            "CreationDate": "2010-07-22T08:00:00.000",
        }],
        "Edits":
        initial_edits + [{
            "Id": "4",
            "PostHistoryTypeId": "5",  # edit body
            "RevisionGUID": "guid3",
            "CreationDate": "2010-07-22T08:00:00.000",
            "UserId": "1",
            "Text": "question body, answer to question"
        }]
    }

    cq = ClarificationQuestion("is this a question ?",
                               parse_time("2010-07-22T07:00:00.000"),
                               entity_id="1")
    clarification_comment, clarification_edit = annotator.clarification(
        question, cq)
    assert clarification_comment.text == "yes this is my question"
    assert clarification_edit.diff.insert == " , answer to question"
Exemplo n.º 3
0
def test_clarification_edit():
    question = {
        "OwnerUserId":
        "1",
        "Comments": [{
            "Id": "1",
            "Text": "is this a question? some unrelated text.",
            "UserId": "2",
            "CreationDate": "2010-07-22T07:00:00.000",
        }],
        "Edits":
        initial_edits + [
            {
                "Id": "4",
                "PostHistoryTypeId": "4",  # title updated
                "RevisionGUID": "guid2",
                "CreationDate": "2010-07-22T08:00:00.000",
                "UserId": "1",
                "Text": "title updated"
            },
            {
                "Id": "5",
                "PostHistoryTypeId": "5",  # edit body
                "RevisionGUID": "guid3",
                "CreationDate": "2010-07-22T08:00:00.000",
                "UserId": "1",
                "Text": "question body, answer to question"
            },
            {
                "Id": "6",
                "PostHistoryTypeId": "5",  # edit body
                "RevisionGUID": "guid4",
                "CreationDate": "2010-07-22T09:00:00.000",
                "UserId": "1",
                "Text": "question body, answer to question, more information"
            }
        ]
    }

    cq = ClarificationQuestion("is this a question ?",
                               parse_time("2010-07-22T07:00:00.000"),
                               entity_id="1")
    ce = annotator._clarification_edit(question, cq)

    assert ce.entity_id == "5"
    assert ce.text == "question body , answer to question"
    assert ce.creation_date == parse_time("2010-07-22T08:00:00.000")
Exemplo n.º 4
0
def test_clarification_edit_initial_post():
    question = {
        "OwnerUserId":
        "1",
        "Comments": [{
            "Id": "1",
            "Text": "is this a question? some unrelated text.",
            "UserId": "2",
            "CreationDate": "2010-07-22T07:00:00.000",
        }],
        "Edits":
        initial_edits
    }

    cq = ClarificationQuestion("is this a question ?",
                               parse_time("2010-07-22T07:00:00.000"),
                               entity_id="1")
    ce = annotator._clarification_edit(question, cq)
    assert ce is None
Exemplo n.º 5
0
def test_clarification_comment_ignore_previous_comments():
    question = {
        "OwnerUserId":
        "1",
        "Comments": [{
            "Id": "1",
            "Text": "comment before question",
            "UserId": "1",
            "CreationDate": "2010-07-22T06:00:00.000",
        }, {
            "Id": "2",
            "Text": "is this a question? some unrelated text.",
            "UserId": "2",
            "CreationDate": "2010-07-22T07:00:00.000",
        }]
    }

    cq = ClarificationQuestion("is this a question ?",
                               parse_time("2010-07-22T07:00:00.000"),
                               entity_id="2")
    cc = annotator._clarification_comment(question, cq)

    assert cc is None
Exemplo n.º 6
0
def test_clarification_comment_not_present():
    question = {
        "OwnerUserId":
        "1",
        "Comments": [{
            "Id": "1",
            "Text": "is this a question? some unrelated text.",
            "UserId": "2",
            "CreationDate": "2010-07-22T07:00:00.000",
        }]
    }

    cq = ClarificationQuestion("is this a question ?",
                               parse_time("2010-07-22T07:00:00.000"),
                               entity_id="1")
    cc = annotator._clarification_comment(question, cq)

    assert cc is None

    question = {
        "OwnerUserId":
        "1",
        "Comments": [{
            "Id": "1",
            "Text": "is this a question? some unrelated text.",
            "UserId": "2",
            "CreationDate": "2010-07-22T07:00:00.000",
        }, {
            "Id": "2",
            "Text": "unrelated comment by unrelated user",
            "UserId": "3",
            "CreationDate": "2010-07-22T08:00:00.000",
        }]
    }

    cc = annotator._clarification_comment(question, cq)
    assert cc is None
Exemplo n.º 7
0
def test_clarifying_question():
    c1 = {
        "Id": "1",
        "Text": "is this a question? some unrelated text.",
        "UserId": "3",
        "CreationDate": "2010-07-22T07:00:00.000",
    }

    c2 = {
        "Id": "2",
        "Text": "is this is another question?",
        "UserId": "2",
        "CreationDate": "2010-07-22T08:00:00.000",
    }

    question = {
        "OwnerUserId": "1",
        # in wrong order, assert method sorts by timestamp
        "Comments": [c2, c1]
    }

    cq = annotator.clarification_question(question)
    assert cq.text == "is this a question ?"
    assert cq.creation_date == parse_time("2010-07-22T07:00:00.000")