Skip to content

Commit e4e5a85

Browse files
committed
Working better now...
setup.py: Use namespace packages. Put this under namespace PyMathics. natlang/__main__.py: With next round of changes, we don't need to set "context".
1 parent 51678a7 commit e4e5a85

File tree

3 files changed

+4
-46
lines changed

3 files changed

+4
-46
lines changed

pymathics/__init__.py

Whitespace-only changes.

pymathics/natlang/__main__.py

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,6 @@ class WordFrequencyData(_SpacyBuiltin):
290290
</dl>
291291
"""
292292

293-
context = "PyMathics`"
294-
295293
# Mathematica uses the gargantuan Google n-gram corpus, see
296294
# http://commondatastorage.googleapis.com/books/syntactic-ngrams/index.html
297295

@@ -316,8 +314,6 @@ class WordCount(_SpacyBuiltin):
316314
= 4
317315
"""
318316

319-
context = "PyMathics`"
320-
321317
def apply(self, text, evaluation, options):
322318
"WordCount[text_String, OptionsPattern[%(name)s]]"
323319
doc = self._nlp(text.get_string_value(), evaluation, options)
@@ -326,7 +322,6 @@ def apply(self, text, evaluation, options):
326322
return Integer(sum(1 for word in doc if word.pos != punctuation))
327323

328324

329-
from trepan.api import debug; debug()
330325
class TextWords(_SpacyBuiltin):
331326
"""
332327
<dl>
@@ -340,8 +335,6 @@ class TextWords(_SpacyBuiltin):
340335
= {Hickory, dickory, dock, The, mouse, ran, up, the, clock}
341336
"""
342337

343-
context = "PyMathics`"
344-
345338
def apply(self, text, evaluation, options):
346339
"TextWords[text_String, OptionsPattern[%(name)s]]"
347340
doc = self._nlp(text.get_string_value(), evaluation, options)
@@ -426,8 +419,6 @@ class DeleteStopwords(_SpacyBuiltin):
426419
= Old Man Apulia, conduct peculiar
427420
"""
428421

429-
context = "PyMathics`"
430-
431422
def apply_list(self, l, evaluation, options):
432423
"DeleteStopwords[l_List, OptionsPattern[%(name)s]]"
433424
is_stop = self._is_stop_lambda(evaluation, options)
@@ -475,8 +466,6 @@ class WordFrequency(_SpacyBuiltin):
475466
= 0.5
476467
"""
477468

478-
context = "PyMathics`"
479-
480469
options = _SpacyBuiltin.options
481470
options.update({"IgnoreCase": "False"})
482471

@@ -589,8 +578,6 @@ class TextCases(_SpacyBuiltin):
589578
= {Albert Einstein, E. Fermi, L. Szilard}
590579
"""
591580

592-
context = "PyMathics`"
593-
594581
def apply(self, text, form, evaluation, options):
595582
"TextCases[text_String, form_, OptionsPattern[%(name)s]]"
596583
doc = self._nlp(text.get_string_value(), evaluation, options)
@@ -620,8 +607,6 @@ class TextPosition(_SpacyBuiltin):
620607
= {{1, 9}, {15, 24}}
621608
"""
622609

623-
context = "PyMathics`"
624-
625610
def apply(self, text, form, evaluation, options):
626611
"TextPosition[text_String, form_, OptionsPattern[%(name)s]]"
627612
doc = self._nlp(text.get_string_value(), evaluation, options)
@@ -651,8 +636,6 @@ class TextStructure(_SpacyBuiltin):
651636
= {(Sentence, ((Verb Phrase, (Noun Phrase, (Determiner, The), (Noun, cat)), (Verb, sat), (Prepositional Phrase, (Preposition, on), (Noun Phrase, (Determiner, the), (Noun, mat))), (Punctuation, .))))}
652637
"""
653638

654-
context = "PyMathics`"
655-
656639
_root_pos = set(i for i, names in _pos_tags.items() if names[1])
657640

658641
def _to_constituent_string(self, node):
@@ -721,8 +704,6 @@ class WordSimilarity(_SpacyBuiltin):
721704
= {0.253, 0.177}
722705
"""
723706

