【发布时间】:2023-03-29 12:18:01
【问题描述】:
我正在使用 python-extractor 来处理 libextractor3。我找不到任何例子。有没有人有任何文档或示例?
【问题讨论】:
标签: python extract text-extraction
我正在使用 python-extractor 来处理 libextractor3。我找不到任何例子。有没有人有任何文档或示例?
【问题讨论】:
标签: python extract text-extraction
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中的源代码。
【讨论】: