Giter VIP home page Giter VIP logo

epub_conversion's Introduction

epub conversion

Create text corpuses using epubs and wiki dumps. This is a python package with a Converter for epub and xml (wiki dumps) to text, lines, or Python generators.

Usage:

Epub usage

Book by book

To convert epubs to text files, usage is straightforward. First create a converter object:

converter = Converter("my_ebooks_folder/")

Then using this converter let's concatenate all the text within the ebooks into a single mega text file:

converter.convert("my_succinct_text_file.gz")

Line by line

You can also proceed line by line:

from epub_conversion.utils import open_book, convert_epub_to_lines

book = open_book("twilight.epub")

lines = convert_epub_to_lines(book)

Wikidump usage

Redirections

Suppose you are interested in all redirections in a given Wikipedia dump file that is still compressed, then you can access the dump as follows:

wiki = epub_conversion.wiki_decoder.almost_smart_open("enwiki.bz2")

Taking this dump as our input let us now use a generator to output all pairs of title and redirection title in this dump:

redirections = {redirect_from:redirect_to
	for redirect_from, redirect_to in epub_conversion.wiki_decoder.get_redirection_list(wiki)
}

Page text

Suppose you are interested in the lines within each page's text section only, then:

for line in epub_conversion.wiki_decoder.convert_wiki_to_lines(wiki):
	process_line( line )

See Also:

  • Wikipedia NER a Python module that uses epub_conversion to process Wikipedia dumps and output only the lines that contain page to page links, with the link anchor texts extracted, and all markup removed.

epub_conversion's People

Contributors

jonathanraiman avatar jwjimmy avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.