Commit 24f38e70 authored by Grzegorz Kostkowski's avatar Grzegorz Kostkowski

fix missing package and minor changes in tools

parent f3705ce3
# Unreleased # Unreleased
## 0.5.1
### Changed
- fix issue with missing package data
- minor changes in tools
## 0.5 ## 0.5
### Changed ### Changed
- tool for storing polarity (fixed polarity, e.g. after 'generalize_polarity') - tool for storing polarity (fixed polarity, e.g. after 'generalize_polarity')
......
...@@ -17,7 +17,7 @@ setuptools.setup( ...@@ -17,7 +17,7 @@ setuptools.setup(
author='Arkadiusz Janz, Grzegorz Kostkowski', author='Arkadiusz Janz, Grzegorz Kostkowski',
description='''Tool for annotating *.ccl documents with emotions-related description='''Tool for annotating *.ccl documents with emotions-related
annotations.''', annotations.''',
version='0.5', version='0.5.1',
license='', license='',
install_requires=requirements, install_requires=requirements,
packages=[ packages=[
......
...@@ -47,3 +47,12 @@ python add_emotions_to_graph.py -g plwn_graph_emotive-2019-10-02_pl_en_with_supe ...@@ -47,3 +47,12 @@ python add_emotions_to_graph.py -g plwn_graph_emotive-2019-10-02_pl_en_with_supe
-o plwn_graph_emotive-2019-09-26_with_super_an_PL_ENG_polarity_and_emo.xml \ -o plwn_graph_emotive-2019-09-26_with_super_an_PL_ENG_polarity_and_emo.xml \
[-a] [-a]
``` ```
## Append emotion (polarity) from L-McD dict to graph:
```
python add_emotions_to_graph.py -g plwn_graph_emotive-2019-09-26_with_super_an_PL_ENG_polarity_and_emo_syn_hypo.xml \
--files Loughran_McD_data/L-McD-positive_syn-polarity.txt \
Loughran_McD_data/L-McD-negative_syn-polarity.txt \
Loughran_McD_data/L-McD-amb_v2_syn-polarity.txt \
-o plwn_LMcD_graph_emotive-2019-09-26_with_super_an_PL_ENG_polarity_and_emo_with_litigious.xml
```
...@@ -10,12 +10,12 @@ import graph_tool as gt ...@@ -10,12 +10,12 @@ import graph_tool as gt
from Emotional.base.emotion_graph import EmotionGraph from Emotional.base.emotion_graph import EmotionGraph
from Emotional.helpers.heuristics import (get_heuristic_by_name, from Emotional.helpers.heuristics import (get_heuristic_by_name,
bind_heuristic_arguments) bind_heuristic_arguments)
from Emotional.tools.graph_utils import (recreate_node_attr, from Emotional.tools.utils import (recreate_node_attr,
create_if_not_exists_node_attr) create_if_not_exists_node_attr)
from reader import read_mapping, read_translation from reader import read_mapping, read_translation
from loader import load_emo_from_files from loader import load_emo_from_files
from utils import as_logging_level from utils import as_logging_level, handle_amb_annotation
# logger = logging.getLogger(__name__) # logger = logging.getLogger(__name__)
# c_handler = logging.StreamHandler() # c_handler = logging.StreamHandler()
...@@ -82,6 +82,7 @@ def generalize_append_synset_polarity(g, syn_id_polarity_map, ...@@ -82,6 +82,7 @@ def generalize_append_synset_polarity(g, syn_id_polarity_map,
syn_polarity = syn_id_polarity_map.get(syn_id, None) syn_polarity = syn_id_polarity_map.get(syn_id, None)
# logging.debug("synset: {}\t{}".format(syn_id, syn_polarity)) # logging.debug("synset: {}\t{}".format(syn_id, syn_polarity))
if syn_polarity: if syn_polarity:
# import q;pudb.set_trace()
if node.polarity and not override_graph_polarity: if node.polarity and not override_graph_polarity:
skip_emo_counter += 1 skip_emo_counter += 1
logging.debug("skipping for {}: existed: {}" logging.debug("skipping for {}: existed: {}"
...@@ -91,6 +92,7 @@ def generalize_append_synset_polarity(g, syn_id_polarity_map, ...@@ -91,6 +92,7 @@ def generalize_append_synset_polarity(g, syn_id_polarity_map,
# use with lexical units polarities # use with lexical units polarities
syn_polarity_map = {syn_id: syn_polarity} syn_polarity_map = {syn_id: syn_polarity}
polarity = heuristic(syn_polarity_map) polarity = heuristic(syn_polarity_map)
polarity = handle_amb_annotation(polarity)
if node.polarity and override_graph_polarity: if node.polarity and override_graph_polarity:
logging.debug("Override polarity for synset {}: {}" logging.debug("Override polarity for synset {}: {}"
.format(syn_id, polarity)) .format(syn_id, polarity))
...@@ -233,16 +235,27 @@ def _set_logging(txt_level): ...@@ -233,16 +235,27 @@ def _set_logging(txt_level):
logging.basicConfig(level=as_logging_level(txt_level)) logging.basicConfig(level=as_logging_level(txt_level))
def _get_emo_stats(g): def _get_emo_stats(g, full=False):
def _get_emo_stat(field): def _get_emo_stat(field, value=None):
if g.has_node_attribute(field): if g.has_node_attribute(field):
return len([n for n in g.all_nodes() if value is None:
if g.use_graph_tool().vp[field][n] is not None]) return len([n for n in g.all_nodes()
if g.use_graph_tool().vp[field][n] is not None])
else:
return len([n for n in g.all_nodes()
if g.use_graph_tool().vp[field][n] == value])
return 0 return 0
no_of_pol = _get_emo_stat('polarity') no_of_pol = _get_emo_stat('polarity')
no_of_emo_nam = _get_emo_stat('emotion_names') no_of_emo_nam = _get_emo_stat('emotion_names')
no_of_emo_val = _get_emo_stat('emotion_valuations') no_of_emo_val = _get_emo_stat('emotion_valuations')
if full:
no_of_amb_pol = _get_emo_stat('polarity', value='amb')
no_of_positive_pol = _get_emo_stat('polarity', value=1)
no_of_negative_pol = _get_emo_stat('polarity', value=-1)
no_of_neutral_pol = _get_emo_stat('polarity', value=0)
return no_of_pol, no_of_emo_nam, no_of_emo_val, [no_of_positive_pol,
no_of_neutral_pol, no_of_negative_pol, no_of_amb_pol]
return no_of_pol, no_of_emo_nam, no_of_emo_val return no_of_pol, no_of_emo_nam, no_of_emo_val
...@@ -260,13 +273,16 @@ if __name__ == "__main__": ...@@ -260,13 +273,16 @@ if __name__ == "__main__":
logging.info("Loading graph ...") logging.info("Loading graph ...")
g.unpickle(args.graph) g.unpickle(args.graph)
no_of_pol, no_of_emo_nam, no_of_emo_val = _get_emo_stats(g) no_of_pol, no_of_emo_nam, no_of_emo_val, pol_details = _get_emo_stats(g,
logging.info('''Loaded graph contains annotations:\n\t{} polarity anotations\n\t{} emotion names\n\t{} emotion valuations''' full=True)
.format(no_of_pol, no_of_emo_nam, no_of_emo_val)) positive_pol, neutral_pol, negative_pol, amb_pol = pol_details
logging.info('''Loaded graph contains annotations:\n\t{} polarity anotations\n\t\t{} positive\n\t\t{} neutral\n\t\t{} negative\n\t\t{} ambiguous\n\t{} emotion names\n\t{} emotion valuations'''
.format(no_of_pol, positive_pol, neutral_pol, negative_pol, amb_pol, no_of_emo_nam, no_of_emo_val))
if args.recalculate_pl: if args.recalculate_pl:
logging.info("Generalizing polarity for pl synsets ...") logging.info("Generalizing polarity for pl synsets ...")
g.generalize_polarity(override_polarity=False) # g.generalize_polarity(override_polarity=False)
g.generalize_polarity()
logging.info("Adding polarity from mapping to graph ...") logging.info("Adding polarity from mapping to graph ...")
gen_syn_id_2_polarity_map = generalize_append_synset_polarity(g, gen_syn_id_2_polarity_map = generalize_append_synset_polarity(g,
...@@ -283,8 +299,11 @@ if __name__ == "__main__": ...@@ -283,8 +299,11 @@ if __name__ == "__main__":
wipe_out_emotions=wipe_out_emo_info, wipe_out_emotions=wipe_out_emo_info,
generalized_polarity=gen_syn_id_2_polarity_map) generalized_polarity=gen_syn_id_2_polarity_map)
no_of_pol, no_of_emo_nam, no_of_emo_val = _get_emo_stats(g) # no_of_pol, no_of_emo_nam, no_of_emo_val = _get_emo_stats(g)
logging.info('''Saving graph with annotations:\n\t{} polarity anotations\n\t{} emotion names\n\t{} emotion valuations''' no_of_pol, no_of_emo_nam, no_of_emo_val, pol_details = _get_emo_stats(g,
.format(no_of_pol, no_of_emo_nam, no_of_emo_val)) full=True)
positive_pol, neutral_pol, negative_pol, amb_pol = pol_details
logging.info('''Saving graph with annotations:\n\t{} polarity anotations\n\t\t{} positive\n\t\t{} neutral\n\t\t{} negative\n\t\t{} ambiguous\n\t{} emotion names\n\t{} emotion valuations'''
.format(no_of_pol, positive_pol, neutral_pol, negative_pol, amb_pol, no_of_emo_nam, no_of_emo_val))
g.pickle(args.output) g.pickle(args.output)
\ No newline at end of file
...@@ -33,6 +33,10 @@ def normalize_markedness(markedness): ...@@ -33,6 +33,10 @@ def normalize_markedness(markedness):
raise ValueError('Cannot normalize markedness "{}"'.format(markedness)) raise ValueError('Cannot normalize markedness "{}"'.format(markedness))
return MAPPING[markedness] return MAPPING[markedness]
def handle_amb_annotation(num_an):
if num_an is None or num_an == 'None':
return "amb"
return num_an
import logging import logging
LOGGING = {'info': logging.INFO, 'debug': logging.DEBUG, 'warn': logging.WARN} LOGGING = {'info': logging.INFO, 'debug': logging.DEBUG, 'warn': logging.WARN}
......
...@@ -12,8 +12,9 @@ with open(output, 'w') as ofile: ...@@ -12,8 +12,9 @@ with open(output, 'w') as ofile:
for n in g.all_nodes(): for n in g.all_nodes():
polarity = n.polarity polarity = n.polarity
syn_id = n.synset.synset_id syn_id = n.synset.synset_id
is_eng = any([lu for lu in n.synset.lu_set if lu.pos > 4])
emo_names = n.emotion_names emo_names = n.emotion_names
emo_vals = n.emotion_valuations emo_vals = n.emotion_valuations
if not (polarity is None and emo_names is None and emo_vals is None): if not (polarity is None and emo_names is None and emo_vals is None):
ofile.write("{}\t{}\t{}\t{}\n".format(syn_id, polarity, emo_names, emo_vals)) ofile.write("{}\t{}\t{}\t{}\t{}\n".format(syn_id, polarity, is_eng, emo_names, emo_vals))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment