baran 0.1.9 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 51599bea086ef467f089b64f9252aa87a881c1889c776219695cec4922318be8
4
- data.tar.gz: b9c20815e90bf477c8b98b3fb2580013c791dcf1a387332552bf51ae33882768
3
+ metadata.gz: bb9c125ca01ed50e901bb91c66be9b775e8ada6724c021c9ade1520615b74991
4
+ data.tar.gz: 6c94f295e48eb79ed37c45f7f431cfd47a5e668499daaa5b13b0b76bd3ca58b9
5
5
  SHA512:
6
- metadata.gz: 8add731f1eb06baa85e7bfe495f11ce58be02b8ca6947f3f0bbfc1d7ac85cad3b693d24dc7f4f9124e5a357f784d5f42eb6875e36d7d2fb1aac09dda22dd8862
7
- data.tar.gz: 54e8924c8c2c86f524805b99cbeab0bb77a2784d72191fd35857def7450f9e9389176a63d684c4346c17787ad34bd7f3c9155b3803a6be2d0b22de24691a9ed2
6
+ metadata.gz: a4c6fba857e4a86b5a604c3241abe57798a523df601438e52ba4880426696041b4e5f950027bffe1e884fffd091c9ad0336f71011cdf42af019288cfbec80b37
7
+ data.tar.gz: 193ba60a25f5539c1d4b0d1d2bc6a552d1ade00cceab8a93fb11256e4ff5c7e92d78277159efa0a6908200ba015609fee83ec3de0a12aa280e10bf6f2e939541
data/CHANGELOG.md CHANGED
@@ -8,7 +8,6 @@
8
8
 
9
9
  - Update README
10
10
 
11
-
12
11
  ## [0.1.2] - 2023-05-28
13
12
 
14
13
  - Fix README
@@ -24,4 +23,8 @@
24
23
 
25
24
  ## [0.1.5] - 2023-06-02
26
25
 
27
- - Refactor
26
+ - Refactor
27
+
28
+ ## [0.1.10] - 2024-03-09
29
+
30
+ - https://github.com/kawakamimoeki/baran/pull/17
data/Gemfile CHANGED
@@ -5,6 +5,6 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in baran.gemspec
6
6
  gemspec
7
7
 
8
- gem "minitest", "~> 5.20"
8
+ gem "minitest", "~> 5.22"
9
9
 
