From ed75ff1b6dfbbedf867e8d7ef7fa0c4c1c455ad4 Mon Sep 17 00:00:00 2001 From: John Beieler Date: Thu, 29 Oct 2015 13:24:57 -0400 Subject: [PATCH 1/7] Update name to petrarch2. --- {petrarch => petrarch2}/.travis.yml | 0 {petrarch => petrarch2}/PETRARCH.log | 0 {petrarch => petrarch2}/PETRglobals.py | 0 {petrarch => petrarch2}/PETRreader.py | 0 {petrarch => petrarch2}/PETRtree.py | 0 {petrarch => petrarch2}/PETRwriter.py | 0 {petrarch => petrarch2}/__init__.py | 0 .../data/config/PETR_config.ini | 0 {petrarch => petrarch2}/data/config/batch.rng | 0 .../data/config/petrarch.properties | 0 .../data/config/validation.rng | 0 .../data/dictionaries/CAMEO.2.0.txt | 0 .../data/dictionaries/CAMEO.2.0_unsorted.txt | 0 .../CAMEO.verbpatterns.150430.txt | 0 .../dictionaries/PETR.Validate.actors.txt | 0 .../dictionaries/PETR.Validate.agents.txt | 0 .../dictionaries/PETR.Validate.discards.txt | 0 .../data/dictionaries/PETR.Validate.verbs.txt | 0 .../data/dictionaries/PETRARCH.log | 0 .../dictionaries/Phoenix.Countries.actors.txt | 0 .../Phoenix.International.actors.txt | 0 .../data/dictionaries/Phoenix.IssueCoding.txt | 0 .../Phoenix.MilNonState.actors.txt | 0 .../data/dictionaries/Phoenix.agents.txt | 0 .../data/dictionaries/Phoenix.discards.txt | 0 .../dictionaries/Phoenix.prepositions.txt | 0 .../data/dictionaries/newdict.txt | 0 .../data/dictionaries/testfile.txt | 0 .../data/text/GigaWord.sample.PETR.xml | 0 .../data/text/PETR.UnitTest.records.xml | 0 .../data/text/single_test.xml | 0 .../petrarch.py => petrarch2/petrarch2.py | 0 {petrarch => petrarch2}/test.py | 0 .../tests/test_petrarch.py | 0 .../tex_outputs/.gitignore | 0 {petrarch => petrarch2}/tree_to_tex.py | 0 {petrarch => petrarch2}/utilities.py | 0 requirements.txt | 13 ------------ setup.py | 20 ++++++++----------- 39 files changed, 8 insertions(+), 25 deletions(-) rename {petrarch => petrarch2}/.travis.yml (100%) rename {petrarch => petrarch2}/PETRARCH.log (100%) rename {petrarch => petrarch2}/PETRglobals.py (100%) rename {petrarch => petrarch2}/PETRreader.py (100%) rename {petrarch => petrarch2}/PETRtree.py (100%) rename {petrarch => petrarch2}/PETRwriter.py (100%) rename {petrarch => petrarch2}/__init__.py (100%) rename {petrarch => petrarch2}/data/config/PETR_config.ini (100%) rename {petrarch => petrarch2}/data/config/batch.rng (100%) rename {petrarch => petrarch2}/data/config/petrarch.properties (100%) rename {petrarch => petrarch2}/data/config/validation.rng (100%) rename {petrarch => petrarch2}/data/dictionaries/CAMEO.2.0.txt (100%) rename {petrarch => petrarch2}/data/dictionaries/CAMEO.2.0_unsorted.txt (100%) rename {petrarch => petrarch2}/data/dictionaries/CAMEO.verbpatterns.150430.txt (100%) rename {petrarch => petrarch2}/data/dictionaries/PETR.Validate.actors.txt (100%) rename {petrarch => petrarch2}/data/dictionaries/PETR.Validate.agents.txt (100%) rename {petrarch => petrarch2}/data/dictionaries/PETR.Validate.discards.txt (100%) rename {petrarch => petrarch2}/data/dictionaries/PETR.Validate.verbs.txt (100%) rename {petrarch => petrarch2}/data/dictionaries/PETRARCH.log (100%) rename {petrarch => petrarch2}/data/dictionaries/Phoenix.Countries.actors.txt (100%) rename {petrarch => petrarch2}/data/dictionaries/Phoenix.International.actors.txt (100%) rename {petrarch => petrarch2}/data/dictionaries/Phoenix.IssueCoding.txt (100%) rename {petrarch => petrarch2}/data/dictionaries/Phoenix.MilNonState.actors.txt (100%) rename {petrarch => petrarch2}/data/dictionaries/Phoenix.agents.txt (100%) rename {petrarch => petrarch2}/data/dictionaries/Phoenix.discards.txt (100%) rename {petrarch => petrarch2}/data/dictionaries/Phoenix.prepositions.txt (100%) rename {petrarch => petrarch2}/data/dictionaries/newdict.txt (100%) rename {petrarch => petrarch2}/data/dictionaries/testfile.txt (100%) rename {petrarch => petrarch2}/data/text/GigaWord.sample.PETR.xml (100%) rename {petrarch => petrarch2}/data/text/PETR.UnitTest.records.xml (100%) rename {petrarch => petrarch2}/data/text/single_test.xml (100%) rename petrarch/petrarch.py => petrarch2/petrarch2.py (100%) rename {petrarch => petrarch2}/test.py (100%) rename {petrarch => petrarch2}/tests/test_petrarch.py (100%) rename {petrarch => petrarch2}/tex_outputs/.gitignore (100%) rename {petrarch => petrarch2}/tree_to_tex.py (100%) rename {petrarch => petrarch2}/utilities.py (100%) delete mode 100644 requirements.txt diff --git a/petrarch/.travis.yml b/petrarch2/.travis.yml similarity index 100% rename from petrarch/.travis.yml rename to petrarch2/.travis.yml diff --git a/petrarch/PETRARCH.log b/petrarch2/PETRARCH.log similarity index 100% rename from petrarch/PETRARCH.log rename to petrarch2/PETRARCH.log diff --git a/petrarch/PETRglobals.py b/petrarch2/PETRglobals.py similarity index 100% rename from petrarch/PETRglobals.py rename to petrarch2/PETRglobals.py diff --git a/petrarch/PETRreader.py b/petrarch2/PETRreader.py similarity index 100% rename from petrarch/PETRreader.py rename to petrarch2/PETRreader.py diff --git a/petrarch/PETRtree.py b/petrarch2/PETRtree.py similarity index 100% rename from petrarch/PETRtree.py rename to petrarch2/PETRtree.py diff --git a/petrarch/PETRwriter.py b/petrarch2/PETRwriter.py similarity index 100% rename from petrarch/PETRwriter.py rename to petrarch2/PETRwriter.py diff --git a/petrarch/__init__.py b/petrarch2/__init__.py similarity index 100% rename from petrarch/__init__.py rename to petrarch2/__init__.py diff --git a/petrarch/data/config/PETR_config.ini b/petrarch2/data/config/PETR_config.ini similarity index 100% rename from petrarch/data/config/PETR_config.ini rename to petrarch2/data/config/PETR_config.ini diff --git a/petrarch/data/config/batch.rng b/petrarch2/data/config/batch.rng similarity index 100% rename from petrarch/data/config/batch.rng rename to petrarch2/data/config/batch.rng diff --git a/petrarch/data/config/petrarch.properties b/petrarch2/data/config/petrarch.properties similarity index 100% rename from petrarch/data/config/petrarch.properties rename to petrarch2/data/config/petrarch.properties diff --git a/petrarch/data/config/validation.rng b/petrarch2/data/config/validation.rng similarity index 100% rename from petrarch/data/config/validation.rng rename to petrarch2/data/config/validation.rng diff --git a/petrarch/data/dictionaries/CAMEO.2.0.txt b/petrarch2/data/dictionaries/CAMEO.2.0.txt similarity index 100% rename from petrarch/data/dictionaries/CAMEO.2.0.txt rename to petrarch2/data/dictionaries/CAMEO.2.0.txt diff --git a/petrarch/data/dictionaries/CAMEO.2.0_unsorted.txt b/petrarch2/data/dictionaries/CAMEO.2.0_unsorted.txt similarity index 100% rename from petrarch/data/dictionaries/CAMEO.2.0_unsorted.txt rename to petrarch2/data/dictionaries/CAMEO.2.0_unsorted.txt diff --git a/petrarch/data/dictionaries/CAMEO.verbpatterns.150430.txt b/petrarch2/data/dictionaries/CAMEO.verbpatterns.150430.txt similarity index 100% rename from petrarch/data/dictionaries/CAMEO.verbpatterns.150430.txt rename to petrarch2/data/dictionaries/CAMEO.verbpatterns.150430.txt diff --git a/petrarch/data/dictionaries/PETR.Validate.actors.txt b/petrarch2/data/dictionaries/PETR.Validate.actors.txt similarity index 100% rename from petrarch/data/dictionaries/PETR.Validate.actors.txt rename to petrarch2/data/dictionaries/PETR.Validate.actors.txt diff --git a/petrarch/data/dictionaries/PETR.Validate.agents.txt b/petrarch2/data/dictionaries/PETR.Validate.agents.txt similarity index 100% rename from petrarch/data/dictionaries/PETR.Validate.agents.txt rename to petrarch2/data/dictionaries/PETR.Validate.agents.txt diff --git a/petrarch/data/dictionaries/PETR.Validate.discards.txt b/petrarch2/data/dictionaries/PETR.Validate.discards.txt similarity index 100% rename from petrarch/data/dictionaries/PETR.Validate.discards.txt rename to petrarch2/data/dictionaries/PETR.Validate.discards.txt diff --git a/petrarch/data/dictionaries/PETR.Validate.verbs.txt b/petrarch2/data/dictionaries/PETR.Validate.verbs.txt similarity index 100% rename from petrarch/data/dictionaries/PETR.Validate.verbs.txt rename to petrarch2/data/dictionaries/PETR.Validate.verbs.txt diff --git a/petrarch/data/dictionaries/PETRARCH.log b/petrarch2/data/dictionaries/PETRARCH.log similarity index 100% rename from petrarch/data/dictionaries/PETRARCH.log rename to petrarch2/data/dictionaries/PETRARCH.log diff --git a/petrarch/data/dictionaries/Phoenix.Countries.actors.txt b/petrarch2/data/dictionaries/Phoenix.Countries.actors.txt similarity index 100% rename from petrarch/data/dictionaries/Phoenix.Countries.actors.txt rename to petrarch2/data/dictionaries/Phoenix.Countries.actors.txt diff --git a/petrarch/data/dictionaries/Phoenix.International.actors.txt b/petrarch2/data/dictionaries/Phoenix.International.actors.txt similarity index 100% rename from petrarch/data/dictionaries/Phoenix.International.actors.txt rename to petrarch2/data/dictionaries/Phoenix.International.actors.txt diff --git a/petrarch/data/dictionaries/Phoenix.IssueCoding.txt b/petrarch2/data/dictionaries/Phoenix.IssueCoding.txt similarity index 100% rename from petrarch/data/dictionaries/Phoenix.IssueCoding.txt rename to petrarch2/data/dictionaries/Phoenix.IssueCoding.txt diff --git a/petrarch/data/dictionaries/Phoenix.MilNonState.actors.txt b/petrarch2/data/dictionaries/Phoenix.MilNonState.actors.txt similarity index 100% rename from petrarch/data/dictionaries/Phoenix.MilNonState.actors.txt rename to petrarch2/data/dictionaries/Phoenix.MilNonState.actors.txt diff --git a/petrarch/data/dictionaries/Phoenix.agents.txt b/petrarch2/data/dictionaries/Phoenix.agents.txt similarity index 100% rename from petrarch/data/dictionaries/Phoenix.agents.txt rename to petrarch2/data/dictionaries/Phoenix.agents.txt diff --git a/petrarch/data/dictionaries/Phoenix.discards.txt b/petrarch2/data/dictionaries/Phoenix.discards.txt similarity index 100% rename from petrarch/data/dictionaries/Phoenix.discards.txt rename to petrarch2/data/dictionaries/Phoenix.discards.txt diff --git a/petrarch/data/dictionaries/Phoenix.prepositions.txt b/petrarch2/data/dictionaries/Phoenix.prepositions.txt similarity index 100% rename from petrarch/data/dictionaries/Phoenix.prepositions.txt rename to petrarch2/data/dictionaries/Phoenix.prepositions.txt diff --git a/petrarch/data/dictionaries/newdict.txt b/petrarch2/data/dictionaries/newdict.txt similarity index 100% rename from petrarch/data/dictionaries/newdict.txt rename to petrarch2/data/dictionaries/newdict.txt diff --git a/petrarch/data/dictionaries/testfile.txt b/petrarch2/data/dictionaries/testfile.txt similarity index 100% rename from petrarch/data/dictionaries/testfile.txt rename to petrarch2/data/dictionaries/testfile.txt diff --git a/petrarch/data/text/GigaWord.sample.PETR.xml b/petrarch2/data/text/GigaWord.sample.PETR.xml similarity index 100% rename from petrarch/data/text/GigaWord.sample.PETR.xml rename to petrarch2/data/text/GigaWord.sample.PETR.xml diff --git a/petrarch/data/text/PETR.UnitTest.records.xml b/petrarch2/data/text/PETR.UnitTest.records.xml similarity index 100% rename from petrarch/data/text/PETR.UnitTest.records.xml rename to petrarch2/data/text/PETR.UnitTest.records.xml diff --git a/petrarch/data/text/single_test.xml b/petrarch2/data/text/single_test.xml similarity index 100% rename from petrarch/data/text/single_test.xml rename to petrarch2/data/text/single_test.xml diff --git a/petrarch/petrarch.py b/petrarch2/petrarch2.py similarity index 100% rename from petrarch/petrarch.py rename to petrarch2/petrarch2.py diff --git a/petrarch/test.py b/petrarch2/test.py similarity index 100% rename from petrarch/test.py rename to petrarch2/test.py diff --git a/petrarch/tests/test_petrarch.py b/petrarch2/tests/test_petrarch.py similarity index 100% rename from petrarch/tests/test_petrarch.py rename to petrarch2/tests/test_petrarch.py diff --git a/petrarch/tex_outputs/.gitignore b/petrarch2/tex_outputs/.gitignore similarity index 100% rename from petrarch/tex_outputs/.gitignore rename to petrarch2/tex_outputs/.gitignore diff --git a/petrarch/tree_to_tex.py b/petrarch2/tree_to_tex.py similarity index 100% rename from petrarch/tree_to_tex.py rename to petrarch2/tree_to_tex.py diff --git a/petrarch/utilities.py b/petrarch2/utilities.py similarity index 100% rename from petrarch/utilities.py rename to petrarch2/utilities.py diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index c6dbb8c..0000000 --- a/requirements.txt +++ /dev/null @@ -1,13 +0,0 @@ -Jinja2==2.7.2 -MarkupSafe==0.23 -Pygments==1.6 -Sphinx==1.2.2 -Unidecode==0.04.16 -corenlp-python==3.2.0-3 -docutils==0.11 -numpydoc==0.4 -pexpect==3.2 -python-dateutil==2.2 -six==1.6.1 -wsgiref==0.1.2 -xmltodict==0.9.0 diff --git a/setup.py b/setup.py index 9f94bb5..1509534 100644 --- a/setup.py +++ b/setup.py @@ -1,21 +1,17 @@ from setuptools import setup -with open('requirements.txt', 'r') as f: - required = f.read().splitlines() - setup( - name='petrarch', - install_requires=required, + name='petrarch2', entry_points={ - 'console_scripts': ['petrarch = petrarch.petrarch:main']}, - version='0.01a', - author='Philip Schrodt, John Beieler', + 'console_scripts': ['petrarch2 = petrarch2.petrarch2:main']}, + version='1.0.0', + author='Philip Schrodt, John Beieler, Clayton Norris', author_email='openeventdata@gmail.com', - packages=['petrarch'], - package_dir={'petrarch': 'petrarch'}, - package_data={'petrarch': ['data/dictionaries/*', 'data/text/*', + packages=['petrarch2'], + package_dir={'petrarch2': 'petrarch2'}, + package_data={'petrarch2': ['data/dictionaries/*', 'data/text/*', 'data/config/*']}, url='openeventdata.org', license='LICENSE.txt', - description='PETRARCH parser for event data.', + description='PETRARCH 2 parser for event data.', long_description=open('README.md').read()) From aaba16aa1b173cac50472658336dfcd49f9722e6 Mon Sep 17 00:00:00 2001 From: John Beieler Date: Thu, 29 Oct 2015 13:27:29 -0400 Subject: [PATCH 2/7] Update tests file. --- petrarch2/tests/test_petrarch.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/petrarch2/tests/test_petrarch.py b/petrarch2/tests/test_petrarch.py index 86ed89c..ca8371d 100644 --- a/petrarch2/tests/test_petrarch.py +++ b/petrarch2/tests/test_petrarch.py @@ -1,5 +1,5 @@ -from petrarch import petrarch, PETRglobals, PETRreader, utilities -from petrarch import PETRtree as ptree +from petrarch2 import petrarch2, PETRglobals, PETRreader, utilities +from petrarch2 import PETRtree as ptree config = petrarch.utilities._get_data('data/config/', 'PETR_config.ini') @@ -38,7 +38,7 @@ def test_noun_meaning1(): phrase = test.tree.children[0] head, headphrase = phrase.get_head() - + assert head== "STATE" assert headphrase == phrase assert phrase.get_meaning() == ["IMGMUSISI"] @@ -52,7 +52,7 @@ def test_noun_meaning2(): phrase = test.tree.children[0] head, headphrase = phrase.get_head() - + assert head== "ORGANIZATION" assert headphrase == phrase assert phrase.get_meaning() == ["IGOWSTNAT"] @@ -64,7 +64,7 @@ def test_noun_meaning3(): test = ptree.Sentence(parse,"Barack Obama and Vladimir Putin", "081315") phrase = test.tree.children[0] - + assert sorted(phrase.get_meaning()) == sorted(["USAGOV","RUSGOV"]) @@ -74,7 +74,7 @@ def test_prepmeaning(): test = ptree.Sentence(parse,"to the market", "081315") phrase = test.tree.children[0] - + assert phrase.get_meaning() == ['TUR'] assert phrase.head == "MARKET" assert phrase.get_prep() == "TO" @@ -86,7 +86,7 @@ def test_noun_meaning4(): test = ptree.Sentence(parse,"The rebels from Syria", "081315") phrase = test.tree.children[0] - + assert phrase.get_meaning() == ['SYRREB'] assert phrase.get_head()[0] == "REBELS" assert phrase.get_head()[1] == phrase @@ -159,7 +159,7 @@ def test_simple(): text = "Germany invaded France" parse = "(ROOT (S (NP (NNP Germany)) (VP (VBD invaded) (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'}}} From 4ff63a6b779b98ddda7feebff0e99e28002dd615 Mon Sep 17 00:00:00 2001 From: John Beieler Date: Thu, 29 Oct 2015 13:32:06 -0400 Subject: [PATCH 3/7] Remove CoreNLP dep. --- petrarch2/utilities.py | 178 ++++++++++++++++++++--------------------- 1 file changed, 89 insertions(+), 89 deletions(-) diff --git a/petrarch2/utilities.py b/petrarch2/utilities.py index f959a82..3a983a0 100644 --- a/petrarch2/utilities.py +++ b/petrarch2/utilities.py @@ -36,57 +36,57 @@ import os import logging -import corenlp +#import corenlp import dateutil.parser import PETRglobals from collections import defaultdict, Counter - -def stanford_parse(event_dict): - logger = logging.getLogger('petr_log') - # What is dead can never die... - print("\nSetting up StanfordNLP. The program isn't dead. Promise.") - logger.info('Setting up StanfordNLP') - core = corenlp.StanfordCoreNLP(PETRglobals.stanfordnlp, - properties=_get_data('data/config/', - 'petrarch.properties'), - memory='2g') - total = len(list(event_dict.keys())) - print( - "Stanford setup complete. Starting parse of {} stories...".format(total)) - logger.info( - 'Stanford setup complete. Starting parse of {} stories.'.format(total)) - for i, key in enumerate(event_dict.keys()): - if (i / float(total)) * 100 in [10.0, 25.0, 50, 75.0]: - print('Parse is {}% complete...'.format((i / float(total)) * 100)) - for sent in event_dict[key]['sents']: - logger.info('StanfordNLP parsing {}_{}...'.format(key, sent)) - sent_dict = event_dict[key]['sents'][sent] - - if len(sent_dict['content']) > 512 or len( - sent_dict['content']) < 64: - logger.warning( - '\tText length wrong. Either too long or too short.') - pass - else: - try: - stanford_result = core.raw_parse(sent_dict['content']) - s_parsetree = stanford_result['sentences'][0]['parsetree'] - if 'coref' in stanford_result: - sent_dict['coref'] = stanford_result['coref'] - - # TODO: To go backwards you'd do str.replace(' ) ', ')') - sent_dict['parsed'] = _format_parsed_str(s_parsetree) - except Exception as e: - print('Something went wrong. ¯\_(ツ)_/¯. See log file.') - logger.warning( - 'Error on {}_{}. ¯\_(ツ)_/¯. {}'.format(key, sent, e)) - print('Done with StanfordNLP parse...\n\n') - logger.info('Done with StanfordNLP parse.') - - return event_dict +# Deprecated. Use hypnos instead. +# def stanford_parse(event_dict): +# logger = logging.getLogger('petr_log') +# # What is dead can never die... +# print("\nSetting up StanfordNLP. The program isn't dead. Promise.") +# logger.info('Setting up StanfordNLP') +# core = corenlp.StanfordCoreNLP(PETRglobals.stanfordnlp, +# properties=_get_data('data/config/', +# 'petrarch.properties'), +# memory='2g') +# total = len(list(event_dict.keys())) +# print( +# "Stanford setup complete. Starting parse of {} stories...".format(total)) +# logger.info( +# 'Stanford setup complete. Starting parse of {} stories.'.format(total)) +# for i, key in enumerate(event_dict.keys()): +# if (i / float(total)) * 100 in [10.0, 25.0, 50, 75.0]: +# print('Parse is {}% complete...'.format((i / float(total)) * 100)) +# for sent in event_dict[key]['sents']: +# logger.info('StanfordNLP parsing {}_{}...'.format(key, sent)) +# sent_dict = event_dict[key]['sents'][sent] +# +# if len(sent_dict['content']) > 512 or len( +# sent_dict['content']) < 64: +# logger.warning( +# '\tText length wrong. Either too long or too short.') +# pass +# else: +# try: +# stanford_result = core.raw_parse(sent_dict['content']) +# s_parsetree = stanford_result['sentences'][0]['parsetree'] +# if 'coref' in stanford_result: +# sent_dict['coref'] = stanford_result['coref'] +# +# # TODO: To go backwards you'd do str.replace(' ) ', ')') +# sent_dict['parsed'] = _format_parsed_str(s_parsetree) +# except Exception as e: +# print('Something went wrong. ¯\_(ツ)_/¯. See log file.') +# logger.warning( +# 'Error on {}_{}. ¯\_(ツ)_/¯. {}'.format(key, sent, e)) +# print('Done with StanfordNLP parse...\n\n') +# logger.info('Done with StanfordNLP parse.') +# +# return event_dict @@ -206,19 +206,19 @@ def init_logger(logger_filename): def combine_code(selfcode,to_add): """ Combines two verb codes, part of the verb interaction framework - - + + Parameters ---------- selfcode,to_add: ints Upper and lower verb codes, respectively - + Returns ------- combined value - + """ - + if to_add < 0: return to_add + selfcode if selfcode >= 0x1000 and to_add >= 0x1000: @@ -232,7 +232,7 @@ def combine_code(selfcode,to_add): def code_to_string(events): """ - Converts an event into a string, replacing the integer codes with strings + Converts an event into a string, replacing the integer codes with strings representing their value in hex """ retstr= "" @@ -247,7 +247,7 @@ def ev_to_string(ev): if isinstance(low,tuple): low = "("+ev_to_string(low)+")" - + return up + " " + low + " " + hex(c) for ev in events: #print(ev) @@ -265,7 +265,7 @@ def ev_to_string(ev): def convert_code(code,forward = 1): """ Convert a verb code between CAMEO and the Petrarch internal coding ontology. - + New coding scheme: 0 0 0 0 @@ -284,18 +284,18 @@ def convert_code(code,forward = 1): D Release E Int'l Involvement F D-escalation - + In the first column, higher numbers take priority. i.e. “Say + Intend” is just “Intend” or “Intend + Consult” is just Consult - - + + Parameters ---------- code: string or int, depending on forward Code to be converted - + forward: boolean Direction of conversion, True = CAMEO -> PICO - + Returns ------- @@ -304,7 +304,7 @@ def convert_code(code,forward = 1): The two parts of the code [XXX:XXX], converted to the new system. The first is an inherent active meaning, the second is an inherent passive meaning. Both are not always present, most codes just have the active. - + """ @@ -319,7 +319,7 @@ def convert_code(code,forward = 1): "018" : 0x1004 , "019" : 0x1005 , - + "020" : 0x2000 , # Appeal "021" : 0x2070 , "0211" : 0x2075 , @@ -347,8 +347,8 @@ def convert_code(code,forward = 1): "026" : 0x2010 , "027" : 0x2020 , "028" : 0x2030 , - - + + "030" : 0x3000 , # Intend "031" : 0x3070 , "0311" : 0x3075 , @@ -377,7 +377,7 @@ def convert_code(code,forward = 1): "037" : 0x3020 , "038" : 0x3230 , "039" : 0x3030 , - + "040" : 0xB000 , # Consult "041" : 0xB001 , "042" : 0xB002 , @@ -385,8 +385,8 @@ def convert_code(code,forward = 1): "044" : 0xB010 , "045" : 0xB030 , "046" : 0xB010 , - - + + "050" : 0x0080 , # Diplomatic Coop "051" : 0x0081 , "052" : 0x0082 , @@ -395,7 +395,7 @@ def convert_code(code,forward = 1): "055" : 0x0085 , "056" : 0x0086 , "057" : 0x0087 , - + "060" : 0x0070 , # Material Coop "061" : 0x0075 , "062" : 0x0076 , @@ -408,7 +408,7 @@ def convert_code(code,forward = 1): "073" : 0x0047 , "074" : 0x0049 , "075" : 0x004E , - + "080" : 0x0200 , # Yield "081" : 0x020B , "0811" : 0x0203 , @@ -435,13 +435,13 @@ def convert_code(code,forward = 1): "0873" : 0x02C6 , "0874" : 0x02C2 , "08" : 0x0200 , - + "090" : 0xA000 , # Investigate "091" : 0xA001 , "092" : 0xA002 , "093" : 0xA003 , "094" : 0xA004 , - + "100" : 0x4000 , # Demand "101" : 0x4070 , "1011" : 0x4075 , @@ -470,7 +470,7 @@ def convert_code(code,forward = 1): "107" : 0x4020 , "108" : 0x4030 , - + "110" : 0x7000 , # Disapprove "111" : 0x7001 , "112" : 0x70a0 , @@ -483,8 +483,8 @@ def convert_code(code,forward = 1): "114" : 0x7003 , "115" : 0x7008 , "116" : 0x7005 , - - + + "120" : -0xFFFF , # Reject "121" : -0xFFFF + 0x0070 , "1211" : -0xFFFF + 0x0075 , @@ -511,7 +511,7 @@ def convert_code(code,forward = 1): "127" : -0xFFFF + 0x0020 , "128" : -0xFFFF + 0x0002 , "129" : -0xFFFF + 0x0001 , - + "130" : 0x6000 , # Threaten "131" : 0x6100 , "1311" : 0x6140 , @@ -534,17 +534,17 @@ def convert_code(code,forward = 1): "1384" : 0x60A4 , "1385" : 0x60B0 , "139" : 0x6005 , - - + + "140" : 0x5000 , # Protest "145" : 0x50A0 , - + "150" : 0x8000 , # Exhibit Force Posture "151" : 0x8001 , "152" : 0x8002 , "153" : 0x8003 , "154" : 0x8004 , - + "160" : 0x0100 , # Reduce Relations "161" : 0x0180 , "162" : 0x0140 , @@ -558,7 +558,7 @@ def convert_code(code,forward = 1): "1661" : 0x0159 , "1662" : 0x015A , "1663" : 0x015E , - + "170" : 0x9000 , # Coerce "171" : 0x9010 , "1711" : 0x9011 , @@ -571,7 +571,7 @@ def convert_code(code,forward = 1): "173" : 0x9020 , "174" : 0x9030 , "175" : 0x9040 , - + "180" : 0x0090 , # Assault "181" : 0x0091 , "182" : 0x0092 , @@ -587,8 +587,8 @@ def convert_code(code,forward = 1): "184" : 0x009C , "185" : 0x009D , "186" : 0x009E , - - + + "190" : 0x00A0 , # Fight "191" : 0x00A1 , "192" : 0x00A2 , @@ -598,16 +598,16 @@ def convert_code(code,forward = 1): "1951" : 0x00A6 , "1952" : 0x00A7 , "196" : 0x00A8 , - + "200" : 0x00B0 , # Use Unconventional Mass Violence "---" : 0 } - + if forward: passive = False active = code.split(":") passive = active[1] if len(active) > 1 else "---" active = active[0] if active[0] else "---" - + if active in cat: active = cat[active] else: @@ -618,15 +618,15 @@ def convert_code(code,forward = 1): passive = cat[passive[:2]+"0"] return active, passive - - + + else: reverse = dict(map(lambda a : (a[1],a[0]) , cat.items()) + # Other weird quirks [ (0x30a0,"138"), # Want to attack - + ]) if code and code in reverse: return reverse[code] - - return 0 # hex(code) \ No newline at end of file + + return 0 # hex(code) From 0010ef30f29dfd4d680d7d27031ffa10f2ca9cf3 Mon Sep 17 00:00:00 2001 From: John Beieler Date: Thu, 29 Oct 2015 13:34:34 -0400 Subject: [PATCH 4/7] Needed this requirement. --- requirements.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..14c1847 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +python-dateutil==2.2 From 1aaa8157ff3ae6e91604ae1b604130049bb5c952 Mon Sep 17 00:00:00 2001 From: John Beieler Date: Thu, 29 Oct 2015 13:39:22 -0400 Subject: [PATCH 5/7] Install deps on Travis. --- .travis.yml | 3 ++- setup.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 662df9a..915a82b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,5 +2,6 @@ language: python python: - "2.7" install: "pip install -e ." +install: "pip install -r requirements.txt" script: py.test -sudo: false \ No newline at end of file +sudo: false diff --git a/setup.py b/setup.py index 1509534..a11124e 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,11 @@ from setuptools import setup +with open('requirements.txt', 'r') as f: + required = f.read().splitlines() + setup( name='petrarch2', + install_requires=required, entry_points={ 'console_scripts': ['petrarch2 = petrarch2.petrarch2:main']}, version='1.0.0', From 91ed0bc162482ff70f20bf9b96f31177c9a27f9d Mon Sep 17 00:00:00 2001 From: John Beieler Date: Thu, 29 Oct 2015 13:42:15 -0400 Subject: [PATCH 6/7] Update travis.yml --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 915a82b..eef5bd8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,8 @@ language: python python: - "2.7" -install: "pip install -e ." -install: "pip install -r requirements.txt" +install: + - pip install -e . + - pip install -r requirements.txt script: py.test sudo: false From 057927a02a02275ba671a64ddbb4c0ebd82945ea Mon Sep 17 00:00:00 2001 From: John Beieler Date: Thu, 29 Oct 2015 13:44:16 -0400 Subject: [PATCH 7/7] Update name in test script. --- petrarch2/tests/test_petrarch.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/petrarch2/tests/test_petrarch.py b/petrarch2/tests/test_petrarch.py index ca8371d..7d7b3e7 100644 --- a/petrarch2/tests/test_petrarch.py +++ b/petrarch2/tests/test_petrarch.py @@ -2,17 +2,17 @@ from petrarch2 import PETRtree as ptree -config = petrarch.utilities._get_data('data/config/', 'PETR_config.ini') +config = petrarch2.utilities._get_data('data/config/', 'PETR_config.ini') print("reading config") -petrarch.PETRreader.parse_Config(config) +petrarch2.PETRreader.parse_Config(config) print("reading dicts") -petrarch.read_dictionaries() +petrarch2.read_dictionaries() def test_version(): - assert petrarch.get_version() == "1.0.0" + assert petrarch2.get_version() == "1.0.0" def test_read(): @@ -163,7 +163,7 @@ def test_simple(): 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) + return_dict = petrarch2.do_coding(dict,None) print(return_dict) assert return_dict['test123']['sents']['0']['events'] == [('DEU','FRA','192')] @@ -176,7 +176,7 @@ def test_simple2(): 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) + return_dict = petrarch2.do_coding(dict,None) print(return_dict) assert return_dict['test123']['sents']['0']['events'] == [('DEU','FRA','173')] @@ -208,7 +208,7 @@ def test_complex1(): 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) + return_dict = petrarch2.do_coding(dict,None) print(return_dict) assert return_dict['test123']['sents']['0']['events'] == [('TUNJUD','NGAEDU','173')]