如何在 Microsoft Windows 上安装 Python 包pyruge? [英] How to install the Python package pyrouge on Microsoft Windows?
问题描述
我想在 Microsoft 上使用 python 包
要在 Path
系统环境变量中添加 perl:
最后,为了避免这种错误:
一种方法是将C:Strawberrycin*.dll
复制到C:Strawberryperlin*.dll
.>
6) 防止在运行 pyrouge
时出现以下错误信息:
Cannot open exception db file for reading: C:Anacondapyrouge-master oolsROUGE-1.5.5data/WordNet-2.0.exc.db
你应该删除RELEASE-1.5.5dataWordNet-2.0.exc.db
,然后从cmd.exe
:
cd RELEASE-1.5.5dataperl WordNet-2.0-Exceptions/buildExeptionDB.pl ./WordNet-2.0-Exceptions ./smart_common_words.txt ./WordNet-2.0.exc.db
7) 打开 C:Anacondaenvspy35Libsite-packagespyrougeRouge155.py
(或安装 pyrouge
的任何地方),转到函数 defevaluate(self, system_id=1, rouge_args=None)
(在我写这个答案时它在第 319 行),并添加 command.insert(0, 'perl')
就在 self.log.info("Running ROUGE with command {}".format(" ".join(command)))
之前.(如果你不这样做,你会得到 OSError: [WinError 193] %1 is not a valid Win32 application
,如果你不这样做,你会得到同样的错误信息不要做前面的一些步骤).
8) 那时 pyrouge
应该可以正常工作.不要尝试运行 python -mpyrouge.test
,它是 错误.相反,您可以按如下方式对其进行测试:
some_folder:│ 胭脂.py│├───model_summaries│ text.A.001.txt│└────system_summaries文本.001.txt
rouge.py
包含:
frompyrouge import Rouge155r = Rouge155()r.system_dir = 'system_summaries'r.model_dir = 'model_summaries'r.system_filename_pattern = 'text.(d+).txt'r.model_filename_pattern = 'text.[A-Z].#ID#.txt'输出 = r.convert_and_evaluate()打印(输出)output_dict = r.output_to_dict(输出)
text.A.001.txt
包含:
预处理我的摘要,然后运行 ROUGE
text.001.txt
包含:
我只想预处理我的摘要,然后自己运行 ROUGE
运行rouge.py
时的输出:
2017-10-31 21:55:37,239 [MainThread] [INFO] 写总结.2017-10-31 21:55:37,249 [MainThread] [INFO] 处理摘要.将系统文件保存到 C:UsersFranckyAppDataLocalTemp mpmh72hoxasystem,将模型文件保存到 C:UsersFranckyAppDataLocalTemp mpmh72hoxamodel.2017-10-31 21:55:37,249 [MainThread] [INFO] 处理 system_summaries 中的文件.2017-10-31 21:55:37,249 [MainThread] [INFO] 处理 text.001.txt.2017-10-31 21:55:37,249 [MainThread] [INFO] 将处理过的文件保存到 C:UsersFranckyAppDataLocalTemp mpmh72hoxasystem.2017-10-31 21:55:37,249 [MainThread] [INFO] 处理 model_summaries 中的文件.2017-10-31 21:55:37,249 [MainThread] [INFO] 处理 text.A.001.txt.2017-10-31 21:55:37,249 [MainThread] [INFO] 将处理过的文件保存到 C:UsersFranckyAppDataLocalTemp mpmh72hoxamodel.2017-10-31 21:55:37,249 [MainThread] [INFO] 将 ROUGE 配置写入 C:UsersFranckyAppDataLocalTemp mpgx71qygq
ouge_conf.xml2017-10-31 21:55:37,249 [MainThread] [INFO] 使用命令 perl C:Anacondapyrouge-master oolsROUGE-1.5.5ROUGE-1.5.5.pl -e C: 运行 ROUGEAnacondapyrouge-master oolsROUGE-1.5.5data -c 95 -2 -1 -U -r 1000 -n 4 -w 1.2 -a -m C:UsersFranckyAppDataLocalTemp mpgx71qygq
ouge_conf.xml命令:['C:\Anaconda\pyrouge-master\tools\ROUGE-1.5.5\ROUGE-1.5.5.pl', '-e', 'C:\Anaconda\pyrouge-master\tools\ROUGE-1.5.5\data', '-c', '95', '-2', '-1', '-U', '-r', '1000', '-n', '4', '-w', '1.2', '-a', '-m', 'C:\Users\Francky\AppData\Local\Temp\tmpgx71qygq\rouge_conf.xml']---------------------------------------------1 ROUGE-1 Average_R: 1.00000 (95%-conf.int. 1.00000 - 1.00000)1 ROUGE-1 Average_P: 0.42857 (95%-conf.int. 0.42857 - 0.42857)1 ROUGE-1 Average_F: 0.60000 (95%-conf.int. 0.60000 - 0.60000)---------------------------------------------1 ROUGE-2 Average_R: 0.80000 (95%-conf.int. 0.80000 - 0.80000)1 ROUGE-2 Average_P: 0.30769 (95%-conf.int. 0.30769 - 0.30769)1 ROUGE-2 Average_F: 0.44444 (95%-conf.int. 0.44444 - 0.44444)---------------------------------------------1 ROUGE-3 Average_R: 0.50000 (95%-conf.int. 0.50000 - 0.50000)1 ROUGE-3 Average_P: 0.16667 (95%-conf.int. 0.16667 - 0.16667)1 ROUGE-3 Average_F: 0.25000 (95%-conf.int. 0.25000 - 0.25000)---------------------------------------------1 ROUGE-4 Average_R: 0.00000 (95%-conf.int. 0.00000 - 0.00000)1 ROUGE-4 Average_P: 0.00000 (95%-conf.int. 0.00000 - 0.00000)1 ROUGE-4 Average_F: 0.00000 (95%-conf.int. 0.00000 - 0.00000)---------------------------------------------1 ROUGE-L Average_R: 1.00000 (95%-conf.int. 1.00000 - 1.00000)1 ROUGE-L Average_P: 0.42857 (95%-conf.int. 0.42857 - 0.42857)1 ROUGE-L Average_F: 0.60000 (95%-conf.int. 0.60000 - 0.60000)---------------------------------------------1 ROUGE-W-1.2 Average_R: 0.69883 (95%-conf.int. 0.69883 - 0.69883)1 ROUGE-W-1.2 Average_P: 0.42857 (95%-conf.int. 0.42857 - 0.42857)1 ROUGE-W-1.2 Average_F: 0.53131 (95%-conf.int. 0.53131 - 0.53131)---------------------------------------------1 ROUGE-S* Average_R: 1.00000 (95%-conf.int. 1.00000 - 1.00000)1 ROUGE-S* 平均值_P:0.16484(95%-conf.int. 0.16484 - 0.16484)1 ROUGE-S* 平均值_F:0.28303(95%-conf.int. 0.28303 - 0.28303)---------------------------------------------1 ROUGE-SU* Average_R: 1.00000 (95%-conf.int. 1.00000 - 1.00000)1 ROUGE-SU* Average_P: 0.19231 (95%-conf.int. 0.19231 - 0.19231)1 ROUGE-SU* Average_F: 0.32258 (95%-conf.int. 0.32258 - 0.32258)
<小时>
如果不执行第3步,运行frompyruge import Rouge155;r = Rouge155()
会得到如下错误信息
回溯(最近一次调用最后一次):文件C:UsersFranckDocuments
ouge.py",第 8 行,在 <module>r = Rouge155()文件C:Anacondaenvspy35libsite-packagespyrougeRouge155.py",第 88 行,在 __init__ 中self.__set_rouge_dir(rouge_dir)文件C:Anacondaenvspy35libsite-packagespyrougeRouge155.py",第 402 行,在 __set_rouge_dirself._home_dir = self.__get_rouge_home_dir_from_settings()文件C:Anacondaenvspy35libsite-packagespyrougeRouge155.py",第 416 行,在 __get_rouge_home_dir_from_settings使用 open(self._settings_file) 作为 f:FileNotFoundError: [Errno 2] 没有这样的文件或目录:'C:\Users\Franck\AppData\Roaming\pyrouge\settings.ini'
I want to use the python package pyrouge
on Microsoft Windows. The package doesn't give any instructions on how to install it on Microsoft Windows. How can I do so?
The following instructions were tested on Windows 7 SP1 x64 Ultimate and python 3.5 x64 (Anaconda).
1) In the cmd.exe
, run
pip install pyrouge
2) Download ROUGE-1.5.5
. You may download it from https://github.com/andersjo/pyrouge/tree/master/tools/ROUGE-1.5.5
3) pyrouge
comes with a python script named pyrouge_set_rouge_path
(it has no file extension for some reason), which you need to run in order to point pyrouge
to the directory where ROUGE-1.5.5
is located. You need to locate pyrouge_set_rouge_path
, which is typically in the python Scripts
directory.
Run the following command from cmd.exe
, appropriately replacing the directories for pyrouge_set_rouge_path
and ROUGE-1.5.5
:
python C:Anacondaenvspy35Scriptspyrouge_set_rouge_path C:pyrouge-master oolsROUGE-1.5.5
4) pyrouge
should now be able to initialize a Rouge155
object. You can run the following python script, it should give no error:
from pyrouge import Rouge155
r = Rouge155()
5) If you don't have perl.exe
, you need to install it (because pyrouge is just a wrapper around the original ROUGE script, which is written in Perl)You can install http://strawberryperl.com
Make sure the perl.exe
binary is in your Path
system environment variable, e.g. using which perl
:
To add perl in your Path
system environment variable:
Lastly, to avoid this kind of error:
One way is to copy C:Strawberrycin*.dll
to C:Strawberryperlin*.dll
.
6) To prevent the following error message when running pyrouge
:
Cannot open exception db file for reading: C:Anacondapyrouge-master oolsROUGE-1.5.5data/WordNet-2.0.exc.db
You should remove RELEASE-1.5.5dataWordNet-2.0.exc.db
, then from cmd.exe
:
cd RELEASE-1.5.5data
perl WordNet-2.0-Exceptions/buildExeptionDB.pl ./WordNet-2.0-Exceptions ./smart_common_words.txt ./WordNet-2.0.exc.db
7) Open C:Anacondaenvspy35Libsite-packagespyrougeRouge155.py
(or wherever you installed pyrouge
), go to the function def evaluate(self, system_id=1, rouge_args=None)
(it's at line 319 at the time I am writing this answer), and add command.insert(0, 'perl ')
right before self.log.info("Running ROUGE with command {}".format(" ".join(command)))
. (If you don't do it, you'll get OSError: [WinError 193] %1 is not a valid Win32 application
, which is the same error message as what you would get for if you don't do some of the previous steps).
8) At that point pyrouge
should work fine. Don't try to run python -m pyrouge.test
, it is buggy. Instead, you can test it as follows:
some_folder:
│ rouge.py
│
├───model_summaries
│ text.A.001.txt
│
└───system_summaries
text.001.txt
rouge.py
contains:
from pyrouge import Rouge155
r = Rouge155()
r.system_dir = 'system_summaries'
r.model_dir = 'model_summaries'
r.system_filename_pattern = 'text.(d+).txt'
r.model_filename_pattern = 'text.[A-Z].#ID#.txt'
output = r.convert_and_evaluate()
print(output)
output_dict = r.output_to_dict(output)
text.A.001.txt
contains:
preprocess my summaries, then run ROUGE
text.001.txt
contains:
I only want to preprocess my summaries and then run ROUGE on my own
Output when running rouge.py
:
2017-10-31 21:55:37,239 [MainThread ] [INFO ] Writing summaries.
2017-10-31 21:55:37,249 [MainThread ] [INFO ] Processing summaries. Saving system files to C:UsersFranckyAppDataLocalTemp mpmh72hoxasystem and model files to C:UsersFranckyAppDataLocalTemp mpmh72hoxamodel.
2017-10-31 21:55:37,249 [MainThread ] [INFO ] Processing files in system_summaries.
2017-10-31 21:55:37,249 [MainThread ] [INFO ] Processing text.001.txt.
2017-10-31 21:55:37,249 [MainThread ] [INFO ] Saved processed files to C:UsersFranckyAppDataLocalTemp mpmh72hoxasystem.
2017-10-31 21:55:37,249 [MainThread ] [INFO ] Processing files in model_summaries.
2017-10-31 21:55:37,249 [MainThread ] [INFO ] Processing text.A.001.txt.
2017-10-31 21:55:37,249 [MainThread ] [INFO ] Saved processed files to C:UsersFranckyAppDataLocalTemp mpmh72hoxamodel.
2017-10-31 21:55:37,249 [MainThread ] [INFO ] Written ROUGE configuration to C:UsersFranckyAppDataLocalTemp mpgx71qygq
ouge_conf.xml
2017-10-31 21:55:37,249 [MainThread ] [INFO ] Running ROUGE with command perl C:Anacondapyrouge-master oolsROUGE-1.5.5ROUGE-1.5.5.pl -e C:Anacondapyrouge-master oolsROUGE-1.5.5data -c 95 -2 -1 -U -r 1000 -n 4 -w 1.2 -a -m C:UsersFranckyAppDataLocalTemp mpgx71qygq
ouge_conf.xml
command: ['C:\Anaconda\pyrouge-master\tools\ROUGE-1.5.5\ROUGE-1.5.5.pl', '-e', 'C:\Anaconda\pyrouge-master\tools\ROUGE-1.5.5\data', '-c', '95', '-2', '-1', '-U', '-r', '1000', '-n', '4', '-w', '1.2', '-a', '-m', 'C:\Users\Francky\AppData\Local\Temp\tmpgx71qygq\rouge_conf.xml']
---------------------------------------------
1 ROUGE-1 Average_R: 1.00000 (95%-conf.int. 1.00000 - 1.00000)
1 ROUGE-1 Average_P: 0.42857 (95%-conf.int. 0.42857 - 0.42857)
1 ROUGE-1 Average_F: 0.60000 (95%-conf.int. 0.60000 - 0.60000)
---------------------------------------------
1 ROUGE-2 Average_R: 0.80000 (95%-conf.int. 0.80000 - 0.80000)
1 ROUGE-2 Average_P: 0.30769 (95%-conf.int. 0.30769 - 0.30769)
1 ROUGE-2 Average_F: 0.44444 (95%-conf.int. 0.44444 - 0.44444)
---------------------------------------------
1 ROUGE-3 Average_R: 0.50000 (95%-conf.int. 0.50000 - 0.50000)
1 ROUGE-3 Average_P: 0.16667 (95%-conf.int. 0.16667 - 0.16667)
1 ROUGE-3 Average_F: 0.25000 (95%-conf.int. 0.25000 - 0.25000)
---------------------------------------------
1 ROUGE-4 Average_R: 0.00000 (95%-conf.int. 0.00000 - 0.00000)
1 ROUGE-4 Average_P: 0.00000 (95%-conf.int. 0.00000 - 0.00000)
1 ROUGE-4 Average_F: 0.00000 (95%-conf.int. 0.00000 - 0.00000)
---------------------------------------------
1 ROUGE-L Average_R: 1.00000 (95%-conf.int. 1.00000 - 1.00000)
1 ROUGE-L Average_P: 0.42857 (95%-conf.int. 0.42857 - 0.42857)
1 ROUGE-L Average_F: 0.60000 (95%-conf.int. 0.60000 - 0.60000)
---------------------------------------------
1 ROUGE-W-1.2 Average_R: 0.69883 (95%-conf.int. 0.69883 - 0.69883)
1 ROUGE-W-1.2 Average_P: 0.42857 (95%-conf.int. 0.42857 - 0.42857)
1 ROUGE-W-1.2 Average_F: 0.53131 (95%-conf.int. 0.53131 - 0.53131)
---------------------------------------------
1 ROUGE-S* Average_R: 1.00000 (95%-conf.int. 1.00000 - 1.00000)
1 ROUGE-S* Average_P: 0.16484 (95%-conf.int. 0.16484 - 0.16484)
1 ROUGE-S* Average_F: 0.28303 (95%-conf.int. 0.28303 - 0.28303)
---------------------------------------------
1 ROUGE-SU* Average_R: 1.00000 (95%-conf.int. 1.00000 - 1.00000)
1 ROUGE-SU* Average_P: 0.19231 (95%-conf.int. 0.19231 - 0.19231)
1 ROUGE-SU* Average_F: 0.32258 (95%-conf.int. 0.32258 - 0.32258)
If you don't perform step 3, running from pyrouge import Rouge155; r = Rouge155()
will get the following error message
Traceback (most recent call last):
File "C:UsersFranckDocuments
ouge.py", line 8, in <module>
r = Rouge155()
File "C:Anacondaenvspy35libsite-packagespyrougeRouge155.py", line 88, in __init__
self.__set_rouge_dir(rouge_dir)
File "C:Anacondaenvspy35libsite-packagespyrougeRouge155.py", line 402, in __set_rouge_dir
self._home_dir = self.__get_rouge_home_dir_from_settings()
File "C:Anacondaenvspy35libsite-packagespyrougeRouge155.py", line 416, in __get_rouge_home_dir_from_settings
with open(self._settings_file) as f:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\Franck\AppData\Roaming\pyrouge\settings.ini'
这篇关于如何在 Microsoft Windows 上安装 Python 包pyruge?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!