TokenizerProjectUT 0.0.1

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.
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,6 @@
1
+ ==COMPLETED
2
+ ===0.0.1
3
+ Program structure and very simple tokenization.
4
+ ==PLANNED
5
+ ===0.0.2
6
+ Correct tokenization of punctuation.
data/LICENSE.rdoc ADDED
@@ -0,0 +1,4 @@
1
+ = LICENSE file
2
+ == Description
3
+ This file is licensed to David Alfter and may not be used without consent by aforementionned person.
4
+ By reading this, you agree to these terms.
data/README.rdoc ADDED
@@ -0,0 +1,20 @@
1
+ = Tokenizer Project
2
+ == DESCRIPTION
3
+ This is a tokenizer intended for simple tasks.
4
+ === Implemented Features
5
+ * simple string tokenization
6
+ * test structure
7
+ == Installation
8
+ If you don't know how to install this,... you have a problem.
9
+ == Synopsis
10
+ The synopsis is not implemented.
11
+ == Support
12
+ No support has been implemented.
13
+ == Changelog
14
+ For further information on the evolution of this tokenizer, see the CHANGELOG.rdoc file.
15
+ == Caution
16
+ Keep quiet while using this tokenizer. Loud noises may or may not interfere with function.
17
+ == License
18
+ This file is licensed under the conditions listed in the LICENSE.rdoc file.
19
+ == Version
20
+ The actual version of this tokenizer can be found in the lib/tokenizer/version.rb file.
data/bin/tokenize ADDED
@@ -0,0 +1,7 @@
1
+ require 'tokenizer'
2
+
3
+ options = :de
4
+ t = Tokenizer::Tokenizer.new(options)
5
+ while str = gets
6
+ puts t.tokenize(str)
7
+ end
data/lib/tokenizer.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'tokenizer/version'
2
+ require 'tokenizer/tokenizer'
3
+
@@ -0,0 +1,23 @@
1
+ # :title: My cool Tokenizer!!!
2
+ # :main: README.rdoc
3
+ #The module Tokenizer is the namespace for this project.
4
+ module Tokenizer
5
+ #The class Tokenizer defines the tokenizer itself.
6
+ class Tokenizer
7
+
8
+ @lang
9
+ #WL is the word limit used by the tokenizer.
10
+ WL = /\s+/
11
+ #Constructs a Tokenizer with specified language. Standard = :de
12
+ def initialize(lang = :de)
13
+ @lang = lang
14
+ end
15
+ #Returns the tokens contained in the given string.
16
+ def tokenize(str)
17
+
18
+ tokens = str.split(WL)
19
+
20
+ tokens
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,4 @@
1
+ module Tokenizer
2
+ #This is the current version.
3
+ VERSION = '0.0.1'
4
+ end
@@ -0,0 +1,283 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test/unit'
3
+ require 'tokenizer'
4
+
5
+ class TestTokenizerDev < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @de_tokenizer = Tokenizer::Tokenizer.new(:de)
9
+ end
10
+
11
+ def test_tokenization_001
12
+ input = 'ich ging? du, und ich nicht (konnte nicht)? Warum?!!'
13
+ etalon = %w{ ich ging ? du , und ich nicht ( konnte nicht ) ? Warum ? ! !}
14
+ compare(etalon, input)
15
+ end
16
+
17
+ def test_tokenization_002
18
+ input = "Die deutschen Umlaute und Sonderzeichen, wie in Mäuse, Scheiß und Tütchen, sind blöd!"
19
+ etalon = %w{Die deutschen Umlaute und Sonderzeichen , wie in Mäuse , Scheiß und Tütchen , sind blöd !}
20
+ compare(etalon, input)
21
+ end
22
+
23
+ def test_tokenization_003
24
+ input = "Abkürzungen, wie z.B. usw. und d.h. können zu Problemem führen."
25
+ etalon = %w{Abkürzungen , wie z.B. usw. und d.h. können zu Problemem führen .}
26
+ compare(etalon, input)
27
+ end
28
+
29
+ def test_tokenization_004
30
+ input = "Es gibt mehr als 1.023.345 Menschen in Deutschland, die keine Tausenderpunkte verstehen."
31
+ etalon = %w{Es gibt mehr als 1.023.345 Menschen in Deutschland , die keine Tausenderpunkte verstehen .}
32
+ compare(etalon, input)
33
+ end
34
+
35
+ def test_tokenization_005
36
+ input = "Cocktails, wie Apfel-Martini, Rum-Kirsche-Cola und andere, bereiten nicht nur Menschen Probleme."
37
+ etalon = %w{ Cocktails , wie Apfel-Martini , Rum-Kirsche-Cola und andere , bereiten nicht nur Menschen Probleme . }
38
+ compare(etalon, input)
39
+ end
40
+
41
+ def test_tokenization_006
42
+ input = 'Es gibt viele verschiedene Zeichen, die noch in Texten vorkommen können wie - zum Beispiel - diese hier "text" oder (text).'
43
+ etalon = %w{Es gibt viele verschiedene Zeichen , die noch in Texten vorkommen können wie - zum Beispiel - diese hier " text " oder ( text ) .}
44
+ compare(etalon, input)
45
+ end
46
+
47
+ def test_tokenization_007
48
+ input = "Abkürzungen sind immer ein Problem, da auch Leerzeichen dazwischen stehen können, wie z. B. hier."
49
+ etalon = ["Abkürzungen", "sind", "immer", "ein", "Problem", ",", "da", "auch", "Leerzeichen", "dazwischen", "stehen", "können", ",", "wie", "z. B.", "hier", "."]
50
+ compare(etalon, input)
51
+ end
52
+
53
+ def test_tokenization_008
54
+ input = "Außerdem kann es nach Abkürzungen und Satzenden auch mit Großschreibung weiter gehen, bei z.B. Aufzählungen."
55
+ etalon = %w{Außerdem kann es nach Abkürzungen und Satzenden auch mit Großschreibung weiter gehen , bei z.B. Aufzählungen .}
56
+ compare(etalon, input)
57
+ end
58
+
59
+ def test_tokenization_009
60
+ input = "Ein weiteres Problem sind solche Getrennt- und Zusammenschreibungen."
61
+ etalon = %w{Ein weiteres Problem sind solche Getrenntschreibungen und Zusammenschreibungen .}
62
+ compare(etalon, input)
63
+ end
64
+
65
+ def test_tokenization_010
66
+ input = "In manchen Texten gibt es auch Worttrennung am Zeilen- ende."
67
+ etalon = %w{In manchen Texten gibt es auch Worttrennung am Zeilenende .}
68
+ compare(etalon, input)
69
+ end
70
+
71
+ def test_tokenization_011 #Ellipsis
72
+ input = "Der Satz endet in einer Ellips..."
73
+ etalon = %w{ Der Satz endet in einer Ellips... } #die elliptischen Punkte sollten nicht vom Wort getrennt werden
74
+ compare(etalon, input)
75
+ end
76
+
77
+ def test_tokenization_012 #Fehlende Leerzeichen
78
+ input = "Der Satz endet.Das Leerzeichen fehlt."
79
+ etalon = %w{ Der Satz endet . Das Leerzeichen fehlt . } #/\.\s(?=[A-Z])/ wuerde die Saetze nicht trennen
80
+ compare(etalon, input)
81
+ end
82
+
83
+ def test_tokenization_013 #Bindestriche
84
+ input = "Das Bindeglied - manisch-depressives Verhalten, binden-verbinden"
85
+ etalon = %w{ Das Bindeglied - manisch-depressives Verhalten , binden - verbinden}
86
+ compare(etalon, input)
87
+ end
88
+
89
+ def test_tokenization_014 #Abkuerzungen
90
+ input = "Der Satz enthielt z.B. Fehler"
91
+ etalon = %w{ Der Satz enthielt z.B. Fehler } #/\.\s(?=[A-Z])/ wuerde hinter Punkt den Satz beenden
92
+ compare(etalon, input)
93
+ end
94
+
95
+ def test_tokenization_015 #Fehlende Grossbuchstaben
96
+ input = "Der Satz endet. der Satz beginnt"
97
+ etalon = %w{ Der Satz endet . der Satz beginnt } #/\.\s(?=[A-Z])/ wuerde die Saetze nicht trennen
98
+ compare(etalon, input)
99
+ end
100
+
101
+ def test_tokenization_016 #Franzoesisch
102
+ input = "L'art de l'univers, c'est un art"
103
+ etalon = %w{ L' art de l' univers , c'est un art } #Kontrovers!
104
+ compare(etalon, input)
105
+ end
106
+
107
+ def test_tokenization_017 #James Bond
108
+ input = "Bond,... James Bond."
109
+ etalon = %w{ Bond , ... James Bond . } #Kontrovers!
110
+ compare(etalon, input)
111
+ end
112
+
113
+ def test_tokenization_018 #Inches
114
+ input = "The square had four 9\" sides"
115
+ etalon = %w{ The square had four 9" sides }
116
+ compare(etalon, input)
117
+ end
118
+
119
+ def test_tokenization_019 #Abkuerzung zugleich Lexikon-Eintrag
120
+ input = "In fig. 3, a fig can be seen. Fig. no. 4 shows no fig."
121
+ etalon = %w{ In fig. 3 , a fig can be seen . Fig. no. 4 shows no fig . } #fig sowohl als Abkuerzung als auch als Wort
122
+ compare(etalon, input)
123
+ end
124
+
125
+ def test_tokenization_020 #Leerzeichen-getrennte Zusammengehörigkeiten
126
+ input = "They booked the flight New York-Los Angeles"
127
+ etalon = ["They", "booked", "the", "flight", "New York", "-", "Los Angeles"] #oder mit Bindestrich verbunden
128
+ compare(etalon, input)
129
+ end
130
+
131
+ def test_tokenization_021 #Ordinale
132
+ input = "Der 1. Platz ging an den Sieger"
133
+ etalon = %w{ Der 1. Platz ging an den Sieger }
134
+ compare(etalon, input)
135
+ end
136
+
137
+ def test_tokenization_022 #Klitika
138
+ input = "Er war's, stimmt's?"
139
+ etalon = %w{ Er war es , stimmt es ? } #Kontrovers! Benoetigt komplexere Analyse
140
+ compare(etalon, input)
141
+ end
142
+
143
+ def test_tokenization_023 #Datums- und Zeitangaben
144
+ input = "Es passierte am 13. Januar 2011 um 12:13 Uhr"
145
+ etalon = [ "Es", "passierte", "am", "13. Januar 2011", "um", "12:13 Uhr"]
146
+ compare(etalon, input)
147
+ end
148
+
149
+ def test_tokenization_024 #Eingebettete Saetze
150
+ input = "\"This is all?\" George asked."
151
+ etalon = %w{ This is all ? George asked . } #kann zu ungrammatischen Saetzen fuehren
152
+ compare(etalon, input)
153
+ end
154
+
155
+ def test_tokenization_025 #Eingebettete Saetze 2
156
+ input = "\"Das ist alles?\" fragte sie."
157
+ etalon = %w{ Das ist alles ? fragte sie . } #ungrammatischer Satz "fragte sie."
158
+ compare(etalon, input)
159
+ end
160
+
161
+
162
+ def test_tokenization_026
163
+ input = "Die deutschen Umlaute und Sonderzeichen, wie in Mäuse, Scheiß und Tütchen, sind blöd!"
164
+ etalon = %w{ Die deutschen Umlaute und Sonderzeichen , wie in Mäuse , Scheiß und Tütchen , sind blöd ! }
165
+ compare(etalon, input)
166
+ end
167
+
168
+ def test_tokenization_027
169
+ input = "Abkürzungen, wie z.B. usw. und d.h. können zu Problemem führen."
170
+ etalon = %w{ Abkürzungen , wie z.B. usw. und d.h. können zu Problemem führen . }
171
+ compare(etalon, input)
172
+ end
173
+
174
+ def test_tokenization_028
175
+ input = "Es gibt mehr als 1.023.345 Menschen in Deutschland, die keine Tausenderpunkte verstehen."
176
+ etalon = %w{ Es gibt mehr als 1.023.345 Menschen in Deutschland , die keine Tausenderpunkte verstehen . }
177
+ compare(etalon, input)
178
+ end
179
+
180
+ def test_tokenization_029
181
+ input = "Cocktails, wie Apfel-Martini, Rum-Kirsche-Cola und andere, bereiten nicht nur Menschen Probleme."
182
+ etalon = %w{ Cocktails , wie Apfel-Martini , Rum-Kirsche-Cola und andere , bereiten nicht nur Menschen Probleme . }
183
+ compare(etalon, input)
184
+ end
185
+
186
+ def test_tokenization_030 #Ellipsis
187
+ input = "Der Satz endet in einer Ellips..."
188
+ etalon = %w{ Der Satz endet in einer Ellips... } #die elliptischen Punkte sollten nicht vom Wort getrennt werden
189
+ compare(etalon, input)
190
+ end
191
+
192
+ def test_tokenization_031 #Fehlende Leerzeichen
193
+ input = "Der Satz endet.Das Leerzeichen fehlt."
194
+ etalon = %w{ Der Satz endet . Das Leerzeichen fehlt . } #/\.\s(?=[A-Z])/ wuerde die Saetze nicht trennen
195
+ compare(etalon, input)
196
+ end
197
+
198
+ def test_tokenization_032 #Bindestriche
199
+ input = "Das Bindeglied - manisch-depressives Verhalten, binden-verbinden"
200
+ etalon = %w{ Das Bindeglied - manisch-depressives Verhalten , binden - verbinden}
201
+ compare(etalon, input)
202
+ end
203
+
204
+ def test_tokenization_033 #Abkuerzungen
205
+ input = "Der Satz enthielt z.B. Fehler"
206
+ etalon = %w{ Der Satz enthielt z.B. Fehler } #/\.\s(?=[A-Z])/ wuerde hinter Punkt den Satz beenden
207
+ compare(etalon, input)
208
+ end
209
+
210
+ def test_tokenization_034 #Fehlende Grossbuchstaben
211
+ input = "Der Satz endet. der Satz beginnt"
212
+ etalon = %w{ Der Satz endet . der Satz beginnt } #/\.\s(?=[A-Z])/ wuerde die Saetze nicht trennen
213
+ compare(etalon, input)
214
+ end
215
+
216
+ def test_tokenization_035 #Franzoesisch
217
+ input = "L'art de l'univers, c'est un art"
218
+ etalon = %w{ L' art de l' univers , c'est un art } #Kontrovers!
219
+ compare(etalon, input)
220
+ end
221
+
222
+ def test_tokenization_036 #James Bond
223
+ input = "Bond,... James Bond."
224
+ etalon = %w{ Bond , ... James Bond . } #Kontrovers!
225
+ compare(etalon, input)
226
+ end
227
+
228
+ def test_tokenization_037 #Inches
229
+ input = "The square had four 9\" sides"
230
+ etalon = %w{ The square had four 9" sides }
231
+ compare(etalon, input)
232
+ end
233
+
234
+ def test_tokenization_039 #Abkuerzung zugleich Lexikon-Eintrag
235
+ input = "In fig. 3, a fig can be seen. Fig. no. 4 shows no fig."
236
+ etalon = %w{ In fig. 3 , a fig can be seen . Fig. no. 4 shows no fig . } #fig sowohl als Abkuerzung als auch als Wort
237
+ compare(etalon, input)
238
+ end
239
+
240
+ def test_tokenization_040 #Leerzeichen-getrennte Zusammengehörigkeiten
241
+ input = "They booked the flight New York-Los Angeles"
242
+ etalon = ["They", "booked", "the", "flight", "New York", "-", "Los Angeles"] #oder mit Bindestrich verbunden
243
+ compare(etalon, input)
244
+ end
245
+
246
+ def test_tokenization_041 #Ordinale
247
+ input = "Der 1. Platz ging an den Sieger"
248
+ etalon = %w{ Der 1. Platz ging an den Sieger }
249
+ compare(etalon, input)
250
+ end
251
+
252
+ def test_tokenization_042 #Klitika
253
+ input = "Er war's, stimmt's?"
254
+ etalon = %w{ Er war es , stimmt es ? } #Kontrovers! Benoetigt komplexere Analyse
255
+ compare(etalon, input)
256
+ end
257
+
258
+ #Datums- und Zeitangaben
259
+ def test_tokenization_043
260
+ input = "Es passierte am 13. Januar 2011 um 12:13 Uhr"
261
+ etalon = ["Es", "passierte", "am", "13. Januar 2011", "um", "12:13 Uhr"]
262
+ compare(etalon, input)
263
+ end
264
+
265
+ #Eingebettete Sätze
266
+ def test_tokenization_044
267
+ input = '"This is all?" George asked.'
268
+ etalon = %w{ This is all ? George asked . } #kann zu ungrammatischen Saetzen fuehren
269
+ compare(etalon, input)
270
+ end
271
+
272
+ def test_tokenization_046 #Eingebettete Saetze 2
273
+ input = '"Das ist alles?" fragte sie.'
274
+ etalon = %w{Das ist alles ? fragte sie .} #ungrammatischer Satz "fragte sie."
275
+ compare(etalon, input)
276
+ end
277
+
278
+ private
279
+ def compare(exp_result, input)
280
+ act_result = @de_tokenizer.tokenize(input)
281
+ assert_equal(exp_result, act_result)
282
+ end
283
+ end
@@ -0,0 +1,31 @@
1
+ require 'tokenizer/tokenizer'
2
+ require 'test/unit'
3
+ #This is the test suite for lib/tokenizer/tokenizer.rb
4
+ class TestTokenizer < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @t = Tokenizer::Tokenizer.new
8
+ @result = @t.tokenize("test\t\n string")
9
+ end
10
+
11
+ def test_has_method
12
+ assert(@t.respond_to?(:tokenize))
13
+ end
14
+
15
+ def test_returns_array
16
+ assert_instance_of(Array, @result)
17
+ end
18
+
19
+ def test_array_not_empty
20
+ assert_equal(false, @result.empty?)
21
+ end
22
+
23
+ def test_array_contains_strings
24
+ assert_instance_of(String, @result.first)
25
+ end
26
+
27
+ def test_splits_more_whitespace
28
+ assert_equal(["test", "string"], @result)
29
+ end
30
+ end
31
+
@@ -0,0 +1,21 @@
1
+ require 'tokenizer'
2
+ require 'test/unit'
3
+ #This is the test suite for lib/tokenizer/version.rb
4
+ class TestVersion < Test::Unit::TestCase
5
+ #Setup a tokenizer
6
+ def setup
7
+ @t = Tokenizer::Tokenizer.new(:de)
8
+ end
9
+ #Test whether version is a string.
10
+ def test_version_is_string
11
+ assert(Tokenizer::VERSION.is_a?(String), "Falsche Klasse fuer Version!")
12
+ end
13
+ #Test whether version is empty.
14
+ def test_version_not_empty
15
+ assert_equal(false, Tokenizer::VERSION.empty?)
16
+ end
17
+
18
+
19
+
20
+
21
+ end #Test Version
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: TokenizerProjectUT
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Alfter
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-24 00:00:00.000000000 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+ description: A simple multilingual tokenizer for NLP tasks. This tool provides a CLI
16
+ and a library for linguistic tokenization which is an anavoidable step for many
17
+ HLT (human language technology) tasks in the preprocessing phase for further syntactic,
18
+ semantic and other higher level processing goals. Use it for tokenization of German,
19
+ English and French texts.
20
+ email: s2daalft@uni-trier.de
21
+ executables:
22
+ - tokenize
23
+ extensions: []
24
+ extra_rdoc_files:
25
+ - README.rdoc
26
+ - LICENSE.rdoc
27
+ - CHANGELOG.rdoc
28
+ files:
29
+ - lib/tokenizer.rb
30
+ - lib/tokenizer/tokenizer.rb
31
+ - lib/tokenizer/version.rb
32
+ - README.rdoc
33
+ - LICENSE.rdoc
34
+ - CHANGELOG.rdoc
35
+ - test/test_version.rb
36
+ - test/test_de_tokenizer_dev.rb
37
+ - test/test_tokenizer.rb
38
+ - bin/tokenize
39
+ has_rdoc: true
40
+ homepage:
41
+ licenses: []
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project: tokenizer
60
+ rubygems_version: 1.5.2
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Tokenizer is a linguistic tool intended to split a text into tokens.
64
+ test_files:
65
+ - test/test_version.rb
66
+ - test/test_de_tokenizer_dev.rb
67
+ - test/test_tokenizer.rb