Skip to content

Commit a0c325c

Browse files
committed
pep8 stuff
1 parent dcefcc1 commit a0c325c

File tree

6 files changed

+78
-79
lines changed

6 files changed

+78
-79
lines changed

files2rouge/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
from files2rouge.files2rouge import run
33
from files2rouge.files2rouge import main
44
from files2rouge.settings import Settings
5+
6+
__all__ = [absolute_import, run, main, Settings]

files2rouge/files2rouge.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,26 @@ def run(summ_path,
4343
print("Preparing documents...")
4444
utils.mkdirs([sys_root, model_root])
4545
utils.split_files(model_file=ref_path,
46-
system_file=summ_path,
47-
model_dir=model_root,
48-
system_dir=sys_root,
49-
eos=args.eos)
46+
system_file=summ_path,
47+
model_dir=model_root,
48+
system_dir=sys_root,
49+
eos=eos)
5050
print("Running ROUGE...")
5151
log_level = logging.ERROR if not verbose else None
5252
r = pyrouge.Rouge155(rouge_dir=os.path.dirname(s.data['ROUGE_path']),
5353
log_level=log_level)
5454
r.system_dir = sys_root
5555
r.model_dir = model_root
56-
r.system_filename_pattern = 's.(\d+).txt'
56+
r.system_filename_pattern = r's.(\d+).txt'
5757
r.model_filename_pattern = 'm.[A-Z].#ID#.txt'
5858
data_arg = "-e %s" % s.data['ROUGE_data']
5959

6060
if not rouge_args:
6161
rouge_args = [
62-
'-c', 95,
63-
'-r', 1000,
64-
'-n', 2,
65-
'-a']
62+
'-c', 95,
63+
'-r', 1000,
64+
'-n', 2,
65+
'-a']
6666
rouge_args_str = " ".join([str(_) for _ in rouge_args])
6767
else:
6868
rouge_args_str = rouge_args

files2rouge/settings.py

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,42 @@
44
PATHS = ['ROUGE_path', 'ROUGE_data']
55
PARAMS = PATHS + []
66

7+
78
def _default_path():
8-
_dir, _filename = os.path.split(__file__)
9-
return os.path.join(_dir, 'settings.json')
9+
_dir, _filename = os.path.split(__file__)
10+
return os.path.join(_dir, 'settings.json')
1011

1112

1213
class Settings:
1314

14-
def __init__(self, path=None):
15-
self.path = _default_path() if path is None else path
16-
17-
def _load(self):
18-
try:
19-
with open(self.path, 'r') as f:
20-
data = json.load(f)
15+
def __init__(self, path=None):
16+
self.path = _default_path() if path is None else path
17+
18+
def _load(self):
19+
try:
20+
with open(self.path, 'r') as f:
21+
data = json.load(f)
22+
self.set_data(data)
23+
except IOError:
24+
print(
25+
"Can't load ROUGE settings in '%s'. Check that the file "
26+
"exists or initialize it with 'setup_rouge.py'" % self.path)
27+
exit()
28+
29+
def _generate(self, data):
2130
self.set_data(data)
22-
except IOError:
23-
print("Can't load ROUGE settings in '%s'. Check that the file exists or initialize it with 'setup_rouge.py'" % self.path)
24-
exit()
25-
26-
27-
def _generate(self, data):
28-
self.set_data(data)
29-
with open(self.path, 'w') as f:
30-
json.dump(data, f, indent=2)
31-
32-
def set_data(self, data):
33-
"""Check & set data to `data`
34-
"""
35-
for param in PARAMS:
36-
if param not in data:
37-
raise ValueError('Missing parameter %d in data' % param)
38-
39-
for path_key in PATHS:
40-
path = data[path_key]
41-
if not os.path.exists(path):
42-
raise ValueError("Path does not exist %s" % path)
43-
self.data = data
31+
with open(self.path, 'w') as f:
32+
json.dump(data, f, indent=2)
33+
34+
def set_data(self, data):
35+
"""Check & set data to `data`
36+
"""
37+
for param in PARAMS:
38+
if param not in data:
39+
raise ValueError('Missing parameter %d in data' % param)
40+
41+
for path_key in PATHS:
42+
path = data[path_key]
43+
if not os.path.exists(path):
44+
raise ValueError("Path does not exist %s" % path)
45+
self.data = data

files2rouge/utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@
22
from __future__ import print_function
33
import os
44

5+
56
def mkdir(path):
67
os.mkdir(path)
78

9+
810
def mkdirs(paths):
911
for path in paths:
1012
mkdir(path)
1113

