将 Hunspell 与 Heroku 结合使用

发布于 2024-11-29 16:15:35 字数 201 浏览 8 评论 0原文

我正在构建一个使用 Hunspell 和 hunspell-ffi gem 的 Rails 应用程序,以便 Ruby 可以与其交互。我正在将应用程序部署到 heroku,但不幸的是,它需要在服务器上安装 Hunspell 才能使 gem 工作。

我有什么办法可以在 Heroku 上安装 Hunspell 吗?或者我是否必须迁移到 EC2?

提前致谢 :)

I'm building a Rails app that uses Hunspell and the hunspell-ffi gem so that Ruby can interface with it. I'm deploying the app to heroku, but unfortunately it needs Hunspell to be installed on the server in order for the gem to work.

Is there any way for me to install Hunspell on Heroku? Or am I going to have to migrate to EC2?

Thanks in advance :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

夏尔 2024-12-06 16:15:35

您需要构建所需的 Hunspell 库并将其直接包含在您的 Heroku 项目中。

Heroku 在 64 位 Ubuntu 上运行,因此必须在该系统下编译二进制文件。最好的方法是简单地使用 Heroku 的 Vulcan 构建服务器 在 Heroku 实例上进行编译。

编译 Heroku

  1. gem install vulcan
  2. vulcan create vulcan-compile-me 最后一个参数是您自己的应用程序名称。
  3. 下载 Hunspell 源代码
  4. 提取
  5. vulcan build -v -s 。 /hunspell-1.3.2 告诉 Vulcan 构建它并自动将成品下载到 /tmp/hunspell..

构建服务器需要 cloudant 插件,该插件会自动安装但您必须确保拥有经过验证(添加信用卡)的 Heroku 帐户。如果您在第六步中遇到错误无构建输出,请执行 heroku addons:add cloudant --app vulcan-compile-me

添加到您的项目

  1. 提取 Heroku Vulcan 构建 tar从 /tmp
  2. 将整个 lib 文件夹复制到项目根目录中的 vendor/hunspell
  3. 告诉 Heroku 在哪里查找库: heroku config:add LD_LIBRARY_PATH=供应商/hunspell/lib

安装词典

从 Open Office 下载一些词典并将它们添加到您的项目中。一个好的位置是根级别名为dictionaries的文件夹。然后在 Ruby 中初始化 Hunspell 时会引用该路径。

http://extensions.services.openoffice.org/dictionary

ftp://sunsite.informatik.rwth-aachen.de/pub/mirror/OpenOffice/contrib/

使用

安装你最喜欢的 Hunspell gem,我使用 hunspell-ffi。有一个 Hunspell 的较新 gem 但我更喜欢以前的 FFI gem。使用词典文件夹路径和语言(语言与词典文件名匹配)初始化 Hunspell 对象。

dict = Hunspell.new("dictionaries", "en_US")

if dict.check('caribean') == false
    suggestions = dict.suggest('caribean')
    if (suggestions.size)
        correction = suggestions.first # returns 'caribbean'
    end
end

供应更复杂的项目

您还可以将库供应到您的项目中,方法是将第一步中由 Vulcan 服务器构建的 tar 放入公共可访问服务器(例如 Google Storage),然后更改 Heroku 构建包以在每个实例上下载 tar启动。

  1. heroku config:set BUILDPACK_URL=https://github.com/peterkeen/heroku-buildpack-vendorbinaries.git
  2. 供应商构建包在根目录查找 .vendor_urls 文件级别与要安装的 tar 球的 HTTP 链接(需要换行才能工作)。
    http://commondatastorage.googleapis.com/developer.you.com /hunspell-heroku-1.3.tgz
  3. Vendoring 将 tar 解压到根文件夹中,因此 Heroku 设置的 lib 路径将是“lib”。 heroku 配置:添加 LD_LIBRARY_PATH=lib

You need to build the required Hunspell library and include it in your Heroku project directly.

Heroku runs on 64-bit Ubuntu therefore the binary has to be compiled under that system. The best approach is to simply use Heroku's Vulcan build server to compile on a Heroku instance.

Compiling for Heroku

  1. gem install vulcan
  2. vulcan create vulcan-compile-me last argument is your own app name.
  3. Download Hunspell source
  4. Extract
  5. vulcan build -v -s ./hunspell-1.3.2 Tells Vulcan to build it and downloads the finished product automatically to /tmp/hunspell..

The build server requires the cloudant add-on, this is installed automatically but you have to make sure to have a verified (credit card added) Heroku account. If you get errors in step six of no build output then do heroku addons:add cloudant --app vulcan-compile-me

