如何从tika-python lib设置TIKA_SERVER_ENDPOINT

时间:2019-06-30 19:20:19

标签: python apache-tika tika-server

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

1 个答案:

答案 0 :(得分: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