Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moved tokenize.py file to fix installation issues (via pip from github) #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions rouge/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Python ROUGE Implementation

## Installation

```
pip install -e "git+https://github.com/mim-solutions/google-research.git#egg=rouge_score&subdirectory=rouge
```

## Fork

The original repo (https://github.com/google-research/google-research) was forked
due to problems with installing it:

* version available in pip (https://pypi.org/project/rouge-score/) is outdated,
* version from master failed to install: it had file `tokenize.py` and it hide standard library module `tokenize`,
so installation scripts failed with error like:

```
File "/home/jupyter-apacuk/.conda/envs/encoder_decoder/lib/python3.8/linecache.py", line 136, in updatecache
with tokenize.open(fullname) as fp:
AttributeError: module 'tokenize' has no attribute 'open'
```

## Overview

This is a native python implementation of ROUGE, designed to replicate results
Expand Down
8 changes: 4 additions & 4 deletions rouge/io_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import tempfile

from absl.testing import absltest
from rouge import io
from rouge import rouge_scorer
from rouge import scoring
from rouge import test_util
from rouge_score import io
from rouge_score import rouge_scorer
from rouge_score import scoring
from rouge_score import test_util


class IoTest(absltest.TestCase):
Expand Down
6 changes: 3 additions & 3 deletions rouge/rouge.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@

from absl import app
from absl import flags
from rouge import io
from rouge import rouge_scorer
from rouge import scoring
from rouge_score import io
from rouge_score import rouge_scorer
from rouge_score import scoring

flags.DEFINE_string("target_filepattern", None,
"Files containing target text.")
Expand Down
4 changes: 2 additions & 2 deletions rouge/rouge_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
import six
from six.moves import map
from six.moves import range
from rouge import scoring
from rouge import tokenizers
from rouge_score import scoring
from rouge_score import tokenizers


class RougeScorer(scoring.BaseScorer):
Expand Down
6 changes: 3 additions & 3 deletions rouge/rouge_scorer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@

from absl.testing import absltest
from absl.testing import parameterized
from rouge import rouge_scorer
from rouge import test_util
from rouge import tokenizers
from rouge_score import rouge_scorer
from rouge_score import test_util
from rouge_score import tokenizers


class RougeScorerTest(parameterized.TestCase):
Expand Down
5 changes: 5 additions & 0 deletions rouge/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ virtualenv -p python3 .
source ./bin/activate

pip install -r rouge/requirements.txt


python -c "import nltk; nltk.download('punkt')"
python -m rouge.io_test
python -m rouge.rouge_scorer_test
python -m rouge.scoring_test
python -m rouge.tokenize_lib_test
python -m rouge.tokenizers_test
6 changes: 3 additions & 3 deletions rouge/scoring_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import numpy as np
from six.moves import range
from six.moves import zip
from rouge import rouge_scorer
from rouge import scoring
from rouge import test_util
from rouge_score import rouge_scorer
from rouge_score import scoring
from rouge_score import test_util

# Delta for matching against ground truth rouge values. Must be relatively
# high compared to the individual rouge tests since bootstrap sampling
Expand Down
2 changes: 1 addition & 1 deletion rouge/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

setuptools.setup(
name="rouge_score",
version="0.0.4",
version="0.0.5",
author="Google LLC",
author_email="[email protected]",
description="Pure python implementation of ROUGE-1.5.5.",
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions rouge/tokenize_test.py → rouge/tokenize_lib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for tokenize."""
"""Tests for tokenize_lib."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from absl.testing import absltest
from rouge import tokenize
from rouge_score import tokenize_lib


class TokenizeTest(absltest.TestCase):

def test_give_me_a_name(self):
self.assertEqual(['one', 'two', 'three'],
tokenize.tokenize('one Two three', None))
tokenize_lib.tokenize('one Two three', None))
self.assertEqual(['one', 'two', 'three'],
tokenize.tokenize('one\n Two \nthree', None))
tokenize_lib.tokenize('one\n Two \nthree', None))


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions rouge/tokenizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"""
import abc
from nltk.stem import porter
from rouge import tokenize
from rouge_score import tokenize_lib


class Tokenizer(abc.ABC):
Expand All @@ -48,4 +48,4 @@ def __init__(self, use_stemmer=False):
self._stemmer = porter.PorterStemmer() if use_stemmer else None

def tokenize(self, text):
return tokenize.tokenize(text, self._stemmer)
return tokenize_lib.tokenize(text, self._stemmer)
2 changes: 1 addition & 1 deletion rouge/tokenizers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"""Tests for tokenizers."""

from absl.testing import absltest
from rouge import tokenizers
from rouge_score import tokenizers


class TokenizersTest(absltest.TestCase):
Expand Down