charubya 0.2.0

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.
data/Cargo.toml ADDED
@@ -0,0 +1,7 @@
1
+ # This Cargo.toml is here to let externals tools (IDEs, etc.) know that this is
2
+ # a Rust project. Your extensions dependencies should be added to the Cargo.toml
3
+ # in the ext/ directory.
4
+
5
+ [workspace]
6
+ members = ["./ext/charubya"]
7
+ resolver = "2"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Marce Coll
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Charubya
2
+
3
+ This is a wrapper around the meilisearch [`Charabia`](https://github.com/meilisearch/charabia) library.
4
+
5
+ It doesn't implement the whole API, only what is needed for our usecase (segmentation).
6
+
7
+ It exposes a single method in the `Charabia` module: `segment`, it takes a string and returns
8
+ a list of strings.
9
+
10
+ ```ruby
11
+ Charubya.segment('昨日すき焼きを食べました')
12
+ # => ['昨日', 'すき焼き', 'を', '食べ', 'まし', 'た']
13
+ ```
14
+
15
+
16
+ ## Installation
17
+
18
+ Install the gem and add to the application's Gemfile by executing:
19
+
20
+ $ bundle add charubya
21
+
22
+ If bundler is not being used to manage dependencies, install the gem by executing:
23
+
24
+ $ gem install charubya
25
+
26
+ ## Development
27
+
28
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
29
+
30
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
31
+
32
+ ## Contributing
33
+
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/happyscribe/charabia-rb.
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ require "rb_sys/extensiontask"
13
+
14
+ task build: :compile
15
+
16
+ GEMSPEC = Gem::Specification.load("charubya.gemspec")
17
+
18
+ RbSys::ExtensionTask.new("charubya", GEMSPEC) do |ext|
19
+ ext.lib_dir = "lib/charubya"
20
+ end
21
+
22
+ task default: %i[compile test rubocop]
23
+
24
+
25
+ desc "Build native extension for a given platform (i.e. `rake 'native[x86_64-linux]'`)"
26
+ task :native, [:platform] do |_t, platform:|
27
+ build_native_gem platform
28
+ end
29
+
30
+ task :publish do |_t|
31
+ %w[x86_64-linux arm64-darwin x86_64-darwin].each do |arch|
32
+ build_native_gem arch
33
+ end
34
+ end
35
+
36
+ def build_native_gem(arch)
37
+ sh "bundle", "exec", "rb-sys-dock", "--platform", arch, "--build", "-r", "3.3,3.2,3.1"
38
+ end
39
+
@@ -0,0 +1,14 @@
1
+ [package]
2
+ name = "charubya"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ authors = ["Marce Coll <marce@dziban.net>"]
6
+ license = "MIT"
7
+ publish = false
8
+
9
+ [lib]
10
+ crate-type = ["cdylib"]
11
+
12
+ [dependencies]
13
+ magnus = { version = "0.6.2" }
14
+ charabia = "0.8.2"
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+ require "rb_sys/mkmf"
5
+
6
+ create_rust_makefile("charubya/charubya")
@@ -0,0 +1,17 @@
1
+ use magnus::{function, prelude::*, Error, Ruby};
2
+ use charabia::Segment;
3
+
4
+ fn segment(text: String) -> Vec<String> {
5
+ text
6
+ .as_str()
7
+ .segment_str()
8
+ .map(|s| s.to_owned())
9
+ .collect()
10
+ }
11
+
12
+ #[magnus::init]
13
+ fn init(ruby: &Ruby) -> Result<(), Error> {
14
+ let module = ruby.define_module("Charubya")?;
15
+ module.define_singleton_method("segment", function!(segment, 1))?;
16
+ Ok(())
17
+ }
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Charubya
4
+ VERSION = "0.2.0"
5
+ end
data/lib/charubya.rb ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "charubya/version"
4
+ begin
5
+ ruby_version = /\d+\.\d+/.match(RUBY_VERSION)
6
+ require_relative "charubya/#{ruby_version}/charubya"
7
+ rescue LoadError
8
+ require_relative "charubya/charubya"
9
+ end
10
+
11
+ module Charubya
12
+ class Error < StandardError; end
13
+ # Your code goes here...
14
+ end
data/shell.nix ADDED
@@ -0,0 +1,15 @@
1
+ { pkgs ? import <nixpkgs> {} }:
2
+ pkgs.mkShell {
3
+ buildInputs = [
4
+ pkgs.clang
5
+ pkgs.libclang
6
+ pkgs.rbspy
7
+ ];
8
+
9
+ shellHook = ''
10
+ export NODE_OPTIONS=--openssl-legacy-provider
11
+ export LD_LIBRARY_PATH="${pkgs.lib.makeLibraryPath([pkgs.libclang.lib])}"
12
+ export LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
13
+ source ~/.bashrc
14
+ '';
15
+ }
data/sig/charubya.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Charubya
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
data/test.rb ADDED
@@ -0,0 +1,6 @@
1
+ puts RUBY_VERSION
2
+ ruby_version = /\d+\.\d+/.match(RUBY_VERSION)
3
+ puts ruby_version
4
+ require 'charubya'
5
+ puts Charubya::VERSION
6
+ puts Charubya.segment('hola que tal')
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: charubya
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Marce Coll
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 1980-01-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - marce@dziban.net
16
+ executables: []
17
+ extensions:
18
+ - ext/charubya/Cargo.toml
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".rubocop.yml"
22
+ - CHANGELOG.md
23
+ - Cargo.lock
24
+ - Cargo.toml
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - ext/charubya/Cargo.toml
29
+ - ext/charubya/extconf.rb
30
+ - ext/charubya/src/lib.rs
31
+ - lib/charubya.rb
32
+ - lib/charubya/version.rb
33
+ - shell.nix
34
+ - sig/charubya.rbs
35
+ - test.rb
36
+ homepage: https://github.com/happyscribe/charubya
37
+ licenses:
38
+ - MIT
39
+ metadata:
40
+ allowed_push_host: https://rubygems.org
41
+ homepage_uri: https://github.com/happyscribe/charubya
42
+ source_code_uri: https://github.com/happyscribe/charubya
43
+ changelog_uri: https://github.com/happyscribe/charubya/CHANGELOG.md
44
+ rubygems_mfa_required: 'true'
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 3.0.0
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 3.3.11
59
+ requirements: []
60
+ rubygems_version: 3.5.15
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: A wrapper around meilisearch's charabia rust library
64
+ test_files: []