cjk_index 0.2.0 → 1.0.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +62 -0
- data/LICENSE-Unicode +39 -0
- data/NOTICE +17 -0
- data/README.md +164 -41
- data/data/ja-kyujitai.tsv +423 -292
- data/data/ko-hanyang-pua.tsv +5666 -0
- data/data/zh-hant-hans-safe.tsv +2774 -0
- data/exe/cjk_index +6 -0
- data/lib/cjk_index/bridgetown.rb +100 -0
- data/lib/cjk_index/builder.rb +247 -89
- data/lib/cjk_index/cli.rb +240 -0
- data/lib/cjk_index/index_file.rb +4 -0
- data/lib/cjk_index/jekyll.rb +21 -5
- data/lib/cjk_index/normalizer.rb +60 -12
- data/lib/cjk_index/postings.rb +218 -0
- data/lib/cjk_index/rake_task.rb +71 -0
- data/lib/cjk_index/runtime.js +243 -29
- data/lib/cjk_index/runtime.rb +1 -0
- data/lib/cjk_index/searcher.rb +101 -37
- data/lib/cjk_index/tokenizer.rb +30 -0
- data/lib/cjk_index/version.rb +1 -1
- data/lib/cjk_index.rb +1 -0
- metadata +16 -4
data/lib/cjk_index/tokenizer.rb
CHANGED
|
@@ -68,6 +68,36 @@ module CJKIndex
|
|
|
68
68
|
phrases(text, unigrams: unigrams, normalizer: normalizer).flatten(1)
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
+
# A run of separators, of CJK characters, or of other characters. A
|
|
72
|
+
# separator is never part of a run (・ is in the katakana block).
|
|
73
|
+
CJK_WORD = /[#{CJK.source[1..-2]}&&[^#{SEPARATOR.source[1..-2]}]]/
|
|
74
|
+
RUN = /(#{SEPARATOR.source}+)|(#{CJK_WORD.source}+)|((?:(?!#{SEPARATOR.source})(?!#{CJK.source}).)+)/m
|
|
75
|
+
|
|
76
|
+
# Yields each token of already normalized text with its offset: the
|
|
77
|
+
# tokens of tokens_with_offsets, without building the phrases. Used to
|
|
78
|
+
# build the index, where it is several times faster.
|
|
79
|
+
def each_token(normalized, unigrams: false)
|
|
80
|
+
offset = 0
|
|
81
|
+
normalized.scan(RUN) do |_, cjk, other|
|
|
82
|
+
run = Regexp.last_match(0)
|
|
83
|
+
if cjk
|
|
84
|
+
chars = run.chars
|
|
85
|
+
if chars.length == 1 || unigrams
|
|
86
|
+
chars.each_with_index { |c, i| yield c, offset + i }
|
|
87
|
+
end
|
|
88
|
+
i = 0
|
|
89
|
+
last = chars.length - 1
|
|
90
|
+
while i < last
|
|
91
|
+
yield chars[i] + chars[i + 1], offset + i
|
|
92
|
+
i += 1
|
|
93
|
+
end
|
|
94
|
+
elsif other
|
|
95
|
+
yield run, offset
|
|
96
|
+
end
|
|
97
|
+
offset += run.length
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
71
101
|
# Splits at separators (spaces, punctuation) into phrases, each a list of
|
|
72
102
|
# [token, offset]. A query matches when every phrase occurs somewhere in
|
|
73
103
|
# the document, with the tokens of each phrase at the same relative offsets.
|
data/lib/cjk_index/version.rb
CHANGED
data/lib/cjk_index.rb
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require_relative "cjk_index/version"
|
|
4
4
|
require_relative "cjk_index/normalizer"
|
|
5
5
|
require_relative "cjk_index/tokenizer"
|
|
6
|
+
require_relative "cjk_index/postings"
|
|
6
7
|
require_relative "cjk_index/builder"
|
|
7
8
|
require_relative "cjk_index/runtime"
|
|
8
9
|
require_relative "cjk_index/searcher"
|
metadata
CHANGED
|
@@ -1,33 +1,43 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cjk_index
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Satoru Nakamura
|
|
8
|
-
bindir:
|
|
8
|
+
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
12
|
description: Builds a bigram search index in Ruby (with kana, old/new kanji and NFKC
|
|
13
13
|
normalization), and queries it in Ruby or with a small browser runtime that returns
|
|
14
|
-
the same results. Includes a
|
|
15
|
-
|
|
14
|
+
the same results. Includes a command-line tool, a Rake task, a Jekyll plugin (with
|
|
15
|
+
a CollectionBuilder preset) and a Bridgetown plugin.
|
|
16
|
+
executables:
|
|
17
|
+
- cjk_index
|
|
16
18
|
extensions: []
|
|
17
19
|
extra_rdoc_files: []
|
|
18
20
|
files:
|
|
19
21
|
- CHANGELOG.md
|
|
20
22
|
- LICENSE
|
|
21
23
|
- LICENSE-OpenCC
|
|
24
|
+
- LICENSE-Unicode
|
|
22
25
|
- NOTICE
|
|
23
26
|
- README.md
|
|
24
27
|
- data/ja-kyujitai.tsv
|
|
28
|
+
- data/ko-hanyang-pua.tsv
|
|
29
|
+
- data/zh-hant-hans-safe.tsv
|
|
25
30
|
- data/zh-hant-hans.tsv
|
|
31
|
+
- exe/cjk_index
|
|
26
32
|
- lib/cjk_index.rb
|
|
33
|
+
- lib/cjk_index/bridgetown.rb
|
|
27
34
|
- lib/cjk_index/builder.rb
|
|
35
|
+
- lib/cjk_index/cli.rb
|
|
28
36
|
- lib/cjk_index/index_file.rb
|
|
29
37
|
- lib/cjk_index/jekyll.rb
|
|
30
38
|
- lib/cjk_index/normalizer.rb
|
|
39
|
+
- lib/cjk_index/postings.rb
|
|
40
|
+
- lib/cjk_index/rake_task.rb
|
|
31
41
|
- lib/cjk_index/runtime.js
|
|
32
42
|
- lib/cjk_index/runtime.rb
|
|
33
43
|
- lib/cjk_index/searcher.rb
|
|
@@ -37,6 +47,8 @@ homepage: https://github.com/nakamura196/cjk_index
|
|
|
37
47
|
licenses:
|
|
38
48
|
- MIT
|
|
39
49
|
- Apache-2.0
|
|
50
|
+
- Unicode-3.0
|
|
51
|
+
- Unlicense
|
|
40
52
|
metadata:
|
|
41
53
|
source_code_uri: https://github.com/nakamura196/cjk_index
|
|
42
54
|
documentation_uri: https://github.com/nakamura196/cjk_index#readme
|