tikarb 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +16 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +66 -0
- data/Rakefile +6 -0
- data/bin/console +7 -0
- data/bin/install_tika +4 -0
- data/lib/tikarb.rb +77 -0
- data/lib/tikarb/version.rb +3 -0
- data/tikarb.gemspec +28 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 91d862cea10dd3a4034893f92e83ec0133c12b56d68d77e5da33b6d5846e1425
|
4
|
+
data.tar.gz: ba170ce89d8eedae219911da2fbe90ce3a9bf05160a50ca557f5094f829ad3a1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b7d7b9f3973020b006d2ca6944a12423c15bf38c560ac0b6897c932ab848664eb8ce64fdff7569c61d2c98e222b9e97b12f8652ddb4305e62f497549b2729aad
|
7
|
+
data.tar.gz: 0ed51549d94fe564b42372cec8d469d23d254724a55e9bc4c5ff8b91a7bd4ffadfb0f5ea885ab1dea873e8345edd988e3de1d999bbb968cb32191b31d56cecce
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at kaneta@sitebridge.co.jp. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Yoshikazu Kaneta
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Tikarb
|
2
|
+
|
3
|
+
A simple Apache Tika binding for ruby using rjb.
|
4
|
+
|
5
|
+
## Dependencies
|
6
|
+
|
7
|
+
* ruby 2.3+
|
8
|
+
* tika 1.16+
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'tikarb'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Setup path to tika-app jar file:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
Tikarb.path = '/path/to/your/tika-app.jar'
|
28
|
+
```
|
29
|
+
|
30
|
+
Use as follows:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
# extract text and metadata from file
|
34
|
+
Tikarb.parse('/path/to/your/file')
|
35
|
+
|
36
|
+
# detect media type
|
37
|
+
Tikarb.detect('/path/to/your/file')
|
38
|
+
|
39
|
+
# call with command-line options
|
40
|
+
Tikarb.cli('--xml', '/path/to/your/file')
|
41
|
+
```
|
42
|
+
|
43
|
+
You can use `StringIO` as an argument:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
Tikarb.parse(StringIO.new(your_data))
|
47
|
+
```
|
48
|
+
|
49
|
+
## Pros and Cons
|
50
|
+
|
51
|
+
This gem calls Tika libraries via Java Native Interface using rjb.
|
52
|
+
|
53
|
+
Pros:
|
54
|
+
* It will be faster than command-line interface in case Tika is executed repeatedly.
|
55
|
+
|
56
|
+
Cons:
|
57
|
+
* It requires some memory to load JavaVM in the process.
|
58
|
+
* It will affect JDK and Tika internal specification change.
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kanety/tikarb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
63
|
+
|
64
|
+
## License
|
65
|
+
|
66
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/install_tika
ADDED
data/lib/tikarb.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'rjb'
|
2
|
+
|
3
|
+
class Tikarb
|
4
|
+
class Java
|
5
|
+
class << self
|
6
|
+
def load
|
7
|
+
Rjb::load(Tikarb.path)
|
8
|
+
|
9
|
+
import 'java.lang.System'
|
10
|
+
import 'java.io.PrintStream'
|
11
|
+
import 'java.io.FileInputStream'
|
12
|
+
import 'java.io.ByteArrayInputStream'
|
13
|
+
import 'java.io.ByteArrayOutputStream'
|
14
|
+
import 'org.apache.tika.Tika'
|
15
|
+
import 'org.apache.tika.cli.TikaCLI'
|
16
|
+
import 'org.apache.tika.metadata.Metadata'
|
17
|
+
end
|
18
|
+
|
19
|
+
def import(path)
|
20
|
+
name = path.split('.').last.to_sym
|
21
|
+
const_set(name, Rjb::import(path)) unless const_defined?(name)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class << self
|
27
|
+
attr_accessor :path
|
28
|
+
|
29
|
+
def detect(file)
|
30
|
+
Java.load
|
31
|
+
|
32
|
+
tika = Java::Tika.new
|
33
|
+
tika.detect(file_to_input_stream(file))
|
34
|
+
end
|
35
|
+
|
36
|
+
def parse(file)
|
37
|
+
Java.load
|
38
|
+
|
39
|
+
tika = Java::Tika.new
|
40
|
+
metadata = Java::Metadata.new
|
41
|
+
text = tika.parseToString(file_to_input_stream(file), metadata)
|
42
|
+
return text, metadata_to_hash(metadata)
|
43
|
+
end
|
44
|
+
|
45
|
+
def cli(*args)
|
46
|
+
Java.load
|
47
|
+
|
48
|
+
trap_stdout do
|
49
|
+
cli = Java::TikaCLI.new
|
50
|
+
args.each { |arg| cli.process(arg) }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def file_to_input_stream(file)
|
57
|
+
if file.respond_to?(:read)
|
58
|
+
Java::ByteArrayInputStream.new(file.read)
|
59
|
+
else
|
60
|
+
Java::FileInputStream.new(file)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def trap_stdout
|
65
|
+
out = Java::ByteArrayOutputStream.new
|
66
|
+
Java::System.setOut(Java::PrintStream.new(out))
|
67
|
+
yield
|
68
|
+
out.toString
|
69
|
+
end
|
70
|
+
|
71
|
+
def metadata_to_hash(metadata)
|
72
|
+
metadata.names.each_with_object({}) do |name, hash|
|
73
|
+
hash[name] = metadata.get(name)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/tikarb.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tikarb/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tikarb"
|
8
|
+
spec.version = Tikarb::VERSION
|
9
|
+
spec.authors = ["Yoshikazu Kaneta"]
|
10
|
+
spec.email = ["kaneta@sitebridge.co.jp"]
|
11
|
+
|
12
|
+
spec.summary = %q{A simple Apache Tika binding for ruby.}
|
13
|
+
spec.description = %q{A simple Apache Tika binding for ruby using rjb.}
|
14
|
+
spec.homepage = "https://github.com/kanety/tikarb"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "rjb"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "simplecov"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tikarb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yoshikazu Kaneta
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rjb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: A simple Apache Tika binding for ruby using rjb.
|
84
|
+
email:
|
85
|
+
- kaneta@sitebridge.co.jp
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- CODE_OF_CONDUCT.md
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/install_tika
|
100
|
+
- lib/tikarb.rb
|
101
|
+
- lib/tikarb/version.rb
|
102
|
+
- tikarb.gemspec
|
103
|
+
homepage: https://github.com/kanety/tikarb
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.7.3
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: A simple Apache Tika binding for ruby.
|
127
|
+
test_files: []
|