Example #1
0
def test_complex1():

    text = "A Tunisian court has jailed a Nigerian student for two years for helping young militants join an armed Islamic group in Lebanon, his lawyer said Wednesday."

    parse = """( (S (S
    (NP (DT A) (NNP Tunisian) (NN court))
    (VP (AUXZ has)
    (VP (VBN jailed)
    (NP (DT a) (JJ Nigerian) (NN student))
    (PP (IN for)
    (NP (CD two) (NNS years)))
    (PP (IN for) (S
    (VP (VBG helping) (S
    (NP (JJ young) (NNS militants))
    (VP (VB join)
    (NP (NP (DT an) (JJ armed) (JJ Islamic) (NN group))f
    (PP (IN in)
    (NP (NNP Lebanon)))))))))))) (, ,)
    (NP (PRP$ his) (NN lawyer))
    (VP (VBD said)
    (NP (NNP Wednesday))) (. .)))"""


    parsed = utilities._format_parsed_str(parse)

    dict = {u'test123': {u'sents': {u'0': {u'content': text, u'parsed': parsed}},
                u'meta': {u'date': u'20010101'}}}
    return_dict = petrarch.do_coding(dict,None)
    print(return_dict)
    assert return_dict['test123']['sents']['0']['events'] == [('TUNJUD','NGAEDU','173')]
Example #2
0
def test_complex1():

    text = "A Tunisian court has jailed a Nigerian student for two years for helping young militants join an armed Islamic group in Lebanon, his lawyer said Wednesday."

    parse = """( (S (S
    (NP (DT A) (NNP Tunisian) (NN court))
    (VP (AUXZ has)
    (VP (VBN jailed)
    (NP (DT a) (JJ Nigerian) (NN student))
    (PP (IN for)
    (NP (CD two) (NNS years)))
    (PP (IN for) (S
    (VP (VBG helping) (S
    (NP (JJ young) (NNS militants))
    (VP (VB join)
    (NP (NP (DT an) (JJ armed) (JJ Islamic) (NN group))
    (PP (IN in)
    (NP (NNP Lebanon)))))))))))) (, ,)
    (NP (PRP$ his) (NN lawyer))
    (VP (VBD said)
    (NP (NNP Wednesday))) (. .)))"""


    parsed = utilities._format_parsed_str(parse)

    dict = {u'test123': {u'sents': {u'0': {u'content': text, u'parsed': parse}},
                u'meta': {u'date': u'20010101'}}}

    return_dict = petrarch.do_coding(dict,None)
    assert return_dict['test123']['sents']['0']['events'] == [['TUNJUD','NGAEDU','173']]
Example #3
0
    def post(self):
        args = self.reqparse.parse_args()
        event_dict = args['events']

        print(event_dict)
        event_dict_updated = petrarch.do_coding(event_dict, None)

        return event_dict_updated
Example #4
0
def test_simple2():
    text = "Germany arrested France"
    parse = "(ROOT (S (NP (NNP Germany)) (VP (VBD arrested) (NP (NNP France)))))"
    parsed = utilities._format_parsed_str(parse)

    dict = {u'test123': {u'sents': {u'0': {u'content': text, u'parsed': parsed}},
                u'meta': {u'date': u'20010101'}}}

    return_dict = petrarch.do_coding(dict,None)
    print(return_dict)
    assert return_dict['test123']['sents']['0']['events'] == [('DEU','FRA','173')]
Example #5
0
def test_simple2():
    text = "Germany arrested France"
    parse = "(ROOT (S (NP (NNP Germany)) (VP (VBD arrested) (NP (NNP France)))))"
    parsed = utilities._format_parsed_str(parse)

    dict = {u'test123': {u'sents': {u'0': {u'content': text, u'parsed': parse}},
                u'meta': {u'date': u'20010101'}}}

    return_dict = petrarch.do_coding(dict,None)
    print(return_dict)
    assert return_dict['test123']['sents']['0']['events'] == [['DEU','FRA','173']]
Example #6
0
    def get(self):
        args = self.reqparse.parse_args()
        text = args['text']
        text = text.encode('utf-8')
        storyid = args['id']
        date = args['date']

        out = send_to_ccnlp(text)
        event_dict = process_corenlp(out, date, storyid)
        event_updated = petrarch.do_coding(event_dict, None)

        return event_updated
Example #7
0
def test_actor_order():

    text = "US troops from Syria have just invaded Northern Iraq"

    parse = """(ROOT (S (NP (NP (NNP US) (NNS troops)) (PP (IN from) (NP (NNP Syria)))) (VP (VBP have) (ADVP (RB just)) (VP (VBN invaded) (NP (JJ Northern) (NNP Iraq))))))"""

    parsed = utilities._format_parsed_str(parse)

    dict = {u'test123': {u'sents': {u'0': {u'content': text, u'parsed': parse}},
                u'meta': {u'date': u'20150101'}}}

    return_dict = petrarch.do_coding(dict,None)
    assert return_dict['test123']['sents']['0']['events'] == [['USAMIL','IRQ','192']]
Example #8
0
def test_nested():

    # In PETRARCH 0.4.0 this event should only code "US claimed that ISIL."
    # Nested sentences are intentionally not coded, but this can be changed if needed.
    #       (this would be changed at the end of check_verbs where the index is reevaluated)
    
    
    text = "The US claimed that ISIL had attacked Iraq and taken the city of Mosul"

    parse = """(ROOT (S (NP (DT The) (NNP US)) (VP (VBD claimed) (SBAR (IN that) (S (NP (NNP ISIL)) (VP (VBD had) (VP (VP (VBN attacked) (NP (NNP Iraq))) (CC and) (VP (VBN taken) (NP (NP (DT the) (NN city)) (PP (IN of) (NP (NNP Mosul))))))))))))"""

    parsed = utilities._format_parsed_str(parse)

    dict = {u'test123': {u'sents': {u'0': {u'content': text, u'parsed': parse}},
                u'meta': {u'date': u'20150101'}}}

    return_dict = petrarch.do_coding(dict,None)
    assert return_dict['test123']['sents']['0']['events'] == [['USA','IMGMUSISI','112']]