asearch 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ === 0.0.1 2012-05-12
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,11 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/asearch.rb
7
+ script/console
8
+ script/destroy
9
+ script/generate
10
+ test/test_asearch.rb
11
+ test/test_helper.rb
data/PostInstall.txt ADDED
@@ -0,0 +1,7 @@
1
+
2
+ For more information on asearch, see http://asearch.rubyforge.org
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
data/README.rdoc ADDED
@@ -0,0 +1,48 @@
1
+ = asearch
2
+
3
+ * http://github.com/#{github_username}/#{project_name}
4
+
5
+ == DESCRIPTION:
6
+
7
+ FIX (describe your package)
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ * FIX (sudo gem install, anything else)
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2012 FIXME full name
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/asearch'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'asearch' do
14
+ self.developer 'Toshiyuki Masui', 'masui@pitecan.com'
15
+ self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
+ self.rubyforge_name = self.name # TODO this is default value
17
+ # self.extra_deps = [['activesupport','>= 2.0.2']]
18
+
19
+ end
20
+
21
+ require 'newgem/tasks'
22
+ Dir['tasks/**/*.rake'].each { |t| load t }
23
+
24
+ # TODO - want other tests/tasks run by default? Add them to the list
25
+ # remove_task :default
26
+ # task :default => [:spec, :features]
data/lib/asearch.rb ADDED
@@ -0,0 +1,105 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Created by Toshiyuki Masui on 11/04/16.
4
+ # Copyright 2011 Pitecan Systems. All rights reserved.
5
+ #
6
+ # a = Asearch.new('abcde')
7
+ # a.match('abcde') => true
8
+ # a.match('abXcde',1) => true
9
+ #
10
+ # a = Asearch.new('abcde')
11
+ # initstate = a.initstate
12
+ # laststate = a.state(initstate,'abcde')
13
+ # laststate[0] & a.acceptpat => non-zero value
14
+ #
15
+
16
+ $:.unshift(File.dirname(__FILE__)) unless
17
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
18
+
19
+ class Asearch
20
+ VERSION = '0.0.1'
21
+
22
+ INITPAT = 0x80000000
23
+ MAXCHAR = 0x100
24
+
25
+ def isupper(c)
26
+ c >= 0x41 && c <= 0x5a
27
+ end
28
+
29
+ def islower(c)
30
+ c >= 0x61 && c <= 0x7a
31
+ end
32
+
33
+ def tolower(c)
34
+ isupper(c) ? c + 0x20 : c
35
+ end
36
+
37
+ def toupper(c)
38
+ islower(c) ? c - 0x20 : c
39
+ end
40
+
41
+ def initialize(pat)
42
+ @shiftpat = []
43
+ @epsilon = 0
44
+ @acceptpat = 0
45
+ mask = INITPAT
46
+ (0...MAXCHAR).each { |c|
47
+ @shiftpat[c] = 0
48
+ }
49
+ chars = pat.unpack("C*")
50
+ chars.each { |c|
51
+ if c == 0x20 then
52
+ @epsilon |= mask
53
+ else
54
+ @shiftpat[c] |= mask
55
+ @shiftpat[toupper(c)] |= mask
56
+ @shiftpat[tolower(c)] |= mask
57
+ mask >>= 1
58
+ end
59
+ }
60
+ @acceptpat = mask
61
+ end
62
+
63
+ attr_reader :acceptpat
64
+
65
+ # def bin(val)
66
+ # s = "0"*40 + sprintf("%b",val)
67
+ # s[-32,100]
68
+ # end
69
+
70
+ #
71
+ # 状態stateからテキストstrを認識したときの状態変化
72
+ #
73
+ def state(state=nil,str='')
74
+ if state.nil? then
75
+ state = initstate
76
+ end
77
+ i0 = state[0]
78
+ i1 = state[1]
79
+ i2 = state[2]
80
+ i3 = state[3]
81
+ chars = str.unpack("C*")
82
+ chars.each { |c|
83
+ mask = @shiftpat[c]
84
+ i3 = (i3 & @epsilon) | ((i3 & mask) >> 1) | (i2 >> 1) | i2
85
+ i2 = (i2 & @epsilon) | ((i2 & mask) >> 1) | (i1 >> 1) | i1
86
+ i1 = (i1 & @epsilon) | ((i1 & mask) >> 1) | (i0 >> 1) | i0
87
+ i0 = (i0 & @epsilon) | ((i0 & mask) >> 1)
88
+ i1 |= (i0 >> 1)
89
+ i2 |= (i1 >> 1)
90
+ i3 |= (i2 >> 1)
91
+ }
92
+ [i0, i1, i2, i3]
93
+ end
94
+
95
+ def initstate
96
+ [INITPAT, 0, 0, 0]
97
+ end
98
+
99
+ def match(str, ambig=0)
100
+ s = state(initstate,str)
101
+ s[ambig] & acceptpat != 0
102
+ end
103
+ end
104
+
105
+
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/asearch.rb'}"
9
+ puts "Loading asearch gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestAsearch < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_1
9
+ a = Asearch.new('abcde')
10
+ assert a.match('abcde') == true
11
+ assert a.match('aBCDe') == true
12
+ assert a.match('abXcde') == false
13
+ assert a.match('abXcde',1) == true
14
+ assert a.match('ab?de') == false
15
+ assert a.match('ab?de',1) == true
16
+ assert a.match('abde') == false
17
+ assert a.match('abde',1) == true
18
+ assert a.match('abXXde',1) == false
19
+ assert a.match('abXXde',2) == true
20
+ end
21
+
22
+ def test_2
23
+ a = Asearch.new('ab de')
24
+ assert a.match('abcde') == true
25
+ assert a.match('abccde') == true
26
+ assert a.match('abXXXXXXXde') == true
27
+ assert a.match('abcccccxe') == false
28
+ assert a.match('abcccccxe',1) == true
29
+ end
30
+
31
+ def test_x
32
+ a = Asearch.new('abcde')
33
+ initstate = a.initstate
34
+ laststate = a.state(initstate,'abcde')
35
+ assert laststate[0] & a.acceptpat != 0
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/asearch'
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asearch
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Toshiyuki Masui
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-05-12 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rdoc
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 19
29
+ segments:
30
+ - 3
31
+ - 10
32
+ version: "3.10"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: newgem
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 5
44
+ segments:
45
+ - 1
46
+ - 5
47
+ - 3
48
+ version: 1.5.3
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: hoe
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 27
60
+ segments:
61
+ - 2
62
+ - 12
63
+ version: "2.12"
64
+ type: :development
65
+ version_requirements: *id003
66
+ description: FIX (describe your package)
67
+ email:
68
+ - masui@pitecan.com
69
+ executables: []
70
+
71
+ extensions: []
72
+
73
+ extra_rdoc_files:
74
+ - History.txt
75
+ - Manifest.txt
76
+ - PostInstall.txt
77
+ files:
78
+ - History.txt
79
+ - Manifest.txt
80
+ - PostInstall.txt
81
+ - README.rdoc
82
+ - Rakefile
83
+ - lib/asearch.rb
84
+ - script/console
85
+ - script/destroy
86
+ - script/generate
87
+ - test/test_asearch.rb
88
+ - test/test_helper.rb
89
+ - .gemtest
90
+ homepage: http://github.com/#{github_username}/#{project_name}
91
+ licenses: []
92
+
93
+ post_install_message: PostInstall.txt
94
+ rdoc_options:
95
+ - --main
96
+ - README.rdoc
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ hash: 3
114
+ segments:
115
+ - 0
116
+ version: "0"
117
+ requirements: []
118
+
119
+ rubyforge_project: asearch
120
+ rubygems_version: 1.8.23
121
+ signing_key:
122
+ specification_version: 3
123
+ summary: FIX (describe your package)
124
+ test_files:
125
+ - test/test_asearch.rb
126
+ - test/test_helper.rb