From 620446455d4ff740332e452bb2312808d4e9f2db Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Thu, 15 Aug 2019 00:27:16 -0700 Subject: [PATCH] Add NLTK: Natural Language Toolkit (#360) --- CHANGELOG.md | 4 ++++ packages/nltk/meta.yaml | 9 +++++++++ packages/nltk/test_nltk.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 packages/nltk/meta.yaml create mode 100644 packages/nltk/test_nltk.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bb53243f..a5203640f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Unreleased +- The built-in `sqlite3** module of Python is now enabled. + +- New package: `nltk` + ## Version 0.13.0 - Tagged versions of Pyodide are now deployed to Netlify. diff --git a/packages/nltk/meta.yaml b/packages/nltk/meta.yaml new file mode 100644 index 000000000..a40a52ea3 --- /dev/null +++ b/packages/nltk/meta.yaml @@ -0,0 +1,9 @@ +package: + name: nltk + version: '3.4' +source: + sha256: 286f6797204ffdb52525a1d21ec0a221ec68b8e3fa4f2d25f412ac8e63c70e8d + url: https://files.pythonhosted.org/packages/6f/ed/9c755d357d33bc1931e157f537721efb5b88d2c583fe593cc09603076cc3/nltk-3.4.zip +test: + imports: + - nltk diff --git a/packages/nltk/test_nltk.py b/packages/nltk/test_nltk.py new file mode 100644 index 000000000..616de6445 --- /dev/null +++ b/packages/nltk/test_nltk.py @@ -0,0 +1,28 @@ +import pytest + + +def test_nltk_edit_distance(selenium): + selenium.load_package('nltk') + selenium.run('import nltk') + edit_distance = selenium.run("nltk.edit_distance('foo', 'food')") + assert edit_distance == 1 + + +def test_nltk_jaccard_distance(selenium): + selenium.load_package('nltk') + selenium.run('import nltk') + jaccard_distance = selenium.run(""" + nltk.jaccard_distance(set('mapping'), set('mappings')) + """) + assert jaccard_distance == pytest.approx(0.1428571) + + +def test_nltk_ngrams(selenium): + selenium.load_package('nltk') + selenium.run('import nltk') + ngrams = selenium.run("list(nltk.ngrams('master', n=3))") + assert len(ngrams) == 4 + assert ngrams[0] == ['m', 'a', 's'] + assert ngrams[1] == ['a', 's', 't'] + assert ngrams[2] == ['s', 't', 'e'] + assert ngrams[3] == ['t', 'e', 'r']