10
- gem "rake", "~> 13.0"
10
+ gem "rake", "~> 13.1"
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- baran (0.1.9)
4
+ baran (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- minitest (5.20.0)
10
- rake (13.0.6)
9
+ minitest (5.22.3)
10
+ rake (13.1.0)
11
11
 
12
12
  PLATFORMS
13
13
  arm64-darwin-22
@@ -15,8 +15,8 @@ PLATFORMS
15
15
 
16
16
  DEPENDENCIES
17
17
  baran!
18
- minitest (~> 5.20)
19
- rake (~> 13.0)
18
+ minitest (~> 5.22)
19
+ rake (~> 13.1)
20
20
 
21
21
  BUNDLED WITH
22
22
  2.4.7
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ![v](https://badgen.net/rubygems/v/baran)
4
4
  ![dt](https://badgen.net/rubygems/dt/baran)
5
- ![license](https://badgen.net/github/license/moekidev/baran)
5
+ ![license](https://badgen.net/github/license/kawakamimoeki/baran)
6
6
 
7
7
  Text Splitter for Large Language Model datasets.
8
8
 
@@ -35,8 +35,8 @@ splitter = Baran::CharacterTextSplitter.new(
35
35
  chunk_overlap: 64,
36
36
  separator: "\n\n"
37
37
  )
38
- splitter.chunks(text)
39
- # => [{ cursor: 0, text: "..." }, ...]
38
+ splitter.chunks(text, metadata: { ... })
39
+ # => [{ cursor: 0, text: "...", metadata: { ... } }, ...]
40
40
  ```
41
41
 
42
42
  ### Recursive Character Text Splitter
@@ -47,8 +47,8 @@ Splitting by the specified characters recursively.
47
47
  splitter = Baran::RecursiveCharacterTextSplitter.new(
48
48
  separators: ["\n\n", "\n", " ", ""]
49
49
  )
50
- splitter.chunks(text)
51
- # => [{ cursor: 0, text: "..." }, ...]
50
+ splitter.chunks(text, metadata: { ... })
51
+ # => [{ cursor: 0, text: "...", metadata: { ... } }, ...]
52
52
  ```
53
53
 
54
54
  ### Markdown Text Splitter
@@ -57,8 +57,8 @@ Splitting by the Markdown descriptions.
57
57
 
58
58
  ```ruby
59
59
  splitter = Baran::MarkdownSplitter.new
60
- splitter.chunks(markdown)
61
- # => [{ cursor: 0, text: "..." }, ...]
60
+ splitter.chunks(markdown, metadata: { ... })
61
+ # => [{ cursor: 0, text: "...", metadata: { ... } }, ...]
62
62
  ```
63
63
 
64
64
  Split with the following priority.
@@ -88,7 +88,7 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
88
88
 
89
89
  ## Contributing
90
90
 
91
- Bug reports and pull requests are welcome on GitHub at https://github.com/moekidev/baran. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/moekidev/baran/blob/main/CODE_OF_CONDUCT.md).
91
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kawakamimoeki/baran. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/kawakamimoeki/baran/blob/main/CODE_OF_CONDUCT.md).
92
92
 
93
93
  ## License
94
94
 
@@ -96,4 +96,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
96
96
 
97
97
  ## Code of Conduct
98
98
 
99
- Everyone interacting in the Baran project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/moekidev/baran/blob/main/CODE_OF_CONDUCT.md).
99
+ Everyone interacting in the Baran project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/kawakamimoeki/baran/blob/main/CODE_OF_CONDUCT.md).
@@ -3,7 +3,7 @@ require_relative './recursive_character_text_splitter'
3
3
  module Baran
4
4
  class MarkdownSplitter < RecursiveCharacterTextSplitter
5
5
  def initialize(chunk_size: 1024, chunk_overlap: 64)
6
- @separators = [
6
+ separators = [
7
7
  "\n# ", # h1
8
8
  "\n## ", # h2
9
9
  "\n### ", # h3
@@ -19,7 +19,7 @@ module Baran
19
19
  " ", # space
20
20
  "" # empty
21
21
  ]
22
- super(chunk_size: chunk_size, chunk_overlap: chunk_overlap)
22
+ super(chunk_size: chunk_size, chunk_overlap: chunk_overlap, separators: separators)
23
23
  end
24
24
  end
25
- end
25
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Baran
4
+ class SentenceTextSplitter < TextSplitter
5
+ def initialize(chunk_size: 1024, chunk_overlap: 64)
6
+ super(chunk_size: chunk_size, chunk_overlap: chunk_overlap)
7
+ end
8
+
9
+ def splitted(text)
10
+ # Use a regex to split text based on the specified sentence-ending characters followed by whitespace
11
+ text.scan(/[^.!?]+[.!?]+(?:\s+|\z)/).map(&:strip)
12
+ end
13
+ end
14
+ end
@@ -22,7 +22,7 @@ module Baran
22
22
  chunk = { text: chunk, cursor: cursor }
23
23
  chunk[:metadata] = metadata if metadata
24
24
  chunks << chunk
25
- cursor += chunk.length
25
+ cursor += chunk[:text].length
26
26
  end
27
27
 
28
28
  chunks
data/lib/baran/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Baran
4
- VERSION = "0.1.9"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/baran.rb CHANGED
@@ -5,6 +5,7 @@ require_relative "baran/text_splitter"
5
5
  require_relative "baran/markdown_splitter"
6
6
  require_relative "baran/recursive_character_text_splitter"
7
7
  require_relative "baran/character_text_splitter"
8
+ require_relative "baran/sentence_text_splitter"
8
9
 
9
10
  module Baran
10
11
  class Error < StandardError; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baran
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Moeki Kawakami
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-26 00:00:00.000000000 Z
11
+ date: 2024-10-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Text Splitter for Large Language Model Datasets.
14
14
  email:
@@ -30,6 +30,7 @@ files:
30
30
  - lib/baran/character_text_splitter.rb
31
31
  - lib/baran/markdown_splitter.rb
32
32
  - lib/baran/recursive_character_text_splitter.rb
33
+ - lib/baran/sentence_text_splitter.rb
33
34
  - lib/baran/text_splitter.rb
34
35
  - lib/baran/version.rb
35
36
  - sig/baran.rbs