|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
|
|
3
|
|
|
# Copyright 2014-2018 by Christopher C. Little. |
|
4
|
|
|
# This file is part of Abydos. |
|
5
|
|
|
# |
|
6
|
|
|
# Abydos is free software: you can redistribute it and/or modify |
|
7
|
|
|
# it under the terms of the GNU General Public License as published by |
|
8
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
|
9
|
|
|
# (at your option) any later version. |
|
10
|
|
|
# |
|
11
|
|
|
# Abydos is distributed in the hope that it will be useful, |
|
12
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
# GNU General Public License for more details. |
|
15
|
|
|
# |
|
16
|
|
|
# You should have received a copy of the GNU General Public License |
|
17
|
|
|
# along with Abydos. If not, see <http://www.gnu.org/licenses/>. |
|
18
|
|
|
|
|
19
|
|
|
"""abydos.tests.test_stemmer_lovins. |
|
20
|
|
|
|
|
21
|
|
|
This module contains unit tests for abydos.stemmer.lovins |
|
22
|
|
|
""" |
|
23
|
|
|
|
|
24
|
|
|
from __future__ import unicode_literals |
|
25
|
|
|
|
|
26
|
|
|
import codecs |
|
27
|
|
|
import unittest |
|
28
|
|
|
|
|
29
|
|
|
from abydos.stemmer.lovins import lovins |
|
30
|
|
|
|
|
31
|
|
|
from .. import _corpus_file |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
class LovinsTestCases(unittest.TestCase): |
|
35
|
|
|
"""Test Lovins functions. |
|
36
|
|
|
|
|
37
|
|
|
abydos.stemmer.lovins |
|
38
|
|
|
""" |
|
39
|
|
|
|
|
40
|
|
|
def test_lovins(self): |
|
41
|
|
|
"""Test abydos.stemmer.lovins.""" |
|
42
|
|
|
# base case |
|
43
|
|
|
self.assertEqual(lovins(''), '') |
|
44
|
|
|
|
|
45
|
|
|
# test cases from Lovins' "Development of a Stemming Algorithm": |
|
46
|
|
|
# http://www.mt-archive.info/MT-1968-Lovins.pdf |
|
47
|
|
|
self.assertEqual(lovins('magnesia'), 'magnes') |
|
48
|
|
|
self.assertEqual(lovins('magnesite'), 'magnes') |
|
49
|
|
|
self.assertEqual(lovins('magnesian'), 'magnes') |
|
50
|
|
|
self.assertEqual(lovins('magnesium'), 'magnes') |
|
51
|
|
|
self.assertEqual(lovins('magnet'), 'magnet') |
|
52
|
|
|
self.assertEqual(lovins('magnetic'), 'magnet') |
|
53
|
|
|
self.assertEqual(lovins('magneto'), 'magnet') |
|
54
|
|
|
self.assertEqual(lovins('magnetically'), 'magnet') |
|
55
|
|
|
self.assertEqual(lovins('magnetism'), 'magnet') |
|
56
|
|
|
self.assertEqual(lovins('magnetite'), 'magnet') |
|
57
|
|
|
self.assertEqual(lovins('magnetitic'), 'magnet') |
|
58
|
|
|
self.assertEqual(lovins('magnetizable'), 'magnet') |
|
59
|
|
|
self.assertEqual(lovins('magnetization'), 'magnet') |
|
60
|
|
|
self.assertEqual(lovins('magnetize'), 'magnet') |
|
61
|
|
|
self.assertEqual(lovins('magnetometer'), 'magnetometer') |
|
62
|
|
|
self.assertEqual(lovins('magnetometric'), 'magnetometer') |
|
63
|
|
|
self.assertEqual(lovins('magnetometry'), 'magnetometer') |
|
64
|
|
|
self.assertEqual(lovins('magnetomotive'), 'magnetomot') |
|
65
|
|
|
self.assertEqual(lovins('magnetron'), 'magnetron') |
|
66
|
|
|
self.assertEqual(lovins('metal'), 'metal') |
|
67
|
|
|
self.assertEqual(lovins('metall'), 'metal') |
|
68
|
|
|
self.assertEqual(lovins('metallically'), 'metal') |
|
69
|
|
|
self.assertEqual(lovins('metalliferous'), 'metallifer') |
|
70
|
|
|
self.assertEqual(lovins('metallize'), 'metal') |
|
71
|
|
|
self.assertEqual(lovins('metallurgical'), 'metallurg') |
|
72
|
|
|
self.assertEqual(lovins('metallurgy'), 'metallurg') |
|
73
|
|
|
self.assertEqual(lovins('induction'), 'induc') |
|
74
|
|
|
self.assertEqual(lovins('inductance'), 'induc') |
|
75
|
|
|
self.assertEqual(lovins('induced'), 'induc') |
|
76
|
|
|
self.assertEqual(lovins('angular'), 'angl') |
|
77
|
|
|
self.assertEqual(lovins('angle'), 'angl') |
|
78
|
|
|
|
|
79
|
|
|
# missed branch test cases |
|
80
|
|
|
self.assertEqual(lovins('feminism'), 'fem') |
|
81
|
|
|
|
|
82
|
|
|
def test_lovins_snowball(self): |
|
83
|
|
|
"""Test abydos.stemmer.lovins (Snowball testset). |
|
84
|
|
|
|
|
85
|
|
|
These test cases are from |
|
86
|
|
|
https://github.com/snowballstem/snowball-data/tree/master/lovins |
|
87
|
|
|
""" |
|
88
|
|
|
# Snowball Lovins test set |
|
89
|
|
|
with codecs.open(_corpus_file('snowball_lovins.csv'), |
|
90
|
|
|
encoding='utf-8') as snowball_ts: |
|
91
|
|
|
next(snowball_ts) |
|
92
|
|
|
for line in snowball_ts: |
|
93
|
|
|
if line[0] != '#': |
|
94
|
|
|
line = line.strip().split(',') |
|
95
|
|
|
word, stem = line[0], line[1] |
|
96
|
|
|
self.assertEqual(lovins(word), stem.lower()) |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
if __name__ == '__main__': |
|
100
|
|
|
unittest.main() |
|
101
|
|
|
|