用于压缩文本数据并将其存储为文本的库 [英] Library to compress text data and store it as text

查看:98
本文介绍了用于压缩文本数据并将其存储为文本的库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将网页存储在压缩文本文件(CSV)中。为了实现最佳压缩,我想提供一组1000个网页。然后,图书馆应该花一些时间为该内容创建最佳的词典。一个明显的字典条目可能是<!DOCTYPE HTML PUBLIC-// W3C // DTD HTML 4.01 // EN http://www.w3.org/TR/html4/strict .dtd> ,因为它几乎存在于所有网页中,所以可以存储为%1或类似的名称。通过创建这样的自定义词典,在我的情况下,压缩率应为99%。

I want to store web pages in compressed text files (CSV). To achieve the optimal compression, I would like to provide a set of 1000 web pages. The library should then spend some time creating the optimal "dictionary" for this content. One obvious "dictionary" entry could be <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">, which could get stored as %1 or something like that because it is present on almost all web pages. By creating a customized dictionary like this, the compression rates should be 99% in my case.

我的问题是,在具有MIT的Windows上是否存在用于执行此操作的库?是否存在类似的自由许可?如果没有,则建议您使用任何通用压缩库。我用zlib尝试了一下,但是它输出二进制数据。如果将二进制数据转换为文本,我担心结果可能会比原始文本更长。

My question is, does a library for doing this exist on Windows with MIT or similar liberal licensing exist? If not, are there any general purpose compression libaries you would recommend. I have tried a bit with zlib, but it outputs binary data. If I would convert this binary data into text, I am worried that the result might be longer than the original text.

编辑:我需要能够存储文本

I need to be able to store the text in CSV files and still be able to import them into a database or even Excel.

推荐答案


  1. 文本文件(不是二进制文件)有点太笼统了。如果您表示不能使用某些
    字节值(00,1A或其他值),则可以使用任何二进制方法+
    之类的东西,例如base64编码。 (尽管我建议使用协程演示源中更有效的方法
    )。



    具体来说,您可以使用任何通用压缩器来压缩
    基本文件,然后压缩基本文件+目标文件,然后对它们进行比较,然后d获得
    a字典压缩(二进制),然后可以使用base64或yenc将其转换为文本




    另外,有些编码器对此具有内置支持,例如

    http://compression.ru/ds/ppmtrain.rar

    http://code.google.com/p/lzham/

如果您实际上希望将普通短语替换为引用,并且
所有其他内容保持不变(有点暗示,但不等于文本输出),则
可以使用文本预处理器,例如:

http://xwrt.sourceforge.net/

http://compression.ru/ds/liptify.rar
(有更加公平)。

If you actually want to have common phrases replaced with references, and all other things left untouched (what is kinda implied, but not equals to "text output"), you can use text preprocessors like:
http://xwrt.sourceforge.net/
http://compression.ru/ds/liptify.rar (There were more afair).

也可以使用混合方法。您可以使用[1]中的通用LZ压缩器,例如lzma,然后将其熵编码替换为基于文本的内容。
例如,在 http://nishi.dreamhosters.com/u/lzmarec_v1_bin中。 rar
,其中有一个实用程序可以删除LZMA的熵编码,并且很容易将
的输出转换为文本。

Also a hybrid method is possible. You can use a general-purpose LZ compressor like in [1], for example lzma, then replace its entropy coding with something text-based. For example, in http://nishi.dreamhosters.com/u/lzmarec_v1_bin.rar there's an utility which removes LZMA's entropy coding, and its pretty easy to convert its output to text.

这篇关于用于压缩文本数据并将其存储为文本的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