norikra-udf-woothee 0.0.1-java

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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1 @@
1
+ jruby-1.7.4
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in norikra-udf-woothee.gemspec
4
+ gemspec
@@ -0,0 +1,29 @@
1
+ # Norikra::Udf::Woothee
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'norikra-udf-woothee'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install norikra-udf-woothee
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,27 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec) do |t|
5
+ t.rspec_opts = ["-c", "-f progress"] # '--format specdoc'
6
+ t.pattern = 'spec/**/*_spec.rb'
7
+ end
8
+
9
+ task :compile do
10
+ require 'rubygems'
11
+
12
+ jarname = FileList['norikra-udf-*.gemspec'].first.gsub(/\.gemspec$/, '.jar')
13
+
14
+ jarfiles = FileList['jar/**/*.jar'].select{|f| not f.end_with?('/' + jarname)}
15
+ jarfiles << Gem.find_files('esper-*.jar').first
16
+ classpath = "-classpath java:#{jarfiles.join(':')}"
17
+
18
+ FileList['java/**/*.java'].each do |fn|
19
+ sh "env LC_ALL=C javac #{classpath} #{fn}"
20
+ end
21
+ sh "env LC_ALL=C jar -cf jar/#{jarname} -C java ."
22
+ end
23
+
24
+ task :test => [:compile, :spec]
25
+ task :default => :test
26
+
27
+ task :all => [:compile, :spec, :build]
Binary file
@@ -0,0 +1,51 @@
1
+ package is.tagomor.norikra.udf;
2
+
3
+ import is.tagomor.woothee.Classifier;
4
+ import is.tagomor.woothee.DataSet;
5
+
6
+ import java.util.Map;
7
+ import java.util.List;
8
+
9
+ public final class Woothee
10
+ {
11
+ public static Map<String,String> parseAgent(final String agent) {
12
+ return Classifier.parse(agent);
13
+ }
14
+
15
+ public static Boolean isPC(final Map<String,String> m) {
16
+ return m.get(DataSet.ATTRIBUTE_CATEGORY).equals(DataSet.DATASET_CATEGORY_PC);
17
+ }
18
+
19
+ public static Boolean isSmartPhone(final Map<String,String> m) {
20
+ return m.get(DataSet.ATTRIBUTE_CATEGORY).equals(DataSet.DATASET_CATEGORY_SMARTPHONE);
21
+ }
22
+
23
+ public static Boolean isMobilePhone(final Map<String,String> m) {
24
+ return m.get(DataSet.ATTRIBUTE_CATEGORY).equals(DataSet.DATASET_CATEGORY_MOBILEPHONE);
25
+ }
26
+
27
+ public static Boolean isAppliance(final Map<String,String> m) {
28
+ return m.get(DataSet.ATTRIBUTE_CATEGORY).equals(DataSet.DATASET_CATEGORY_APPLIANCE);
29
+ }
30
+
31
+ public static Boolean isMisc(final Map<String,String> m) {
32
+ return m.get(DataSet.ATTRIBUTE_CATEGORY).equals(DataSet.DATASET_CATEGORY_MISC);
33
+ }
34
+
35
+ public static Boolean isCrawler(final Map<String,String> m) {
36
+ return m.get(DataSet.ATTRIBUTE_CATEGORY).equals(DataSet.DATASET_CATEGORY_CRAWLER);
37
+ }
38
+
39
+ public static Boolean isUnknown(final Map<String,String> m) {
40
+ return m.get(DataSet.ATTRIBUTE_CATEGORY).equals(DataSet.VALUE_UNKNOWN);
41
+ }
42
+
43
+ public static Boolean isIn(final Map<String,String> m, final List<String> categories) {
44
+ String targetCategory = m.get(DataSet.ATTRIBUTE_CATEGORY);
45
+ for (String c : categories) {
46
+ if (targetCategory.equals(c))
47
+ return Boolean.TRUE;
48
+ }
49
+ return Boolean.FALSE;
50
+ }
51
+ }
@@ -0,0 +1,79 @@
1
+ require "norikra/udf/woothee/version"
2
+
3
+ require 'java'
4
+ require 'norikra/udf'
5
+
6
+ module Norikra
7
+ module UDF
8
+ # class style
9
+ class WootheeParseAgent < Norikra::UDF::SingleRow
10
+ def self.init
11
+ require 'woothee.jar'
12
+ require 'norikra-udf-woothee.jar'
13
+ end
14
+ def function_name
15
+ "parseAgent"
16
+ end
17
+ def class_name
18
+ "is.tagomor.norikra.udf.Woothee"
19
+ end
20
+ def method_name # default: same as function_name
21
+ "parseAgent"
22
+ end
23
+ # "definition" also available
24
+ end
25
+
26
+ # udf bundle module style
27
+ module WootheeUDF
28
+ def self.init
29
+ require 'woothee.jar'
30
+ require 'norikra-udf-woothee.jar'
31
+ end
32
+
33
+ def self.plugins
34
+ [IsPC, IsSmartPhone, IsMobilePhone, IsAppliance, IsMisc, IsCrawler, IsUnknown, IsIn]
35
+ end
36
+
37
+ class IsPC < Norikra::UDF::SingleRow
38
+ def definition
39
+ ["isPC", "is.tagomor.norikra.udf.Woothee", "isPC"]
40
+ end
41
+ end
42
+ class IsSmartPhone < Norikra::UDF::SingleRow
43
+ def definition
44
+ ["isSmartPhone", "is.tagomor.norikra.udf.Woothee", "isSmartPhone"]
45
+ end
46
+ end
47
+ class IsMobilePhone < Norikra::UDF::SingleRow
48
+ def definition
49
+ ["isMobilePhone", "is.tagomor.norikra.udf.Woothee", "isMobilePhone"]
50
+ end
51
+ end
52
+ class IsAppliance < Norikra::UDF::SingleRow
53
+ def definition
54
+ ["isAppliance", "is.tagomor.norikra.udf.Woothee", "isAppliance"]
55
+ end
56
+ end
57
+ class IsMisc < Norikra::UDF::SingleRow
58
+ def definition
59
+ ["isMisc", "is.tagomor.norikra.udf.Woothee", "isMisc"]
60
+ end
61
+ end
62
+ class IsCrawler < Norikra::UDF::SingleRow
63
+ def definition
64
+ ["isCrawler", "is.tagomor.norikra.udf.Woothee", "isCrawler"]
65
+ end
66
+ end
67
+ class IsUnknown < Norikra::UDF::SingleRow
68
+ def definition
69
+ ["isUnknown", "is.tagomor.norikra.udf.Woothee", "isUnknown"]
70
+ end
71
+ end
72
+ class IsIn < Norikra::UDF::SingleRow
73
+ def definition
74
+ ["isIn", "is.tagomor.norikra.udf.Woothee", "isIn"]
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,7 @@
1
+ module Norikra
2
+ module UDF
3
+ class Woothee
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'norikra/udf/woothee/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "norikra-udf-woothee"
8
+ spec.version = Norikra::UDF::Woothee::VERSION
9
+ spec.authors = ["TAGOMORI Satoshi"]
10
+ spec.email = ["tagomoris@gmail.com"]
11
+ spec.description = %q{Woothee UDF for Norikra}
12
+ spec.summary = %q{Norikra UDF to parse User-Agent}
13
+ spec.homepage = "https://github.com/tagomoris/norikra-udf-woothee"
14
+ spec.license = "GPLv2"
15
+ spec.platform = "java" #Gem::Platform::JAVA
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib", "jar"]
21
+
22
+ spec.add_runtime_dependency "norikra", ">= 0.0.8"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ end
@@ -0,0 +1,75 @@
1
+ require 'norikra/udf_spec_helper'
2
+
3
+ include Norikra::UDFSpecHelper
4
+
5
+ require 'norikra/udf/woothee'
6
+
7
+ describe Norikra::UDF::WootheeParseAgent do
8
+ udf_function Norikra::UDF::WootheeParseAgent
9
+
10
+ it 'can parse user-agent and returns HashMap instance' do
11
+ r = fcall(:parseAgent, "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)")
12
+ expect(r['name']).to eql('Googlebot')
13
+ expect(r['category']).to eql('crawler')
14
+ end
15
+ end
16
+
17
+ describe Norikra::UDF::WootheeUDF do
18
+ udf_function Norikra::UDF::WootheeParseAgent
19
+ udf_function Norikra::UDF::WootheeUDF
20
+
21
+ it 'provides isPC' do
22
+ pc_agent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0)"
23
+ expect(fcall(:isPC, fcall(:parseAgent, pc_agent))).to be_true
24
+
25
+ smartphone_agent = "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3"
26
+ expect(fcall(:isPC, fcall(:parseAgent, smartphone_agent))).to be_false
27
+ end
28
+
29
+ it 'provides isSmartPhone' do
30
+ smartphone_agent = "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3"
31
+ expect(fcall(:isSmartPhone, fcall(:parseAgent, smartphone_agent))).to be_true
32
+
33
+ mobilephone_agent = "DoCoMo/2.0 SH01A(c100;TB;W24H16)"
34
+ expect(fcall(:isSmartPhone, fcall(:parseAgent, mobilephone_agent))).to be_false
35
+ end
36
+
37
+ it 'provides isMobilePhone' do
38
+ mobilephone_agent = "DoCoMo/2.0 SH01A(c100;TB;W24H16)"
39
+ expect(fcall(:isMobilePhone, fcall(:parseAgent, mobilephone_agent))).to be_true
40
+
41
+ appliance_agent = "Mozilla/5.0 (PLAYSTATION 3; 1.00)"
42
+ expect(fcall(:isMobilePhone, fcall(:parseAgent, appliance_agent))).to be_false
43
+ end
44
+
45
+ it 'provides isAppliance' do
46
+ appliance_agent = "Mozilla/5.0 (PLAYSTATION 3; 1.00)"
47
+ expect(fcall(:isAppliance, fcall(:parseAgent, appliance_agent))).to be_true
48
+
49
+ misc_agent = "Windows-RSS-Platform/2.0 (MSIE 9.0; Windows NT 6.0)"
50
+ expect(fcall(:isAppliance, fcall(:parseAgent, misc_agent))).to be_false
51
+ end
52
+
53
+ it 'provides isMisc' do
54
+ misc_agent = "Windows-RSS-Platform/2.0 (MSIE 9.0; Windows NT 6.0)"
55
+ expect(fcall(:isMisc, fcall(:parseAgent, misc_agent))).to be_true
56
+
57
+ crawler_agent = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
58
+ expect(fcall(:isMisc, fcall(:parseAgent, crawler_agent))).to be_false
59
+ end
60
+
61
+ it 'provides isCrawler' do
62
+ crawler_agent = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
63
+ expect(fcall(:isCrawler, fcall(:parseAgent, crawler_agent))).to be_true
64
+
65
+ pc_agent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0)"
66
+ expect(fcall(:isCrawler, fcall(:parseAgent, pc_agent))).to be_false
67
+ end
68
+
69
+ it 'provides isIn' do
70
+ pc_agent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0)"
71
+ agent = fcall(:parseAgent, pc_agent)
72
+ expect(fcall(:isIn, agent, ['pc','smartphone','mobilephone','appliance'])).to be_true
73
+ expect(fcall(:isIn, agent, ['misc','crawler'])).to be_false
74
+ end
75
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: norikra-udf-woothee
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: java
7
+ authors:
8
+ - TAGOMORI Satoshi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: norikra
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: 0.0.8
21
+ none: false
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.8
27
+ none: false
28
+ prerelease: false
29
+ type: :runtime
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ~>
35
+ - !ruby/object:Gem::Version
36
+ version: '1.3'
37
+ none: false
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ version: '1.3'
43
+ none: false
44
+ prerelease: false
45
+ type: :development
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ none: false
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ none: false
60
+ prerelease: false
61
+ type: :development
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ none: false
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ none: false
76
+ prerelease: false
77
+ type: :development
78
+ description: Woothee UDF for Norikra
79
+ email:
80
+ - tagomoris@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - .ruby-version
87
+ - Gemfile
88
+ - README.md
89
+ - Rakefile
90
+ - jar/norikra-udf-woothee.jar
91
+ - jar/woothee.jar
92
+ - java/is/tagomor/norikra/udf/Woothee.class
93
+ - java/is/tagomor/norikra/udf/Woothee.java
94
+ - lib/norikra/udf/woothee.rb
95
+ - lib/norikra/udf/woothee/version.rb
96
+ - norikra-udf-woothee.gemspec
97
+ - spec/woothee_spec.rb
98
+ homepage: https://github.com/tagomoris/norikra-udf-woothee
99
+ licenses:
100
+ - GPLv2
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ - jar
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ none: false
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ none: false
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 1.8.24
121
+ signing_key:
122
+ specification_version: 3
123
+ summary: Norikra UDF to parse User-Agent
124
+ test_files:
125
+ - spec/woothee_spec.rb