langdetect-ruby 0.1.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.
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LinguaRuby
4
+ class Result
5
+ attr_reader :language, :confidence, :name
6
+
7
+ LANGUAGE_NAMES = {
8
+ id: "Indonesian",
9
+ en: "English",
10
+ ms: "Malay",
11
+ jv: "Javanese",
12
+ su: "Sundanese",
13
+ nl: "Dutch",
14
+ ar: "Arabic",
15
+ zh: "Chinese",
16
+ ja: "Japanese",
17
+ ko: "Korean",
18
+ fr: "French",
19
+ de: "German",
20
+ es: "Spanish",
21
+ pt: "Portuguese",
22
+ it: "Italian",
23
+ ru: "Russian",
24
+ tr: "Turkish",
25
+ pl: "Polish",
26
+ sv: "Swedish",
27
+ da: "Danish",
28
+ no: "Norwegian",
29
+ fi: "Finnish",
30
+ th: "Thai",
31
+ vi: "Vietnamese",
32
+ tl: "Tagalog",
33
+ hi: "Hindi"
34
+ }.freeze
35
+
36
+ def initialize(language:, confidence:)
37
+ @language = language.to_sym
38
+ @confidence = confidence
39
+ @name = LANGUAGE_NAMES[@language] || @language.to_s.upcase
40
+ end
41
+
42
+ def to_h
43
+ { language: @language, confidence: @confidence, name: @name }
44
+ end
45
+
46
+ def to_s
47
+ "#{@name} (#{@language}): #{(@confidence * 100).round(1)}%"
48
+ end
49
+
50
+ def <=>(other)
51
+ other.confidence <=> @confidence
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LinguaRuby
4
+ VERSION = "0.1.1"
5
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lingua_ruby/version"
4
+ require_relative "lingua_ruby/configuration"
5
+ require_relative "lingua_ruby/ngram"
6
+ require_relative "lingua_ruby/result"
7
+ require_relative "lingua_ruby/profile"
8
+ require_relative "lingua_ruby/profile_loader"
9
+ require_relative "lingua_ruby/detector"
10
+
11
+ module LinguaRuby
12
+ class Error < StandardError; end
13
+
14
+ class << self
15
+ def configuration
16
+ @configuration ||= Configuration.new
17
+ end
18
+
19
+ def configure
20
+ yield(configuration)
21
+ end
22
+
23
+ def reset_configuration!
24
+ @configuration = Configuration.new
25
+ @default_detector = nil
26
+ end
27
+
28
+ def detect(text)
29
+ default_detector.detect(text)
30
+ end
31
+
32
+ def detect_all(text)
33
+ default_detector.detect_all(text)
34
+ end
35
+
36
+ def detect_batch(texts)
37
+ raise ArgumentError, "texts must be an Array" unless texts.is_a?(Array)
38
+
39
+ detector = default_detector
40
+ texts.map { |text| detector.detect(text) }
41
+ end
42
+
43
+ private
44
+
45
+ def default_detector
46
+ @default_detector ||= Detector.new
47
+ end
48
+ end
49
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: langdetect-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Johannes Dwi Cahyo
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: minitest
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '5.0'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '5.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '13.0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '13.0'
40
+ description: Pure Ruby language detection library using character n-gram frequency
41
+ profiles. Detects 50+ languages with high accuracy.
42
+ email:
43
+ - johannes@example.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - CHANGELOG.md
49
+ - LICENSE
50
+ - README.md
51
+ - Rakefile
52
+ - langdetect-ruby.gemspec
53
+ - lib/lingua_ruby.rb
54
+ - lib/lingua_ruby/configuration.rb
55
+ - lib/lingua_ruby/detector.rb
56
+ - lib/lingua_ruby/ngram.rb
57
+ - lib/lingua_ruby/profile.rb
58
+ - lib/lingua_ruby/profile_loader.rb
59
+ - lib/lingua_ruby/profiles/ar.json
60
+ - lib/lingua_ruby/profiles/en.json
61
+ - lib/lingua_ruby/profiles/id.json
62
+ - lib/lingua_ruby/profiles/ja.json
63
+ - lib/lingua_ruby/profiles/jv.json
64
+ - lib/lingua_ruby/profiles/ko.json
65
+ - lib/lingua_ruby/profiles/ms.json
66
+ - lib/lingua_ruby/profiles/nl.json
67
+ - lib/lingua_ruby/profiles/su.json
68
+ - lib/lingua_ruby/profiles/zh.json
69
+ - lib/lingua_ruby/result.rb
70
+ - lib/lingua_ruby/version.rb
71
+ homepage: https://github.com/johannesdwicahyo/lingua-ruby
72
+ licenses:
73
+ - MIT
74
+ metadata:
75
+ homepage_uri: https://github.com/johannesdwicahyo/lingua-ruby
76
+ source_code_uri: https://github.com/johannesdwicahyo/lingua-ruby
77
+ changelog_uri: https://github.com/johannesdwicahyo/lingua-ruby/blob/main/CHANGELOG.md
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 3.0.0
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.6.9
93
+ specification_version: 4
94
+ summary: Language detection for Ruby using n-gram profiles
95
+ test_files: []