text_hyphen 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+ # Text::Hyphen -- text-hyphen -- 16.03.2004 -- hwyss@ywesee.com
3
+
4
+ require 'text_hyphen.so'
5
+
6
+ VERSION = '1.0.0'
7
+
8
+ module Text
9
+ module Hyphen
10
+ class Dictionary
11
+ def best_chance(word)
12
+ weights = analyze(word)
13
+ best = weights.max
14
+ if(best > 0)
15
+ weights.index(best) + 1
16
+ end
17
+ end
18
+ def best_chance_before(pos, word)
19
+ weights = analyze(word)
20
+ valid = weights[0,pos]
21
+ best = valid.max
22
+ if(best > 0)
23
+ valid.rindex(best) + 1
24
+ end
25
+ end
26
+ def first_chance(word)
27
+ idx = 0
28
+ analyze(word).any? { |weight|
29
+ idx += 1
30
+ if(weight > 0)
31
+ return idx
32
+ end
33
+ }
34
+ nil
35
+ end
36
+ def hyphenate_best(word)
37
+ hyph = word.dup
38
+ if(pos = best_chance(word))
39
+ hyph[pos,0] = '-'
40
+ end
41
+ hyph
42
+ end
43
+ def hyphenate_best_before(pos, word)
44
+ hyph = word.dup
45
+ if(pos = best_chance_before(pos, word))
46
+ hyph[pos,0] = '-'
47
+ end
48
+ hyph
49
+ end
50
+ def hyphenate_first(word)
51
+ hyph = word.dup
52
+ if(pos = first_chance(word))
53
+ hyph[pos,0] = '-'
54
+ end
55
+ hyph
56
+ end
57
+ def hyphenate_before(pos, word)
58
+ hyph = word.dup
59
+ if(pos = last_chance_before(pos, word))
60
+ hyph[pos,0] = '-'
61
+ end
62
+ hyph
63
+ end
64
+ def last_chance_before(pos, word)
65
+ weights = analyze(word)
66
+ pos.downto(0) { |pos|
67
+ if(weights.at(pos - 1) > 0)
68
+ return pos
69
+ end
70
+ }
71
+ nil
72
+ end
73
+ end
74
+ end
75
+ end
Binary file
@@ -0,0 +1,15 @@
1
+ Hyphenation dictionary
2
+ ----------------------
3
+
4
+ Language: German (de DE).
5
+ Origin: Based on the TeX hyphenation tables
6
+ License: GNU LGPL license.
7
+ Author: conversion author is Marco Huggenberger<marco@by-night.ch>
8
+
9
+ Please note, this dictionary is based on syllable matching patterns
10
+ and thus should be suitable under other variations of German
11
+
12
+ HYPH de DE hyph_de
13
+ HYPH de CH hyph_de
14
+
15
+