14+
1215
def tee(saveto, *args, **kwargs):
1316
"""Mimic the tee command, write on both stdout and file
1417
"""
1518
print(*args, **kwargs)
1619
if saveto is not None:
1720
print(file=saveto, *args, **kwargs)
1821

22+
1923
def split_files(model_file, system_file, model_dir, system_dir, eos="."):
20-
def outputs(line, f):
24+
def outputs(line, f):
2125
split_sen = " .\n".join(line.split(" %s " % eos))
2226
print(split_sen, end="", file=f)
2327

@@ -37,7 +41,6 @@ def outputs(line, f):
3741
break
3842
if len(line) == 0:
3943
continue
40-
44+
4145
with open("%s/s.%d.txt" % (system_dir, i), "w") as f:
4246
outputs(line, f)
43-

setup.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
from setuptools import setup, find_packages
22

3-
version="2.0.0"
3+
version = "2.0.0"
44
setup(
55
name="files2rouge",
66
version=version,
77
description="Calculating ROUGE score between two files (line-by-line)",
88
url="http://github.com/pltrdy/files2rouge",
9-
download_url="https://github.com/pltrdy/files2rouge/archive/%s.tar.gz" % version,
9+
download_url="https://github.com/pltrdy/files2rouge/archive/%s.tar.gz"
10+
% version,
1011
author="pltrdy",
1112
author_email="pltrdy@gmail.com",
12-
keywords=["NL", "CL", "natural language processing", "computational linguistics", "summarization"],
13+
keywords=["NL", "CL", "natural language processing",
14+
"computational linguistics", "summarization"],
1315
packages=find_packages(),
1416
classifiers=[
1517
"Intended Audience :: Science/Research",
1618
"Programming Language :: Python :: 3",
1719
"Topic :: Text Processing :: Linguistic"
18-
],
20+
],
1921
license="LICENCE.txt",
2022
long_description=open("README.md").read(),
2123

2224
entry_points={
23-
'console_scripts': [
24-
'files2rouge=files2rouge:main'
25-
]
25+
'console_scripts': [
26+
'files2rouge=files2rouge:main'
27+
]
2628
},
27-
install_requires = [
29+
install_requires=[
2830
],
2931
include_package_data=True,
3032
)

setup_rouge.py

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,38 @@
44
It has to be run before `setup.py`
55
66
"""
7-
from files2rouge import settings
87
import os
98
import shutil
10-
import sys
11-
12-
13-
def get_input(*args, **kwargs):
14-
# Support Python 2 and 3 input
15-
# Default to Python 3's input()
16-
fct = input
179

18-
# If this is Python 2, use raw_input()
19-
if sys.version_info[:2] <= (2, 7):
20-
fct = raw_input
21-
22-
return fct(*args, **kwargs)
10+
from files2rouge import settings
11+
from six.moves import input
2312

24-
def copy_ROUGE():
25-
home = os.environ['HOME']
2613

27-
src_ROUGE_root = "./files2rouge/RELEASE-1.5.5/"
14+
def copy_rouge():
15+
home = os.environ['HOME']
2816

29-
default_root = os.path.join(home, '.files2rouge/')
17+
src_rouge_root = "./files2rouge/RELEASE-1.5.5/"
3018

31-
print("files2rouge uses scripts and tools that will not be stored with the python package")
32-
path = get_input("where do you want to save it? [default: %s]" % default_root)
19+
default_root = os.path.join(home, '.files2rouge/')
3320

34-
if path == "":
35-
path = default_root
21+
print("files2rouge uses scripts and tools that will not be stored with "
22+
"the python package")
23+
path = input(
24+
"where do you want to save it? [default: %s]" % default_root)
3625

37-
ROUGE_data = os.path.join(path, "data")
38-
ROUGE_path = os.path.join(path, "ROUGE-1.5.5.pl")
26+
if path == "":
27+
path = default_root
3928

40-
print("Copying '%s' to '%s'" % (src_ROUGE_root, path))
41-
shutil.copytree(src_ROUGE_root, path)
29+
rouge_data = os.path.join(path, "data")
30+
rouge_path = os.path.join(path, "ROUGE-1.5.5.pl")
4231

32+
print("Copying '%s' to '%s'" % (src_rouge_root, path))
33+
shutil.copytree(src_rouge_root, path)
4334

44-
return {"ROUGE_path": ROUGE_path, "ROUGE_data": ROUGE_data}
35+
return {"ROUGE_path": rouge_path, "ROUGE_data": rouge_data}
4536

4637

4738
conf_path = "./files2rouge/settings.json"
4839
s = settings.Settings(path=conf_path)
49-
data = copy_ROUGE()
40+
data = copy_rouge()
5041
s._generate(data)
51-

0 commit comments

Comments
 (0)