Skip to content

Commit

Permalink
Merge pull request louismullie#120 from indentlabs/master
Browse files Browse the repository at this point in the history
Use S3's static-public-assets bucket instead of louismullie.com
  • Loading branch information
louismullie committed May 5, 2017
2 parents d6a163f + 58911ce commit 8c6450a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 38 deletions.
52 changes: 26 additions & 26 deletions lib/treat/core/installer.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# A dependency manager for Treat language plugins.
# Usage: Treat::Installer.install('language')
module Treat::Core::Installer

require 'schiphol'

# Address of the server with the files.
Server = 'www.louismullie.com'
Server = 's3.amazonaws.com/static-public-assets'

# Filenames for the Stanford packages.
StanfordPackages = {
Expand All @@ -20,34 +20,34 @@ module Treat::Core::Installer
:bin => File.absolute_path(Treat.paths.bin),
:models => File.absolute_path(Treat.paths.models)
}

# Install required dependencies and optional
# dependencies for a specific language.
def self.install(language = 'english')

# Require the Rubygem dependency installer.
silence_warnings do
require 'rubygems/dependency_installer'
end

@@installer = Gem::DependencyInstaller.new

if language == 'travis'
install_travis; return
end

l = "#{language.to_s.capitalize} language"

puts "\nTreat Installer, v. #{Treat::VERSION.to_s}\n\n"

begin

title "Installing core dependencies."
install_language_dependencies('agnostic')

title "Installing dependencies for the #{l}.\n"
install_language_dependencies(language)

# If gem is installed only, download models.
begin
Gem::Specification.find_by_name('punkt-segmenter')
Expand All @@ -73,15 +73,15 @@ def self.install(language = 'english')
end

end

# Minimal install for Travis CI.
def self.install_travis
install_language_dependencies(:agnostic)
install_language_dependencies(:english)
download_stanford(:minimal)
download_punkt_models(:english)
end


def self.install_language_dependencies(language)
dependencies = Treat.languages[language].dependencies
Expand All @@ -92,31 +92,31 @@ def self.install_language_dependencies(language)
end

def self.download_stanford(package = :minimal)

f = StanfordPackages[package]
url = "http://#{Server}/treat/#{f}"
loc = Schiphol.download(url,
loc = Schiphol.download(url,
download_folder: Treat.paths.tmp
)
puts "- Unzipping package ..."
dest = File.join(Treat.paths.tmp, 'stanford')
unzip_stanford(loc, dest)

model_dir = File.join(Paths[:models], 'stanford')
bin_dir = File.join(Paths[:bin], 'stanford')
origin = File.join(Paths[:tmp], 'stanford')

# Mac hidden files fix.
mac_remove = File.join(dest, '__MACOSX')
if File.readable?(mac_remove)
FileUtils.rm_rf(mac_remove)
end

unless File.readable?(bin_dir)
puts "- Creating directory bin/stanford ..."
FileUtils.mkdir_p(bin_dir)
end

unless File.readable?(model_dir)
puts "- Creating directory models/stanford ..."
FileUtils.mkdir_p(model_dir)
Expand All @@ -127,26 +127,26 @@ def self.download_stanford(package = :minimal)
Dir.glob(File.join(origin, '*')) do |f|
next if ['.', '..'].include?(f)
if f.index('jar')
FileUtils.cp(f, File.join(Paths[:bin],
FileUtils.cp(f, File.join(Paths[:bin],
'stanford', File.basename(f)))
elsif FileTest.directory?(f)
FileUtils.cp_r(f, model_dir)
end
end

puts "- Cleaning up..."
FileUtils.rm_rf(origin)

'Done.'

end

def self.download_punkt_models(language)

f = "#{language}.yaml"
dest = "#{Treat.paths.models}punkt/"
url = "http://#{Server}/treat/punkt/#{f}"
loc = Schiphol.download(url,
loc = Schiphol.download(url,
download_folder: Treat.paths.tmp
)
unless File.readable?(dest)
Expand All @@ -156,7 +156,7 @@ def self.download_punkt_models(language)

puts "- Copying model file to models/punkt ..."
FileUtils.cp(loc, File.join(Paths[:models], 'punkt', f))

puts "- Cleaning up..."
FileUtils.rm_rf(Paths[:tmp] + Server)

Expand Down Expand Up @@ -185,15 +185,15 @@ def self.install_gem(dependency)
puts "Warning: couldn't install " +
"gem '#{dependency}' (#{error.message})."
end

end

# Unzip a file to the destination path.
def self.unzip_stanford(file, destination)

require 'zip/zip'
f_path = ''

Zip::ZipFile.open(file) do |zip_file|
zip_file.each do |f|
f_path = File.join(destination, f.name)
Expand Down
25 changes: 13 additions & 12 deletions treat.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,39 @@ $:.push File.expand_path('../lib', __FILE__)
require 'treat/version'

Gem::Specification.new do |s|

s.name = 'treat'
s.version = Treat::VERSION
s.authors = ['Louis Mullie']
s.email = ['louis.mullie@gmail.com']
s.homepage = 'https://github.com/louismullie/treat'
s.summary = %q{ Text Retrieval, Extraction and Annotation Toolkit. }
s.description = %q{ Treat is a natural language processing framework for Ruby. }

# Add all files.
s.files =
Dir['bin/**/*'] +
Dir['lib/**/*'] +
s.files =
Dir['bin/**/*'] +
Dir['lib/**/*'] +
Dir['spec/**/*'] +
Dir['models/**/*'] +
Dir['tmp/**/*'] +
Dir['models/**/*'] +
Dir['tmp/**/*'] +
Dir['files/**/*'] +
['README.md', 'LICENSE']

# Runtime dependencies
s.add_runtime_dependency 'schiphol'
s.add_runtime_dependency 'birch'
s.add_runtime_dependency 'yomu'

# Development dependencies
s.add_development_dependency 'rspec'
s.add_development_dependency 'rake'
s.add_development_dependency 'simplecov'

# Post-install message
s.post_install_message = %q{Thanks for installing Treat.
To complete the installation, run `require 'treat'` in an IRB
terminal, followed by `Treat::Core::Installer.install`. }
To complete the installation, run `require 'treat'` in an IRB
terminal, followed by `Treat::Core::Installer.install`.
}

end

0 comments on commit 8c6450a

Please sign in to comment.