ba-normalizedsearch 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +26 -0
- data/LICENSE.md +10 -0
- data/README.md +34 -0
- data/Rakefile +17 -0
- data/exe/normsearch +6 -0
- data/lib/ba-normalizedsearch/cli.rb +12 -0
- data/lib/ba-normalizedsearch/version.rb +5 -0
- data/lib/ba-normalizedsearch.rb +66 -0
- data/sig/ba-normalizedsearch.rbs +4 -0
- metadata +74 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3958f87c10b2fe41d41a4565fc7fef87c5b03c4f3e1b5b4e5809afef6fca2e0e
|
4
|
+
data.tar.gz: 5cd79e45ebe5c988763aa4afa0a703da8c378a11bb1773073047460174f01008
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7569888a9ba9b2049061eb3e02db6401ac36d3313454fe5a8477eacff12851d095169a052222cfa6d9d29bcfae10ebd062e677173996167053264c554e1c76ad
|
7
|
+
data.tar.gz: e2e7d4ff7111431110060bb137d69c49bff84294ac2351302cd6be9bc3d4a837dc3dee154460e8a8a5bf741e352292c871bb2c0bf414ababdb885be46a5b713c
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ba-normalizedsearch (0.1.2)
|
5
|
+
thor (~> 1.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
minitest (5.16.3)
|
11
|
+
rake (13.0.6)
|
12
|
+
thor (1.2.1)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
x86_64-linux
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
ba-normalizedsearch!
|
19
|
+
minitest (~> 5.0)
|
20
|
+
rake (~> 13.0)
|
21
|
+
|
22
|
+
RUBY VERSION
|
23
|
+
ruby 2.7.4p191
|
24
|
+
|
25
|
+
BUNDLED WITH
|
26
|
+
2.3.14
|
data/LICENSE.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 Sächsische Akademie der Wissenschaften
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
10
|
+
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# ba-normalizedsearch
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Install the gem and add to the application's Gemfile by executing:
|
6
|
+
|
7
|
+
$ bundle add ba-normalizedsearch --git=https://git.saw-leipzig.de/bibarab/misc/ba-normalizedsearch.git
|
8
|
+
|
9
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
10
|
+
|
11
|
+
$ git clone https://git.saw-leipzig.de/bibarab/misc/ba-normalizedsearch.git
|
12
|
+
$ gem install ba-normalizedsearch/*.gem
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
### In your code
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
require 'ba-normalizedsearch'
|
20
|
+
@search = BANormalizedSearch::Search.new
|
21
|
+
normalized_string = @search.normalize "some string"
|
22
|
+
```
|
23
|
+
|
24
|
+
### On the command line
|
25
|
+
|
26
|
+
```bash
|
27
|
+
normsearch normalize "some string"
|
28
|
+
```
|
29
|
+
|
30
|
+
## Development
|
31
|
+
|
32
|
+
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.
|
33
|
+
|
34
|
+
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 `rake gem` which will create a new .gem file, remove the older ones if any, commit your changes and `git tag name-for-new-release`, then `git push`.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "build a new .gem file"
|
13
|
+
task :gem do
|
14
|
+
`gem build *.gemspec`
|
15
|
+
end
|
16
|
+
|
17
|
+
task default: :test
|
data/exe/normsearch
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require_relative '../ba-normalizedsearch'
|
3
|
+
|
4
|
+
module BANormalizedSearch
|
5
|
+
class CLI < Thor
|
6
|
+
desc 'normalize <string>', 'output a normalized version of the input string'
|
7
|
+
def normalize s
|
8
|
+
@search = BANormalizedSearch::Search.new
|
9
|
+
puts @search.normalize s
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "ba-normalizedsearch/version"
|
4
|
+
|
5
|
+
module BANormalizedSearch
|
6
|
+
class Error < StandardError; end
|
7
|
+
|
8
|
+
class Search
|
9
|
+
def initialize wordlist=[]
|
10
|
+
@wordlist = wordlist
|
11
|
+
# tatweel fathatan dammatan kasratan fatha damma kasra shadda sukun
|
12
|
+
@vocals = ["\u0640", "\u064b", "\u064c", "\u064d", "\u064e", "\u064f", "\u0650", "\u0651", "\u0652"]
|
13
|
+
@re_vocals_delete = "[" + @vocals.join("") + "]"
|
14
|
+
@waw = "و"
|
15
|
+
@abd = "عبد"
|
16
|
+
@din = "الدين"
|
17
|
+
@al = "ال"
|
18
|
+
@lah = "له"
|
19
|
+
end
|
20
|
+
|
21
|
+
def normalize s
|
22
|
+
s = s.unicode_normalize(:nfc)
|
23
|
+
s = s.gsub(/#{@re_vocals_delete}/ , "") # delete vowels
|
24
|
+
s = s.gsub(/[إأٱآ]/ , "ا") # normalise alif
|
25
|
+
s = s.gsub(/[\u0676]/ , "\u0624") # ARABIC LETTER HIGH HAMZA WAW --> ARABIC LETTER WAW WITH HAMZA ABOVE
|
26
|
+
s = s.gsub(/[\u0649\u06CC\u064a]/ , "\u064a") # normalise alif maqsura, farsi yeh, (ARABIC LETTER YEH WITH HAMZA ABOVE not yet! \u0626, see rules below), yeh --> yeh
|
27
|
+
s = s.gsub(/(?<=\b)#{@al}(?!#{@lah})/ , "") # delete "al") after space (could in some cases be part of the word itself --> false positives)
|
28
|
+
s = s.gsub(/(?<=\b)#{@waw}\s/ , "#{@waw}") # Persian "wa XYZ" --> Arabic "waXYZ")
|
29
|
+
s = s.gsub(/(?<=\b)#{@abd}\s/ , "#{@abd}") # standardise names with abd, e.g. abd allah (etc.) --> abdallah
|
30
|
+
s = s.gsub(/(?<=\B)\u0626(?=\B)/ , "ي") # Arabic letter yeh with hamza above (in the middle of a word) --> Arabic letter yeh, e.g. عقائد --> عقايد
|
31
|
+
s = s.gsub(/(?<=\B)\u0626(?=\b)/ , "يء") # Arabic letter yeh with hamza above (at the end of a word) --> yeh + Hamza, e.g. مبادئ --> مباديء
|
32
|
+
|
33
|
+
# Ta' marbuta (U+0629) (Wortende) im Persischen mit Hah (U+0647) wiedergegeben, z.B. حاشية (ar) vs. حاشيه (fa)
|
34
|
+
# ta' marbuta --> h? (Persian/Mar'ashi)
|
35
|
+
|
36
|
+
# arabisches Hamza auf Alif maqsura (U+0626) in pers. Onlinedaten als Yah+Hamza (U+0626) wiedergegeben, z.B. مبادئ (ar) vs. مباديء (fa)
|
37
|
+
# Allerdings kommt das ئ (U+0626) im Mar'ashi-Katalog vor (قضائ, مفاتيحئ).
|
38
|
+
|
39
|
+
# s = s.gsub(/\s#{din}(?=\b)/ , "#{din}") # standardise names with al-din, e.g. shihab aldin --> shihabaldin
|
40
|
+
|
41
|
+
# Latin and romanised
|
42
|
+
s = s.downcase
|
43
|
+
s = s.gsub(/š/ , "sh")
|
44
|
+
s = s.gsub(/ḫ/ , "kh")
|
45
|
+
s = s.gsub(/ġ/ , "gh")
|
46
|
+
s = s.gsub(/ḏ/ , "dh")
|
47
|
+
s = s.gsub(/ṯ/ , "th")
|
48
|
+
s = s.gsub(/á/ , "ā")
|
49
|
+
|
50
|
+
# FRAGE THOMAS: ' kann Hamza ODER 'Ayn sein --> Mehrfachindizierung wie?
|
51
|
+
# Besser: alle Hamzas/Ayns u.ä. löschen
|
52
|
+
# --> TE: auf einen Buchstaben abbilden
|
53
|
+
# Frage Thomas: Ehrentitel als Präfix löschen? (außer bei kurzen Suchstrings?) --> vs. substring-Suche
|
54
|
+
# Frage Thomas: Abdallah vs. Abd allah
|
55
|
+
# Suche substring?
|
56
|
+
|
57
|
+
return s
|
58
|
+
end
|
59
|
+
|
60
|
+
def search searchword
|
61
|
+
@wordlist.select do |listword|
|
62
|
+
normalize(listword) == normalize(searchword)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ba-normalizedsearch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Thomas Efer
|
8
|
+
- Daniel Kinitz
|
9
|
+
- J. R. Schmid
|
10
|
+
autorequire:
|
11
|
+
bindir: exe
|
12
|
+
cert_chain: []
|
13
|
+
date: 2023-02-28 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.2'
|
21
|
+
name: thor
|
22
|
+
prerelease: false
|
23
|
+
type: :runtime
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '1.2'
|
29
|
+
description:
|
30
|
+
email:
|
31
|
+
- kinitz@saw-leipzig.de
|
32
|
+
executables:
|
33
|
+
- normsearch
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- CHANGELOG.md
|
38
|
+
- Gemfile
|
39
|
+
- Gemfile.lock
|
40
|
+
- LICENSE.md
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- exe/normsearch
|
44
|
+
- lib/ba-normalizedsearch.rb
|
45
|
+
- lib/ba-normalizedsearch/cli.rb
|
46
|
+
- lib/ba-normalizedsearch/version.rb
|
47
|
+
- sig/ba-normalizedsearch.rbs
|
48
|
+
homepage: https://rubygems.org/gems/ba-normalizedsearch
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
metadata:
|
52
|
+
homepage_uri: https://rubygems.org/gems/ba-normalizedsearch
|
53
|
+
source_code_uri: https://rubygems.org/gems/ba-normalizedsearch.git/
|
54
|
+
changelog_uri: https://rubygems.org/gems/ba-normalizedsearch/-/raw/main/CHANGELOG.md
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 2.6.0
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubygems_version: 3.3.25
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: Normalize strings containing Arabic script or Romanisations of Arabic
|
74
|
+
test_files: []
|