Skip to content

Commit

Permalink
Added saveToDisk method to NER
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Aug 29, 2022
1 parent 3bd7308 commit 3abdc4e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 0.1.2 (unreleased)

- Added support for text categorization
- Added `saveToDisk` method to `NER`

## 0.1.1 (2022-08-28)

Expand Down
7 changes: 7 additions & 0 deletions src/NER.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public function entities($text)
return $this->doc($text)->entities();
}

public function saveToDisk($filename)
{
if ($this->ffi->mitie_save_named_entity_extractor($filename, $this->pointer) != 0) {
throw new Exception('Unable to save model');
}
}

public function tokens($text)
{
return $this->doc($text)->tokens();
Expand Down
16 changes: 16 additions & 0 deletions tests/NERTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,20 @@ public function testMissingFile()

new Mitie\NER('missing.dat');
}

public function testSaveToDisk()
{
$path = tempnam(sys_get_temp_dir(), 'model');
$this->model()->saveToDisk($path);
$this->assertFileExists($path);
unlink($path);
}

public function testSaveToDiskError()
{
$this->expectException(Mitie\Exception::class);
$this->expectExceptionMessage('Unable to save model');

$this->model()->saveToDisk('missing/ner_model.dat');
}
}

0 comments on commit 3abdc4e

Please sign in to comment.