|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +from .helper import session, check_evaluation |
| 3 | + |
| 4 | +import sys |
| 5 | +from mathics.core.parser import parse, SingleLineFeeder |
| 6 | +from mathics.core.definitions import Definitions |
| 7 | +from mathics.core.evaluation import Evaluation |
| 8 | +import pytest |
| 9 | + |
| 10 | +def test_natlang(): |
| 11 | + |
| 12 | + session.evaluate( |
| 13 | + """ |
| 14 | + LoadModule["pymathics.natlang"] |
| 15 | + """ |
| 16 | + ) |
| 17 | + |
| 18 | + for str_expr, str_expected, message in ( |
| 19 | + ( |
| 20 | + 'WordCount["A long time ago"]', |
| 21 | + "4", |
| 22 | + "WordCount", |
| 23 | + ), |
| 24 | + ( |
| 25 | + 'TextWords["Hickory, dickory, dock! The mouse ran up the clock."]', |
| 26 | + 'System`List["Hickory", "dickory", "dock", "The", "mouse", "ran", "up", "the", "clock"]', |
| 27 | + "TextWords", |
| 28 | + ), |
| 29 | + ( |
| 30 | + 'TextSentences["Night and day. Day and night."]', |
| 31 | + 'System`List["Night and day.", "Day and night."]', |
| 32 | + "TextSentences", |
| 33 | + ), |
| 34 | + ( |
| 35 | + 'TextSentences["Mr. Jones met Mrs. Jones."]', |
| 36 | + 'System`List["Mr. Jones met Mrs. Jones."]', |
| 37 | + "TextSentences with Abbreviations", |
| 38 | + ), |
| 39 | + ( |
| 40 | + 'DeleteStopwords[{"Somewhere", "over", "the", "rainbow"}]', |
| 41 | + 'System`List["rainbow"]', |
| 42 | + "DeleteStopWords", |
| 43 | + ), |
| 44 | + ( |
| 45 | + 'WordFrequency["Apple Tree", "apple", IgnoreCase -> True]', |
| 46 | + "0.5", |
| 47 | + "WordFrequency", |
| 48 | + ), |
| 49 | + ( |
| 50 | + 'TextCases["I was in London last year.", "Pronoun"]', |
| 51 | + 'System`List["I"]', |
| 52 | + "TextCases", |
| 53 | + ), |
| 54 | + ): |
| 55 | + check_evaluation(str_expr, str_expected, message) |
0 commit comments