楼主: Lisrelchen
957 7

【Apache Tika】Get Tika Parsing up and Running in 5 Minutes [推广有奖]

  • 0关注
  • 62粉丝

VIP

已卖:4194份资源

院士

67%

还不是VIP/贵宾

-

TA的文库  其他...

Bayesian NewOccidental

Spatial Data Analysis

东西方数据挖掘

威望
0
论坛币
50288 个
通用积分
83.6906
学术水平
253 点
热心指数
300 点
信用等级
208 点
经验
41518 点
帖子
3256
精华
14
在线时间
766 小时
注册时间
2006-5-4
最后登录
2022-11-6

楼主
Lisrelchen 发表于 2017-3-12 07:15:41 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
Get Tika parsing up and running in 5 minutes

[size=17.3333339691162px]This page is a quick start guide showing how to add a new parser to Apache Tika. Following the simple steps listed below your new parser can be running in only 5 minutes.


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:running Minutes apache minute ning Create running minutes simple start

沙发
Lisrelchen 发表于 2017-3-12 07:16:36
  1. Add your MIME-Type

  2. Tika loads the core, standard MIME-Types from the file "org/apache/tika/mime/tika-mimetypes.xml", which comes from tika-core/src/main/resources/org/apache/tika/mime/tika-mimetypes.xml . If your new MIME-Type is a standard one which is missing from Tika, submit a patch for this file!

  3. If your MIME-Type needs adding, create a new file "org/apache/tika/mime/custom-mimetypes.xml" in your codebase. You should add to it something like this:

  4. <?xml version="1.0" encoding="UTF-8"?>
  5. <mime-info>
  6.    <mime-type type="application/hello">
  7.           <glob pattern="*.hi"/>
  8.    </mime-type>
  9. </mime-info>
复制代码

藤椅
Lisrelchen 发表于 2017-3-12 07:17:50
  1. Create your Parser class

  2. Now, you need to create your new parser. This is a class that must implement the Parser interface offered by Tika. Instead of implementing the Parser interface directly, it is recommended that you extend the abstract class AbstractParser if possible. AbstractParser handles translating between API changes for you.

  3. A very simple Tika Parser looks like this

  4. package org.apache.tika.parser.hello;

  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.util.Collections;
  8. import java.util.Set;

  9. import org.apache.tika.exception.TikaException;
  10. import org.apache.tika.metadata.Metadata;
  11. import org.apache.tika.mime.MediaType;
  12. import org.apache.tika.parser.ParseContext;
  13. import org.apache.tika.parser.AbstractParser;
  14. import org.apache.tika.sax.XHTMLContentHandler;
  15. import org.xml.sax.ContentHandler;
  16. import org.xml.sax.SAXException;

  17. public class HelloParser extends AbstractParser {

  18.         private static final Set<MediaType> SUPPORTED_TYPES = Collections.singleton(MediaType.application("hello"));
  19.         public static final String HELLO_MIME_TYPE = "application/hello";
  20.         
  21.         public Set<MediaType> getSupportedTypes(ParseContext context) {
  22.                 return SUPPORTED_TYPES;
  23.         }

  24.         public void parse(
  25.                         InputStream stream, ContentHandler handler,
  26.                         Metadata metadata, ParseContext context)
  27.                         throws IOException, SAXException, TikaException {

  28.                 metadata.set(Metadata.CONTENT_TYPE, HELLO_MIME_TYPE);
  29.                 metadata.set("Hello", "World");

  30.                 XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
  31.                 xhtml.startDocument();
  32.                 xhtml.endDocument();
  33.         }
  34. }
复制代码

板凳
auirzxp 学生认证  发表于 2017-3-12 07:28:17
提示: 作者被禁止或删除 内容自动屏蔽

报纸
MouJack007 发表于 2017-3-12 08:08:00
谢谢楼主分享!

地板
MouJack007 发表于 2017-3-12 08:08:18

7
钱学森64 发表于 2017-3-12 09:32:38
谢谢分享

8
franky_sas 发表于 2017-3-12 12:48:00

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-11 01:39