【问题标题】:Example of use libextractor3 from python从 python 中使用 libextractor3 的示例
【发布时间】:2023-03-29 12:18:01
【问题描述】:

我正在使用 python-extractor 来处理 libextractor3。我找不到任何例子。有没有人有任何文档或示例?

【问题讨论】:

    标签: python extract text-extraction


    【解决方案1】:

    python-extractor 的源包包含一个名为extract.py 的文件,其中有一个关于如何使用libextractor Python 绑定的小演示。

    extract.py 中的内容

    import extractor
    import sys
    from ctypes import *
    import struct
    
    xtract = extractor.Extractor()
    
    def print_k(xt, plugin, type, format, mime, data, datalen):
        mstr = cast (data, c_char_p)
    # FIXME: this ignores 'datalen', not that great...
    # (in general, depending on the mime type and format, only
    # the first 'datalen' bytes in 'data' should be used).
        if (format == extractor.EXTRACTOR_METAFORMAT_UTF8):
            print "%s - %s" % (xtract.keywordTypes()[type],  mstr.value)
        return 0
    
    
    for arg in sys.argv[1:]:
        print "Keywords from %s:" % arg
        xtract.extract(print_k, None, arg)
    

    为了更好地理解python-extractor,请阅读extractor.py中的源代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-21
      • 2011-11-21
      • 1970-01-01
      • 1970-01-01
      • 2014-07-30
      • 2012-01-15
      • 2014-06-18
      • 1970-01-01
      相关资源
      最近更新 更多