724-
context = "PyMathics`"
725-
726707
messages = _merge_dictionaries(
727708
_SpacyBuiltin.messages,
728709
{
@@ -807,8 +788,6 @@ class WordStem(Builtin):
807788

808789
requires = ("nltk",)
809790

810-
context = "PyMathics`"
811-
812791
_stemmer = None
813792

814793
@staticmethod
@@ -822,12 +801,12 @@ def porter(w):
822801
return WordStem._get_porter_stemmer().stem(w)
823802

824803
def apply(self, word, evaluation):
825-
"WordStem[word_String]"
804+
"WordStem[word_System`String]"
826805
stemmer = self._get_porter_stemmer()
827806
return String(stemmer.stem(word.get_string_value()))
828807

829808
def apply_list(self, words, evaluation):
830-
"WordStem[words_List]"
809+
"WordStem[words_System`List]"
831810
if all(isinstance(w, String) for w in words.leaves):
832811
stemmer = self._get_porter_stemmer()
833812
return Expression(
@@ -998,8 +977,6 @@ class WordDefinition(_WordNetBuiltin):
998977
= {a metric unit of weight equal to one thousandth of a kilogram}
999978
"""
1000979

1001-
context = "PyMathics`"
1002-
1003980
def apply(self, word, evaluation, options):
1004981
"WordDefinition[word_String, OptionsPattern[%(name)s]]"
1005982
wordnet, language_code = self._load_wordnet(
@@ -1164,8 +1141,6 @@ class WordData(_WordListBuiltin):
11641141
},
11651142
)
11661143

1167-
context = "PyMathics`"
1168-
11691144
def _parse_word(self, word):
11701145
if isinstance(word, String):
11711146
return word.get_string_value().lower()
@@ -1303,8 +1278,6 @@ class DictionaryWordQ(_WordNetBuiltin):
13031278
= False
13041279
"""
13051280

1306-
context = "PyMathics`"
1307-
13081281
def apply(self, word, evaluation, options):
13091282
"DictionaryWordQ[word_, OptionsPattern[%(name)s]]"
13101283
if not isinstance(word, String):
@@ -1335,8 +1308,6 @@ class DictionaryLookup(_WordListBuiltin):
13351308
= {bake, bakeapple, baked}
13361309
"""
13371310

1338-
context = "PyMathics`"
1339-
13401311
def compile(self, pattern, evaluation):
13411312
re_patt = to_regex(pattern, evaluation)
13421313
if re_patt is None:
@@ -1396,8 +1367,6 @@ class WordList(_WordListBuiltin):
13961367
= 9.3
13971368
"""
13981369

1399-
context = "PyMathics`"
1400-
14011370
def apply(self, evaluation, options):
14021371
"WordList[OptionsPattern[%(name)s]]"
14031372
words = self._words(self._language_name(evaluation, options), "All", evaluation)
@@ -1427,8 +1396,6 @@ class RandomWord(_WordListBuiltin):
14271396
</dl>
14281397
"""
14291398

1430-
context = "PyMathics`"
1431-
14321399
def _random_words(self, type, n, evaluation, options):
14331400
words = self._words(self._language_name(evaluation, options), type, evaluation)
14341401
with RandomEnv(evaluation) as rand:
@@ -1469,8 +1436,6 @@ class LanguageIdentify(Builtin):
14691436
= German
14701437
"""
14711438

1472-
context = "PyMathics`"
1473-
14741439
requires = (
14751440
"langid",
14761441
"pycountry",
@@ -1501,8 +1466,6 @@ class Pluralize(Builtin):
15011466
= potatoes
15021467
"""
15031468

1504-
context = "PyMathics`"
1505-
15061469
requires = ("pattern",)
15071470

15081471
def apply(self, word, evaluation):
@@ -1511,7 +1474,6 @@ def apply(self, word, evaluation):
15111474

15121475
return String(pluralize(word.get_string_value()))
15131476

1514-
15151477
class SpellingCorrectionList(Builtin):
15161478
"""
15171479
<dl>
@@ -1525,8 +1487,6 @@ class SpellingCorrectionList(Builtin):
15251487
= {hippopotamus...}
15261488
"""
15271489

1528-
context = "PyMathics`"
1529-
15301490
requires = ("enchant",)
15311491

15321492
options = {

setup.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
import platform
66
import os
7-
from setuptools import setup, find_packages
7+
from setuptools import setup, find_namespace_packages
88

99
# Ensure user has the correct Python version
1010
if sys.version_info < (3, 6):
@@ -19,9 +19,7 @@
1919
setup(
2020
name="pymathics-natlang",
2121
version=__version__,
22-
packages=[
23-
"pymathics.natlang",
24-
],
22+
packages=find_namespace_packages(include=["pymathics.*"]),
2523
install_requires=["mathics>=1.0", "nltk", "spacy"],
2624
# don't pack Mathics in egg because of media files, etc.
2725
zip_safe=False,

0 commit comments

Comments
 (0)