Skip to content

Commit 8007814

Browse files
Feature: Aspell custom dictionary (#13)
* Add PersonalDictionary for Aspell * Update README and CHANGELOG * Add gitattributes for clean install package * Remove old phpunit config * Fix codesniffer errors
1 parent 5d11385 commit 8007814

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+546
-238
lines changed

.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.gitattributes export-ignore
2+
.gitignore export-ignore
3+
.travis.yml export-ignore
4+
phpunit.xml.dist export-ignore

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
# Project specifics
12
/build
3+
4+
# Composer
25
/composer.lock
36
/composer.phar
47
/vendor/
8+
9+
# Configs.
10+
/phpunit.xml

.travis.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@ language: php
33
sudo: false
44

55
php:
6-
- 5.6
7-
- 7.0
8-
- 7.1
96
- 7.2
7+
- 7.3
108

119
matrix:
1210
fast_finish: true
13-
include:
14-
- php: 5.6
15-
env:
16-
- COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
17-
- PHPUNIT_FLAGS="--coverage-clover build/logs/clover.xml"
11+
# include:
12+
# - php: 5.6
13+
# env:
14+
# - COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
15+
# - PHPUNIT_FLAGS="--coverage-clover build/logs/clover.xml"
1816

1917
before_install:
2018
- travis_retry composer self-update
19+
- sudo apt-get install aspell
2120

2221
install:
2322
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction
2423

2524
script:
2625
- mkdir -p build/logs
26+
- vendor/bin/phpcs --standard=PSR12 src/ tests/
2727
- vendor/bin/phpunit ${PHPUNIT_FLAGS}
2828

2929
after_script:

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@
1111

1212
- PHP 7 support.
1313

14+
## 2.0
15+
16+
- Add custom dictionary support for aspell
17+
- Raise PHP requirement to 7.2
18+
- Dropped `@deprecated` interfaces
1419

1520
## 1.7.2 - 2017-04-30
1621

1722
### Fixed
1823

19-
- HtmlFilter: <script> content should be filtered out.
24+
- HtmlFilter: `<script>` content should be filtered out.
2025
- HtmlFilter: only for "keywords" and "description" meta tags "content" attr should be treated as
2126
string.
2227

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,23 @@ use Mekras\Speller\Aspell\Aspell;
7373
$speller = new Aspell('/usr/local/bin/aspell');
7474
```
7575

76+
### Custom Dictionary
77+
78+
You can use a custom dictionary for aspell. The dictionary needs to be in the following format:
79+
80+
```
81+
personal_ws-1.1 [lang] [words]
82+
```
83+
84+
Where `[lang]` shout be the shorthand for the language you are using (e.g. `en`) and `[words]` is the count
85+
of words inside the dictionary. **Beware** that there should no spaces at the end of words. Each word should be listed
86+
in a new line.
87+
88+
```php
89+
$aspell = new Aspell();
90+
$aspell->setPersonalDictionary(new Dictionary('/path/to/custom.pws'));
91+
```
92+
7693
### Important
7794

7895
- aspell allow to specify only one language at once, so only first item taken from

composer.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,21 @@
1313
{
1414
"name": "Михаил Красильников",
1515
"email": "[email protected]"
16+
},
17+
{
18+
"name": "Andreas Frömer",
19+
"email": "[email protected]"
1620
}
1721
],
1822
"require": {
19-
"php": ">=5.6",
20-
"symfony/process": "^3.0|^4.0"
23+
"php": "^7.2",
24+
"symfony/process": "^4.0"
2125
},
2226
"require-dev": {
23-
"phpunit/phpunit": "^5.0",
24-
"php-coveralls/php-coveralls": "^2.0"
27+
"phpunit/phpunit": "^7.5",
28+
"php-coveralls/php-coveralls": "^2.0",
29+
"satooshi/php-coveralls": "^1.0",
30+
"squizlabs/php_codesniffer": "^3.2"
2531
},
2632
"autoload": {
2733
"psr-4": {
@@ -32,5 +38,8 @@
3238
"psr-4": {
3339
"Mekras\\Speller\\Tests\\": "tests"
3440
}
41+
},
42+
"config": {
43+
"sort-packages": true
3544
}
3645
}

phpunit.xml.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
convertWarningsToExceptions="true"
66
processIsolation="false"
77
stopOnFailure="false"
8-
syntaxCheck="false"
98
bootstrap="vendor/autoload.php"
109
>
1110
<testsuites>

src/Aspell/Aspell.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
namespace Mekras\Speller\Aspell;
1111

12+
use Mekras\Speller\Dictionary;
1213
use Mekras\Speller\Exception\ExternalProgramFailedException;
1314
use Mekras\Speller\Ispell\Ispell;
1415
use Mekras\Speller\Source\EncodingAwareSource;
15-
use Mekras\Speller\Source\Source;
1616
use Symfony\Component\Process\Exception\InvalidArgumentException;
1717
use Symfony\Component\Process\Exception\LogicException;
1818
use Symfony\Component\Process\Exception\RuntimeException;
@@ -31,6 +31,11 @@ class Aspell extends Ispell
3131
*/
3232
private $supportedLanguages = null;
3333

34+
/**
35+
* @var Dictionary
36+
*/
37+
private $personalDictionary;
38+
3439
/**
3540
* Create new aspell adapter.
3641
*
@@ -88,22 +93,25 @@ public function getSupportedLanguages()
8893
return $this->supportedLanguages;
8994
}
9095

96+
/**
97+
* @param Dictionary $dictionary
98+
*/
99+
public function setPersonalDictionary(Dictionary $dictionary)
100+
{
101+
$this->personalDictionary = $dictionary;
102+
}
103+
91104
/**
92105
* Create arguments for external speller.
93106
*
94-
* @param Source $source Text source to check.
95-
* @param array $languages List of languages used in text (IETF language tag).
107+
* @param EncodingAwareSource $source Text source to check.
108+
* @param array $languages List of languages used in text (IETF language tag).
96109
*
97110
* @return string[]
98111
*
99-
* @throws ExternalProgramFailedException
100-
* @throws InvalidArgumentException
101-
* @throws LogicException
102-
* @throws RuntimeException
103-
*
104112
* @since 1.6
105113
*/
106-
protected function createArguments(Source $source, array $languages)
114+
protected function createArguments(EncodingAwareSource $source, array $languages)
107115
{
108116
$args = [
109117
// Input encoding
@@ -116,6 +124,10 @@ protected function createArguments(Source $source, array $languages)
116124
$args[] = '--lang=' . $languages[0];
117125
}
118126

127+
if ($this->personalDictionary !== null) {
128+
$args[] = '--personal=' . $this->personalDictionary->getPath();
129+
}
130+
119131
return $args;
120132
}
121133
}

src/Dictionary.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* PHP Speller.
4+
*
5+
* @copyright 2017, Михаил Красильников <[email protected]>
6+
* @author Михаил Красильников <[email protected]>
7+
* @license http://opensource.org/licenses/MIT MIT
8+
*/
9+
10+
namespace Mekras\Speller;
11+
12+
/**
13+
* Representing any dictionary for a certain speller
14+
*/
15+
class Dictionary
16+
{
17+
/** @var string */
18+
private $dictionaryPath;
19+
20+
/**
21+
* @param string $path
22+
*/
23+
public function __construct(string $path)
24+
{
25+
$this->dictionaryPath = $path;
26+
}
27+
28+
/**
29+
* @return string
30+
*/
31+
public function getPath()
32+
{
33+
return $this->dictionaryPath;
34+
}
35+
}

0 commit comments

Comments
 (0)