Class Text::Hyphen
In: lib/text/hyphen.rb
Parent: Object

Introduction

Text::Hyphenhyphenate words using modified versions of TeX hyphenation patterns.

Usage

  require 'text/hyphen'
  hh = Text::Hyphen.new(:language => 'en_us', :left => 2, :right => 2)
    # Defaults to the above
  hh = TeX::Hyphen.new

  word = "representation"
  points = hyp.hyphenate(word)    #=> [3, 5, 8, 10]
  puts hyp.visualize(word)        #=> rep-re-sen-ta-tion

  en = Text::Hyphen.new(:left => 0, :right => 0)
  fr = Text::Hyphen.new(:language = "fr", :left => 0, :right => 0)
  puts en.visualise("organiser")  #=> or-gan-iser
  puts fr.visualise("organiser")  #=> or-ga-ni-ser

Description

Creates a new Hyphen object and loads the language patterns into memory. The hyphenator can then be asked for the hyphenation of a word. If no language is specified, then the language en_us (EN_US) is used by default.

Copyright:Copyright (c) 2004 - 2005 Austin Ziegler
Version:1.0.2
Based On:TeX::Hyphen 0.4 Copyright (c) 2003 - 2004 Martin DeMello and Austin Ziegler, in turn based on Perl‘s TeX::Hyphen [search.cpan.org/author/JANPAZ/TeX-Hyphen-0.140/lib/TeX/Hyphen.pm] Copyright (c) 1997 - 2002 Jan Pazdziora

Licence

Licensing for Text::Hyphen is unfortunately complex because of the various copyrights and licences of the source hyphenation files. Some of these files are available only under the TeX licence and others are available only under the GNU GPL while others are public domain. Each language file has these licences embedded within the file. Please consult each file‘s licence to ensure that it is compatible with your application.

The copyright on the Text::Hyphen application/library and the Ruby translations of hyphenation files belongs to Austin Ziegler. All other copyrights on original versions still stand; Text::Hyphen is a derivative work of these and other projects.

Application and Compilation Licences

Text::Hyphen, the application/library is licensed under the same terms as Ruby. Note that this specifically refers to the contents of bin/hyphen, lib/text/hyphen.rb, and lib/text/hyphen/language.rb.

Individual language hyphenation files are NOT licensed under these terms, but under the following MIT-style licence and the original hyphenation pattern licenses. The copyright for the original TeX hyphenation files is held by the original authors; any mistakes in conversion of these files to Ruby is attributable to the contributors to the Text::Hyphen package only.

The compilation package Text::Hyphen is licensed under the same terms as Ruby.

Blanket Language Hyphenation File Licence

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Methods

Classes and Modules

Class Text::Hyphen::Language

Constants

DEBUG = false
VERSION = '1.0.2'
DEFAULT_MIN_LEFT = 2
DEFAULT_MIN_RIGHT = 2

Attributes

iso_language  [R]  Returns the language‘s ISO 639 ID, e.g., "en_us" or "pt".
language  [RW]  The name of the language to be used in hyphenating words. This will be a two or three character ISO 639 code, with the two character form being the canonical resource name. This will load the language hyphenation definitions from text/hyphen/language/<code> as a Ruby class. The resource ‘text/hyphen/language/en_us’ defines the language class Text::Hyphen::Language::EN_US. It also defines the secondary forms Text::Hyphen::Language::EN and Text::Hyphen::Language::ENG_US.

Minimal transformations will be performed on the language code provided, such that any dashes are converted to underscores (e.g., ‘en-us’ becomes ‘en_us’) and all characters are regularised. Resource names will be downcased and class names will be upcased (e.g., ‘Pt’ for the Portuguese language becomes ‘pt’ and ‘PT’, respectively).

The language may also be specified as an instance of Text::Hyphen::Language.

left  [RW]  No fewer than this number of letters will show up to the left of the hyphen. This overrides the default specified in the language.
right  [RW]  No fewer than this number of letters will show up to the right of the hyphen. This overrides the default specified in the language.

Public Class methods

The following initializations are equivalent:

  hyp = TeX::Hyphenate.new(:language => "EU")
  hyp = TeX::Hyphenate.new { |h| h.language = "EU" }

Public Instance methods

Returns a list of places where the word can be divided, as

  hyp.hyphenate('representation')

returns [3, 5, 8, 10]. If the word has been hyphenated previously, it will be returned from a per-instance cache.

This function will hyphenate a word so that the first point is at most size characters.

Returns statistics

Returns a visualization of the hyphenation points, so:

  hyp.visualize('representation')

returns rep-re-sen-ta-tion, at least for English patterns. If the word has been visualised previously, it will be returned from a per-instance cache.

visualize(word)

Alias for visualise

[Validate]