ruby-jdict 0.0.1 → 0.0.3

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
  SHA1:
3
- metadata.gz: 48dbfb86f9f72639eae7cecdde05da6953afdc8c
4
- data.tar.gz: 01bae383b6df3ae0e9a524e094d7f1f1890663cd
3
+ metadata.gz: 58dbc6bc5ed75fbff7f33a6e86c4bc490cff1de7
4
+ data.tar.gz: 312d82389911dc301efe8e21dd6df5d4433b326b
5
5
  SHA512:
6
- metadata.gz: 4253b05fc65786103431707d298711170b8cc4cd426919b1dee06ba37a767766021ac80d1207a31a61bf8ea9a15466cf5e173f3b155328986dc674978793b5cd
7
- data.tar.gz: 47a4b27fe519e1284bfd5311404f18489d701ddedc754d9203eaec07101bb4485378760de4f51e56f4fbe7aa235925e01505b18943e81d22af1cbb5464eca801
6
+ metadata.gz: f15f93d16609e867021a3250402cf886f04718cb7d86c5e9de3dc7fba69e703fa2fab4d053df79dd6b52a594361064bae64730b062cc8ff8124d875a1f016b1c
7
+ data.tar.gz: 08252da028585416346a3cecf6d5f75813bf1a74e4127e24b979eee5f0c8e136559d16718bb0940474336be245fad6f3a7806e45a9c308f2064a57eb49da25f4
data/README.md CHANGED
@@ -8,3 +8,6 @@ Dictionary files are located [here](http://www.csse.monash.edu.au/~jwb/wwwjdicin
8
8
  ```
9
9
  gem install ruby-jdict
10
10
  ```
11
+
12
+ ## Usage
13
+ See [this](https://github.com/Ruin0x11/ruby-jdict/blob/master/examples/query.rb) example for basic usage.
@@ -12,6 +12,7 @@ JDict.configure do |config|
12
12
  config.num_results = 50 # maximum results to return from searching
13
13
  end
14
14
 
15
+ # make sure that the dictionary file "JMDict" is in DICT_PATH before initializing.
15
16
  dict = JDict::JMDict.new
16
17
 
17
18
  query = "日本語"
@@ -88,15 +88,20 @@ module JDict
88
88
 
89
89
  @entries_cache = []
90
90
 
91
+ # convert full-width katakana to hiragana
92
+ # TODO: convert half-width katakana to hiragana
93
+ term.tr!('ァ-ン','ぁ-ん')
94
+
91
95
  # search for:
92
96
  # kanji... one field
93
97
  # kana ... up to 10 fields
94
98
  # sense... up to 10 fields
95
99
  # query = 'kanji OR ' + (0..10).map { |x| "kana_#{x} OR sense_#{x}" }.join(' OR ') + ":\"#{term}\""
100
+
96
101
  query = "{kanji kana senses} : \"#{term}\""
97
102
  query += "*" unless exact
98
103
 
99
- @index.execute("SELECT kanji, kana, senses, bm25(search) as score FROM search WHERE search MATCH '#{query}' LIMIT #{JDict.configuration.num_results}") do |row|
104
+ @index.execute("SELECT kanji, kana, senses, bm25(search) as score FROM search WHERE search MATCH ? LIMIT ?", query, JDict.configuration.num_results) do |row|
100
105
  entry = Entry.from_sql(row)
101
106
  score = 0.0
102
107
 
@@ -117,13 +122,6 @@ module JDict
117
122
  is_exact_match = entry.kanji == term ||
118
123
  entry.kana.any? { |k| k == term }
119
124
 
120
- re = Regexp.new("#{term}", Regexp::IGNORECASE) # match the search term, ignoring case
121
- # entry.senses.each do |s|
122
- # s.glosses.each { |g| is_exact_match = is_exact_match || g.force_encoding("UTF-8").match(re) }
123
- # end
124
-
125
- # score = 1.0 if is_exact_match
126
-
127
125
  # add the result
128
126
  results << [score, entry]
129
127
  end
@@ -1,3 +1,3 @@
1
1
  module JDict
2
- Version = '0.0.1'
2
+ Version = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-jdict
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Pickering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-22 00:00:00.000000000 Z
11
+ date: 2015-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libxml-ruby