如何从tika-python lib设置TIKA_SERVER_ENDPOINT

问题描述 投票:0回答:1

https://github.com/chrismattmann/tika-python的文档中出色的lib tika-python显示,可以设置tika_server.jar文件以避免每次使用该算法时进行下载。有没有人这样做并可以发布配置?

首次使用该算法时,将下载tika_server.jar,以便lib可以使用它。我想通过在本地设置文件来避免此下载。

从PDF提取文本

def extraiPDF(f):
    resultado = []
    tika.TikaClientOnly = True
    raw = parser.from_file(f)
    metadados = raw["metadata"]
    conteudo  = raw["content"] 
    conteudo  = (conteudo).replace('\n', '').replace('\r\n', '').replace('\r', '').replace('\\', '').replace('\t', ' ')
    resultado.append(conteudo)
    resultado.append(metadados)
    return resultado
python apache-tika tika-server
1个回答
1
投票

下载后要运行tika服务器,请执行此bash脚本。

#!/bin/bash

TIKA_PORT=9998
TIKA_HOST=localhost
CURRENT_USER=$(whoami) 
TIKA_JAR_URL="http://search.maven.org/remotecontent?filepath=org/apache/tika/tika-server/1.19/tika-server-1.19.jar"
TIKA_WORKSPACE=$HOME/tika
TIKA_FILE_NAME="tika_server.jar"

echo -e "Current user: $CURRENT_USER"

if [ ! -f $TIKA_WORKSPACE/$TIKA_FILE_NAME ]; then
    echo -e "Downloading tika-server.jar"

    if [ ! -d "$TIKA_WORKSPACE" ]; then
        echo -e "making tika workspace"
        mkdir $TIKA_WORKSPACE
    fi

    wget -c $TIKA_JAR_URL -O $TIKA_WORKSPACE/$TIKA_FILE_NAME 
fi

echo -e "## Setting environment vars"

export TIKA_SERVER_ENDPOINT="http://$TIKA_HOST:$TIKA_PORT"
echo -e "TIKA_SERVER_ENDPOINT to $TIKA_SERVER_ENDPOINT"

export TIKA_CLIENT_ONLY=True
echo -e "TIKA_CLIENT_ONLY to $TIKA_CLIENT_ONLY"

echo -e "## Starting tika server on: $TIKA_WORKSPACE"
cd $TIKA_WORKSPACE

java -jar tika_server.jar -h $TIKA_HOST
© www.soinside.com 2019 - 2024. All rights reserved.