google_refine 0.4 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2dfb7bddc7289a9591321cf8facb6643fa7ef0b1
4
+ data.tar.gz: 2ce085b7ad8925bc82d5ca3fcd9ab43c10197e0f
5
+ SHA512:
6
+ metadata.gz: 9335119183340461b525de57a432e165702e06a70257cef81e9d0c26d91ab2c01e425910a38b6322999cd18aff4d4d73fb8d038dbfb9fe1f5766b84f36672018
7
+ data.tar.gz: 4656138281269cf3d6bd00f36b944dbdef8e3919a35a6fe90ae8d6e163d43d14925864caab686afc480df7552e2bc0ef4d8fc0ff622d6217c9af6a991e5305c4
data/bin/upload-to-refine CHANGED
@@ -8,7 +8,7 @@ require 'tempfile'
8
8
  opts = Trollop::options do
9
9
  opt :host, "Address of Google Refine", :default => '0.0.0.0:3333'
10
10
  opt :project_name, 'Project name'
11
- opt :header_lines, 'Header lines', :default => 0
11
+ opt :header_lines, 'Header lines', :default => 1
12
12
  opt :process_qoutes
13
13
  opt :limit, 'limit', :default => 0
14
14
  end
@@ -20,7 +20,7 @@ host = opts[:host]
20
20
 
21
21
  file = nil
22
22
 
23
- if ARGV.size > 0
23
+ if ARGV.size > 0
24
24
  file = ARGV.shift
25
25
  abort "File \"#{file}\" does not exists." if not File.exists?(file)
26
26
  end
@@ -31,9 +31,9 @@ if file.nil?
31
31
  if STDIN.tty?
32
32
  abort "The STDIN should not be a TTY."
33
33
  else
34
- tempfile = Tempfile.new('upload-to-pipelines')
34
+ tempfile = Tempfile.new('upload-to-refine')
35
35
  tempfile.close
36
-
36
+
37
37
  IO.copy_stream(STDIN, tempfile)
38
38
  file = tempfile.path
39
39
  end
@@ -42,6 +42,11 @@ end
42
42
 
43
43
  refine = Refine.new(host)
44
44
 
45
+ File.open(file) do |f|
46
+ line = f.readline
47
+ opts[:separator] = line.count(",") > line.count("\t") ? "," : "\t"
48
+ end
49
+
45
50
  puts refine.create_project(file, opts)
46
51
 
47
52
  tempfile.unlink if not tempfile.nil?
data/lib/google_refine.rb CHANGED
@@ -3,7 +3,7 @@ require 'json'
3
3
 
4
4
  class Project
5
5
 
6
- attr_accessor :id
6
+ attr_accessor :id
7
7
  attr_accessor :refine
8
8
 
9
9
  def initialize(refine, id)
@@ -18,9 +18,9 @@ end
18
18
 
19
19
  class Job
20
20
 
21
- attr_accessor :id
21
+ attr_accessor :id
22
22
  attr_accessor :refine
23
-
23
+
24
24
  def initialize(refine, id)
25
25
  self.refine = refine
26
26
  self.id = id
@@ -64,7 +64,7 @@ class Refine
64
64
  def initialize(url)
65
65
  self.url = url
66
66
  end
67
-
67
+
68
68
  def url=(url)
69
69
  if url !~ /^http/
70
70
  url = "http://#{url}"
@@ -86,20 +86,21 @@ class Refine
86
86
 
87
87
  def create_project(filename, param = {})
88
88
 
89
-
90
89
  param[:project_name] ||= File.basename(filename)
91
90
 
92
91
  if self.version >= "2.5"
93
92
  begin
94
93
  options = {}
95
- options[:projectName] = param[:project_name]
94
+ options[:projectName] = param[:project_name]
96
95
  options[:encoding] = param[:encoding] || "UTF-8"
97
- options[:separator] = param[:separator] || "\\t"
98
- options[:headerLines] = param[:header_lines] || 0
99
- options[:limit] = param[:limit]
96
+ options[:separator] = param[:separator] || "\t"
97
+ options[:headerLines] = param[:header_lines] || 1
98
+ options[:limit] = param[:limit]
100
99
  options[:guessCellValueTypes] = param[:guess_value_type] || false
101
100
  options[:processQuotes] = param[:process_quotes] || false
102
101
 
102
+ warn options
103
+
103
104
  job = create_importing_job
104
105
  job.load_raw_data(filename)
105
106
  project = job.create_project(options)
@@ -117,7 +118,7 @@ class Refine
117
118
  guess_value_type: param[:guess_value_type],
118
119
  ignore_quotes: ! param[:process_quotes],
119
120
  project_file: File.new(filename, "rb")
120
- }.map { |key, value| [ key.to_s.gsub('_', '-'), value ] }
121
+ }.map { |key, value| [ key.to_s.gsub('_', '-'), value ] }
121
122
  ]
122
123
  )
123
124
  rescue RestClient::Found
metadata CHANGED
@@ -1,80 +1,74 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_refine
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
5
- prerelease:
4
+ version: '0.5'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Cheng Guangnan
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-08 00:00:00.000000000 Z
11
+ date: 2016-01-28 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rest-client
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: trollop
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  description: Ruby library and command line executables for uploading tab files into
47
42
  Google Refine (v2.0 and v2.5).
48
- email: chenggn@gmail.com
43
+ email: chengguangnan@gmail.com
49
44
  executables:
50
45
  - upload-to-refine
51
46
  extensions: []
52
47
  extra_rdoc_files: []
53
48
  files:
54
- - lib/google_refine.rb
55
49
  - bin/upload-to-refine
56
- homepage: https://github.com/guangnan/google_refine
50
+ - lib/google_refine.rb
51
+ homepage: https://github.com/chengguangnan/google_refine
57
52
  licenses: []
53
+ metadata: {}
58
54
  post_install_message:
59
55
  rdoc_options: []
60
56
  require_paths:
61
57
  - lib
62
58
  required_ruby_version: !ruby/object:Gem::Requirement
63
- none: false
64
59
  requirements:
65
- - - ! '>='
60
+ - - ">="
66
61
  - !ruby/object:Gem::Version
67
62
  version: '0'
68
63
  required_rubygems_version: !ruby/object:Gem::Requirement
69
- none: false
70
64
  requirements:
71
- - - ! '>='
65
+ - - ">="
72
66
  - !ruby/object:Gem::Version
73
67
  version: '0'
74
68
  requirements: []
75
69
  rubyforge_project:
76
- rubygems_version: 1.8.24
70
+ rubygems_version: 2.5.1
77
71
  signing_key:
78
- specification_version: 3
72
+ specification_version: 4
79
73
  summary: Upload to Google Refine.
80
74
  test_files: []