diff --git a/.circleci/config.yml b/.circleci/config.yml index f0464ec..63b97c9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,18 +3,14 @@ version: 2 jobs: build: docker: - - image: phusion/baseimage + - image: circleci/openjdk:8-jdk working_directory: ~/circulate steps: - run: name: Install Python Pip JDK command: | - apt-get -qq update - apt-get -y install git openssh-client python python-pip python-dev software-properties-common - add-apt-repository -y ppa:openjdk-r/ppa - apt-get update && apt-get install -y openjdk-8-jdk - export JDK_HOME=/usr/lib/jvm/java-8-openjdk-amd64 - export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 + sudo apt-get -qq update + sudo apt-get -y install git openssh-client python3 python3-pip python3-dev software-properties-common - checkout - run: name: Private Pypi Config Setup @@ -28,39 +24,39 @@ jobs: - run: name: Pre-install Virtual Env command: | - pip install virtualenv - virtualenv venv + pip3 install virtualenv + virtualenv -p python3 ~/venv - restore_cache: - key: deps2.7-{{ .Branch }}-{{ checksum "requirements.txt" }} + key: deps3.5-{{ .Branch }}-{{ checksum "requirements.txt" }} - run: name: Install Dependencies command: | - . venv/bin/activate - export JDK_HOME=/usr/lib/jvm/java-8-openjdk-amd64 - export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 - pip install -U pip wheel setuptools - pip install cython - pip install coveralls - pip install -r requirements.txt --extra-index-url $PYPI_HOST + . ~/venv/bin/activate + export JDK_HOME=/usr/local/openjdk-8 + export JAVA_HOME=/usr/local/openjdk-8 + pip3 install -U pip wheel setuptools + pip3 install cython + pip3 install coveralls + pip3 install --extra-index-url $PYPI_HOST_WITH_CRED -r requirements.txt - save_cache: - key: deps2.7-{{ .Branch }}-{{ checksum "requirements.txt" }} + key: deps3.5-{{ .Branch }}-{{ checksum "requirements.txt" }} paths: - - "venv" + - "~/venv" - run: name: Test command: | - . venv/bin/activate - export JDK_HOME=/usr/lib/jvm/java-8-openjdk-amd64 - export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 + . ~/venv/bin/activate + export JDK_HOME=/usr/local/openjdk-8 + export JAVA_HOME=/usr/local/openjdk-8 coverage run --source=emoint -m unittest discover -v coverage report COVERALLS_REPO_TOKEN=$COVERALLS_REPO_TOKEN coveralls --verbose - run: name: Push To Private Pypi Server command: | - . venv/bin/activate - python setup.py bdist_wheel upload -r $PYPI_HOST - python setup.py sdist upload -r $PYPI_HOST + . ~/venv/bin/activate + python3 setup.py bdist_wheel upload -r $PYPI_HOST + python3 setup.py sdist upload -r $PYPI_HOST - store_artifacts: path: test-reports/ destination: tr1 diff --git a/.travis.yml b/.travis.yml index 5ac39fa..cb0ba58 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,11 @@ language: python python: - - "2.7" + - "3.5" install: - - pip install -U pip wheel setuptools - - pip install coveralls --quiet - - pip install cython --quiet - - pip install -r requirements.txt --extra-index-url $PYPI_HOST --quiet + - pip3 install -U pip wheel setuptools + - pip3 install coveralls --quiet + - pip3 install cython --quiet + - pip3 install -r requirements.txt --extra-index-url $PYPI_HOST_WITH_CRED --quiet script: coverage run --source=. -m unittest discover -v diff --git a/emoint/featurizers/base_featurizers.py b/emoint/featurizers/base_featurizers.py index 0b47296..1cac4b7 100644 --- a/emoint/featurizers/base_featurizers.py +++ b/emoint/featurizers/base_featurizers.py @@ -94,7 +94,10 @@ def create_embedding_mapping(lexicon_path, word_first=True, leave_head=False): lines = lines[1:] lexicon_map = {} for l in lines: - splits = l.split(' ') + if isinstance(l, str): + splits = l.split(' ') + else: + splits = l.decode('utf-8').split('\t') if word_first: lexicon_map[splits[0]] = np.asarray(splits[1:], dtype='float32') else: diff --git a/emoint/featurizers/emoji_sentiment_ranking_featurizer.py b/emoint/featurizers/emoji_sentiment_ranking_featurizer.py index 9629fbc..286772c 100644 --- a/emoint/featurizers/emoji_sentiment_ranking_featurizer.py +++ b/emoint/featurizers/emoji_sentiment_ranking_featurizer.py @@ -34,7 +34,10 @@ def create_lexicon_mapping(lexicons_path): rows = csv.DictReader(open(lexicons_path), ) emoji_map = {} for row in rows: - emoji_map[row['Emoji'].decode('utf-8')] = [ + tmp = row['Emoji'] + if not isinstance(tmp, str): + tmp = row['Emoji'].decode('utf-8') + emoji_map[tmp] = [ float(row['Negative'])/float(row['Occurrences']), float(row['Positive'])/float(row['Occurrences']), float(row['Neutral'])/float(row['Occurrences']) diff --git a/emoint/featurizers/liwc_featurizer.py b/emoint/featurizers/liwc_featurizer.py index b510e61..f767618 100644 --- a/emoint/featurizers/liwc_featurizer.py +++ b/emoint/featurizers/liwc_featurizer.py @@ -6,7 +6,7 @@ from emoint.featurizers.base_featurizers import Featurizer from emoint.utils.utils import LIWCTrie -from utils import liwc_lexicon_path +from .utils import liwc_lexicon_path """ Info: http://liwc.wpengine.com/ @@ -40,7 +40,7 @@ def create_lexicon_mapping(lexicon_path): liwc_trie.insert(pair[0], pair[1]) except Exception as ex: pass - return categories.values(), liwc_trie + return list(categories.values()), liwc_trie def __init__(self, lexicons_path=liwc_lexicon_path): """Initialize LIWC Lexicon Featurizer @@ -80,7 +80,8 @@ def set_punctuation_counts(self, text, liwc): def featurize(self, text, tokenizer): liwc = {} - text = text.decode('utf8') + if not isinstance(text, str): + text = text.decode('utf8') num_capital_words = len(re.findall(r"[A-Z]['A-Z]*", text)) words = re.findall(r"[a-z]['a-z]*", text.lower()) diff --git a/emoint/tests/test_ensembles.py b/emoint/tests/test_ensembles.py index 0ccd168..3087393 100644 --- a/emoint/tests/test_ensembles.py +++ b/emoint/tests/test_ensembles.py @@ -25,7 +25,7 @@ def helper(self, func, ens_type, out_file, expected, w=None): with open(out_file, 'r') as f: got = f.read().splitlines() self.assertListEqual( - [float(x) for x in got], + [round(float(x), 1) for x in got], expected, msg='Expected: {} != Got: {}'.format(expected, got) ) diff --git a/requirements.txt b/requirements.txt index 87fd2b9..0fa0652 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ ---extra-index-url $PYPI_HOST +--trusted-host pypi.deepaffects.com Cython xgboost sklearn @@ -6,5 +6,5 @@ pandas scipy numpy pyjnius -tweetokenize nltk +tweetokenize==1.1.0 diff --git a/setup.py b/setup.py index 19d88a0..50e100f 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,11 @@ from setuptools import setup, find_packages from codecs import open from os import path -from pip.req import parse_requirements + +try: # for pip >= 10 + from pip._internal.req import parse_requirements +except ImportError: # for pip <= 9.0.3 + from pip.req import parse_requirements here = path.abspath(path.dirname(__file__)) @@ -13,7 +17,7 @@ setup( name='EmoInt', - version='0.1.0', + version='0.1.2', description='Affective Computing', long_description=long_description, url='https://github.com/seernet/EmoInt',