Skip to content
This repository
Newer
Older
100644 102 lines (82 sloc) 2.396 kb
dc951413 »
2011-07-25 + Namespacing in tests
1 module Picky
fac93d25 »
2011-07-05 + backend cleanup, + to_s
2
536a8521 »
2011-08-25 + backend rewrite, towards making it more exchangeable
3 module Backends
fac93d25 »
2011-07-05 + backend cleanup, + to_s
4
794aa490 »
2011-08-27 + experimental file-based index backend prototype
5 class File
ac02b191 »
2012-09-06 + backend refactored, - duplicate code
6
7 def json *args
8 JSON.new *args
9 end
fac93d25 »
2011-07-05 + backend cleanup, + to_s
10
794aa490 »
2011-08-27 + experimental file-based index backend prototype
11 # File-based index files dumped in the JSON format.
ee888e51 »
2011-07-04 + internal rewrite, part 4
12 #
dc951413 »
2011-07-25 + Namespacing in tests
13 class JSON < Basic
14
d199aab3 »
2011-11-26 + rewritten performance specs
15 attr_writer :mapping
16
d60c6674 »
2011-08-28 + notes on the file backend
17 # The in-memory mapping hash, mapping
18 # a Symbol key to [length, offset] of
19 # the JSON data in the file.
20 #
d199aab3 »
2011-11-26 + rewritten performance specs
21 def mapping
22 @mapping || raise("The File index/category needs to be loaded first.")
23 end
794aa490 »
2011-08-27 + experimental file-based index backend prototype
24
d60c6674 »
2011-08-28 + notes on the file backend
25 # See lib/picky/backends/file.rb for what this should return.
794aa490 »
2011-08-27 + experimental file-based index backend prototype
26 #
27 # 1. Gets the length and offset for the key.
28 # 2. Extracts and decodes the object from the file.
29 #
30 def [] key
31 length, offset = mapping[key]
f466fb71 »
2011-08-27 + naive implementation of file based backend, + minimal backend inter…
32 return unless length
b6b58bd6 »
2012-07-01 + Yajl -> MultiJson
33 result = MultiJson.decode IO.read(cache_path, length, offset)
794aa490 »
2011-08-27 + experimental file-based index backend prototype
34 result
35 end
36
37 # Clears the currently loaded index.
38 #
d60c6674 »
2011-08-28 + notes on the file backend
39 # Note: This only clears the in-memory mapping,
40 # but this is enough for the index to not exist
41 # anymore, at least to the application.
42 #
794aa490 »
2011-08-27 + experimental file-based index backend prototype
43 def clear
44 self.mapping.clear
45 end
46
3a232d93 »
2011-12-16 ! analyzer, + phonetics, + category doc
47 # Size of the index is equal to the mapping size.
48 #
49 def size
50 self.mapping.size
51 end
52
794aa490 »
2011-08-27 + experimental file-based index backend prototype
53 # Loads the mapping hash from json format.
dc951413 »
2011-07-25 + Namespacing in tests
54 #
55 def load
794aa490 »
2011-08-27 + experimental file-based index backend prototype
56 self.mapping = mapping_file.load
57 self
dc951413 »
2011-07-25 + Namespacing in tests
58 end
794aa490 »
2011-08-27 + experimental file-based index backend prototype
59
dc951413 »
2011-07-25 + Namespacing in tests
60 # Dumps the index hash in json format.
61 #
794aa490 »
2011-08-27 + experimental file-based index backend prototype
62 # 1. Dump actual data.
63 # 2. Dumps mapping key => [length, offset].
64 #
dc951413 »
2011-07-25 + Namespacing in tests
65 def dump hash
794aa490 »
2011-08-27 + experimental file-based index backend prototype
66 offset = 0
67 mapping = {}
a5015c29 »
2012-11-28 + Rewrote file backend to use the memory backend with the weights index
68
c6d3d26b »
2011-10-30 + dumping indexes during runtime is possible now
69 create_directory cache_path
794aa490 »
2011-08-27 + experimental file-based index backend prototype
70 ::File.open(cache_path, 'w:utf-8') do |out_file|
71 hash.each do |(key, object)|
b6b58bd6 »
2012-07-01 + Yajl -> MultiJson
72 encoded = MultiJson.encode object
794aa490 »
2011-08-27 + experimental file-based index backend prototype
73 length = encoded.size
74 mapping[key] = [length, offset]
75 offset += length
76 out_file.write encoded
77 end
78 end
79
80 mapping_file.dump mapping
dc951413 »
2011-07-25 + Namespacing in tests
81 end
794aa490 »
2011-08-27 + experimental file-based index backend prototype
82
dc951413 »
2011-07-25 + Namespacing in tests
83 # A json file does not provide retrieve functionality.
84 #
85 def retrieve
86 raise "Can't retrieve from JSON file. Use text file."
87 end
88
f466fb71 »
2011-08-27 + naive implementation of file based backend, + minimal backend inter…
89 # Uses the extension "json".
90 #
91 def extension
92 :json
93 end
94
2116d5fc »
2011-02-27 + Internals restructuring
95 end
fac93d25 »
2011-07-05 + backend cleanup, + to_s
96
2116d5fc »
2011-02-27 + Internals restructuring
97 end
fac93d25 »
2011-07-05 + backend cleanup, + to_s
98
2116d5fc »
2011-02-27 + Internals restructuring
99 end
ee888e51 »
2011-07-04 + internal rewrite, part 4
100
fb90607b »
2011-11-13 First steps towards SQLite backend
101 end
Something went wrong with that request. Please try again.