Adding to Your Project

  1. Extract the Heroku Vulcan build tar from /tmp
  2. Copy the entire lib folder to vendor/hunspell in your project root directory
  3. Tell Heroku where to look for libraries: heroku config:add LD_LIBRARY_PATH=vendor/hunspell/lib.

Install Dictionaries

Download some dictionaries from Open Office and add them to your project. A good location is a folder called dictionaries at root level. This path is then referenced when initializing Hunspell in Ruby.

http://extensions.services.openoffice.org/dictionary

ftp://sunsite.informatik.rwth-aachen.de/pub/mirror/OpenOffice/contrib/

Using

Install your favorite Hunspell gem, I use hunspell-ffi. There is a newer gem for Hunspell but I prefer the previous FFI gem. To use initialize the Hunspell object with your dictionaries folder path and language (language match the dictionary file name).

dict = Hunspell.new("dictionaries", "en_US")

if dict.check('caribean') == false
    suggestions = dict.suggest('caribean')
    if (suggestions.size)
        correction = suggestions.first # returns 'caribbean'
    end
end

Vendoring for More Complex Projects

You can also vendor the library into your project by putting the tar built by the Vulcan server in the first step into a public accessible server such as Google Storage and then changing the Heroku build pack to download the tar on each instance startup.

  1. heroku config:set BUILDPACK_URL=https://github.com/peterkeen/heroku-buildpack-vendorbinaries.git
  2. The vendor build pack looks for a .vendor_urls file at the root level with HTTP links to the tar balls to install (needs to end in a new line to work).
    http://commondatastorage.googleapis.com/developer.you.com/hunspell-heroku-1.3.tgz
  3. Vendoring unpacks the tar into the root folder so the lib path for the Heroku settings would then just be "lib". heroku config:add LD_LIBRARY_PATH=lib
不及他 2024-12-06 16:15:35

除非我弄错了或者发生了一些变化(我找不到任何证据),否则您无法在 Heroku 上安装外部本机库。如果尚未安装该库(我认为 ImageMagick 可能是这种情况,也许还有其他库),您将无法使用 gem。

Unless I am mistaken or something has changed (I cannot find any evidence of this), you cannot install external native libraries on Heroku. If the library is not already installed (this is the case, I think, for ImageMagick, and perhaps others), you will not be able to use the gem.

花开浅夏 2024-12-06 16:15:35

查看此网址: http://gems-summary.heroku.com/2011-07-19

Heroku 对 gem 社区的支持之多令人惊讶。因此,您所需要做的就是将 gem 添加到您的捆绑包中,因为 Hunspell 位于 ruby​​gems 上,捆绑安装,然后部署。

Gemfile

source 'http://rubygems.org'
gem 'rails', '3.0.5'
gem 'hunspell'

然后添加到 git:

git add .
git commit -m 'added hunspell'

然后捆绑:

bundle

并部署:

 git push heroku

Checkout this url: http://gems-summary.heroku.com/2011-07-19

It's freaking amazing how much support Heroku has for the gem community. So all you need to to is add the gem to your bundle since Hunspell is on rubygems, bundle install, and then deploy.

Gemfile

source 'http://rubygems.org'
gem 'rails', '3.0.5'
gem 'hunspell'

Then add to git:

git add .
git commit -m 'added hunspell'

Then bundle:

bundle

And deploy:

 git push heroku
想你的星星会说话 2024-12-06 16:15:35

使用 Bundler,您应该能够安装任何 gem。根据 http://devcenter.heroku.com /articles/how-do-i-install-gems-for-my-app,“几乎所有 gem - 即使是具有本机依赖项的 gem - 都可以使用 Bundler 安装。如果存在无法安装的特定 gem在 Heroku 上,请提交支持票。”

AFAIK,当您的应用程序启动时,Gemfile 中的 gem 会即时安装到您的应用程序启动的服务器上。

Aspen 堆栈已预安装 gem,但您仍然应该能够添加未预安装的 gem。

竹子堆栈没有预先安装的gem,因此必须显式声明所有gem依赖项。我相信青瓷堆栈也是如此。

With Bundler, you should be able to install any gem. According to http://devcenter.heroku.com/articles/how-do-i-install-gems-for-my-app, "Almost any gem - even those with native dependencies - can be installed using Bundler. If there’s a specific gem that won’t install on Heroku, please submit a support ticket."

AFAIK, when your app is spun up, gems in the Gemfile are installed on-the-fly to the server your app is spun up to.

The Aspen stack has pre-installed gems, but you still should be able to add gems not pre-installed.

The bamboo stack has no pre-installed gems, so all gem dependencies must be declared explicitly. I believe that is the same for the Celadon stack.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文