Giter Site home page Giter Site logo

chunker's Introduction

Chunker

A simple chunker for text data. It is useful for chunking text data into smaller parts for processing.

Features

  • Chunk text data into smaller parts
  • Don't split words in the middle
  • Limit the length of each chunk, and overlap between chunks
  • Clean up the chunks by removing leading and trailing whitespaces
  • Can remove new lines from the chunks
  • It also includes a function to chunk by sentence (ChunkSentences)

Installation

go get github.com/jonathanhecl/chunker

Usage

c := chunker.NewChunker(40, 10, chunker.DefaultSeparators, true, false)
chunks := c.Chunk("This is a test string. It is used to test the chunker. It is a very simple chunker.")

Result

Chunk  1  `This is a test string. It is used to` [ Length 36 ]
Chunk  2  `used to test the chunker. It is a` [ Length 33 ]
Chunk  3  `It is a very simple chunker.` [ Length 28 ]

Benchmark

goos: windows
goarch: amd64
pkg: github.com/jonathanhecl/chunker
cpu: 13th Gen Intel(R) Core(TM) i7-13700K
BenchmarkChunk_Example1KB/input_size_1024(256/32)-24              351300              3121 ns/op
BenchmarkChunk_Example1MB/input_size_1048576(512/64)-24              388           3065229 ns/op
BenchmarkChunk_Example5MB/input_size_5242880(512/64)-24               78          15126105 ns/op
BenchmarkChunk_Example10MB/input_size_10485760(1024/128)-24           37          27304095 ns/op

chunker's People

Contributors

jonathanhecl avatar

Watchers

 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.