datamuse 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- datamuse-0.1.0/LICENSE +21 -0
- datamuse-0.1.0/PKG-INFO +34 -0
- datamuse-0.1.0/README.md +16 -0
- datamuse-0.1.0/datamuse/__init__.py +5 -0
- datamuse-0.1.0/datamuse/annotations.py +40 -0
- datamuse-0.1.0/datamuse/datamuse.py +99 -0
- datamuse-0.1.0/datamuse.egg-info/PKG-INFO +34 -0
- datamuse-0.1.0/datamuse.egg-info/SOURCES.txt +12 -0
- datamuse-0.1.0/datamuse.egg-info/dependency_links.txt +1 -0
- datamuse-0.1.0/datamuse.egg-info/requires.txt +2 -0
- datamuse-0.1.0/datamuse.egg-info/top_level.txt +1 -0
- datamuse-0.1.0/pyproject.toml +37 -0
- datamuse-0.1.0/setup.cfg +4 -0
- datamuse-0.1.0/tests/test_datamuse.py +85 -0
datamuse-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bivas Kumar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
datamuse-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: datamuse
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: datamuse is a simple wrapper around the datamuse api https://www.datamuse.com/api/
|
|
5
|
+
Author-email: Bivas Kumar <thetrotfreak@yahoo.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://pypi.org/project/datamuse
|
|
8
|
+
Project-URL: Source, https://github.com/thetrotfreak/datamuse
|
|
9
|
+
Project-URL: Documentation, https://thetrotfreak.github.io/datamuse
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.11
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: certifi>=2026.1.4
|
|
16
|
+
Requires-Dist: urllib3>=2.6.3
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# datamuse
|
|
20
|
+
|
|
21
|
+
`datamuse` is a simple wrapper around the [datamuse](https://www.datamuse.com/) [api](https://www.datamuse.com/api/)
|
|
22
|
+
|
|
23
|
+
## Installing
|
|
24
|
+
|
|
25
|
+
You can install `datamuse` via `pip` / `pypi`:
|
|
26
|
+
|
|
27
|
+
```shell
|
|
28
|
+
pip install datamuse
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Acknowledgements
|
|
32
|
+
|
|
33
|
+
- [Harvey Beeferman, 1942–2024](https://beeferman.org/harvey/)
|
|
34
|
+
- [datamuse](https://www.datamuse.com/)
|
datamuse-0.1.0/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# datamuse
|
|
2
|
+
|
|
3
|
+
`datamuse` is a simple wrapper around the [datamuse](https://www.datamuse.com/) [api](https://www.datamuse.com/api/)
|
|
4
|
+
|
|
5
|
+
## Installing
|
|
6
|
+
|
|
7
|
+
You can install `datamuse` via `pip` / `pypi`:
|
|
8
|
+
|
|
9
|
+
```shell
|
|
10
|
+
pip install datamuse
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Acknowledgements
|
|
14
|
+
|
|
15
|
+
- [Harvey Beeferman, 1942–2024](https://beeferman.org/harvey/)
|
|
16
|
+
- [datamuse](https://www.datamuse.com/)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from types import MappingProxyType
|
|
2
|
+
from typing import Literal, LiteralString, TypeAlias
|
|
3
|
+
|
|
4
|
+
Word: TypeAlias = LiteralString
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
RelatedWordCode = Literal[
|
|
8
|
+
"nouns_adjective",
|
|
9
|
+
"adjectives_noun",
|
|
10
|
+
"synonyms",
|
|
11
|
+
"triggers",
|
|
12
|
+
"antonyms",
|
|
13
|
+
"hypernyms",
|
|
14
|
+
"hyponyms",
|
|
15
|
+
"holonyms",
|
|
16
|
+
"meronyms",
|
|
17
|
+
"frequent_followers",
|
|
18
|
+
"frequent_predecessors",
|
|
19
|
+
"homophones",
|
|
20
|
+
"consonant",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
_lookup_related_code = MappingProxyType(
|
|
25
|
+
{
|
|
26
|
+
"nouns_adjective": "jja",
|
|
27
|
+
"adjectives_noun": "jjb",
|
|
28
|
+
"synonyms": "syn",
|
|
29
|
+
"triggers": "trg",
|
|
30
|
+
"antonyms": "ant",
|
|
31
|
+
"hypernyms": "spc",
|
|
32
|
+
"hyponyms": "gen",
|
|
33
|
+
"holonyms": "com",
|
|
34
|
+
"meronyms": "par",
|
|
35
|
+
"frequent_followers": "bga",
|
|
36
|
+
"frequent_predecessors": "bgb",
|
|
37
|
+
"homophones": "hom",
|
|
38
|
+
"consonant": "cns",
|
|
39
|
+
}
|
|
40
|
+
)
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import functools
|
|
2
|
+
from typing import final
|
|
3
|
+
|
|
4
|
+
import certifi
|
|
5
|
+
import urllib3
|
|
6
|
+
|
|
7
|
+
from datamuse.annotations import RelatedWordCode, Word, _lookup_related_code
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@final
|
|
11
|
+
class Datamuse:
|
|
12
|
+
"""
|
|
13
|
+
The [Datamuse](https://www.datamuse.com/) [API](https://www.datamuse.com/api/) is a word-finding query engine for developers.
|
|
14
|
+
|
|
15
|
+
You can use it in your apps to find words that match a given set of constraints and that are likely in a given context.
|
|
16
|
+
You can specify a wide variety of constraints on meaning, spelling, sound, and vocabulary in your queries, in any combination.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
__API_URL = "api.datamuse.com"
|
|
20
|
+
__slots__ = ("__pool",)
|
|
21
|
+
|
|
22
|
+
def __init__(self) -> None:
|
|
23
|
+
self.__pool = urllib3.HTTPSConnectionPool(
|
|
24
|
+
host=self.__API_URL,
|
|
25
|
+
port=443,
|
|
26
|
+
cert_reqs="CERT_REQUIRED",
|
|
27
|
+
ca_certs=certifi.where(),
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
@functools.lru_cache
|
|
31
|
+
def __get_words(self, **kwds: Word | RelatedWordCode) -> list[Word]:
|
|
32
|
+
response = self.__pool.request(method="GET", url="/words", fields=kwds)
|
|
33
|
+
return [word["word"] for word in response.json()]
|
|
34
|
+
|
|
35
|
+
@functools.lru_cache
|
|
36
|
+
def __get_suggestions(self, **kwds: Word | RelatedWordCode) -> list[Word]:
|
|
37
|
+
response = self.__pool.request(method="GET", url="/sug", fields=kwds)
|
|
38
|
+
return [word["word"] for word in response.json()]
|
|
39
|
+
|
|
40
|
+
def synonyms(self, ml: Word):
|
|
41
|
+
"""
|
|
42
|
+
words with a meaning similar to `ml`
|
|
43
|
+
|
|
44
|
+
:param ml: means like
|
|
45
|
+
"""
|
|
46
|
+
return self.__get_words(ml=ml)
|
|
47
|
+
|
|
48
|
+
def associations(self, ml: Word, start: Word = "*", end: Word = "*"):
|
|
49
|
+
"""
|
|
50
|
+
words related to `ml`
|
|
51
|
+
|
|
52
|
+
:param ml: means like
|
|
53
|
+
:param start: start with
|
|
54
|
+
:param end: end in
|
|
55
|
+
"""
|
|
56
|
+
return self.__get_words(ml=ml, sp=start + end)
|
|
57
|
+
|
|
58
|
+
def homophones(self, sl: Word):
|
|
59
|
+
"""
|
|
60
|
+
words that sound like `sl`
|
|
61
|
+
|
|
62
|
+
:param sl: sounds like
|
|
63
|
+
"""
|
|
64
|
+
return self.__get_words(sl=sl)
|
|
65
|
+
|
|
66
|
+
def pattern(self, start: Word, end: Word, letters: int):
|
|
67
|
+
"""
|
|
68
|
+
words that start with `start`, end in `end`, and have `letters` in between
|
|
69
|
+
|
|
70
|
+
:param start: start with
|
|
71
|
+
:param end: end in
|
|
72
|
+
:param letters: letters in between
|
|
73
|
+
"""
|
|
74
|
+
return self.__get_words(sp=f"{start[0]}{'?' * letters}{end[0]}")
|
|
75
|
+
|
|
76
|
+
def orthographic_neighbours(self, sp: Word):
|
|
77
|
+
"""
|
|
78
|
+
words that are spelled similarly to `sp`
|
|
79
|
+
|
|
80
|
+
:param sp: spelled like
|
|
81
|
+
"""
|
|
82
|
+
return self.__get_words(sp=sp)
|
|
83
|
+
|
|
84
|
+
def related(self, word: Word, rel: RelatedWordCode):
|
|
85
|
+
"""
|
|
86
|
+
words that are related by `rel`
|
|
87
|
+
|
|
88
|
+
:param word: the word
|
|
89
|
+
:param rel: related word
|
|
90
|
+
"""
|
|
91
|
+
return self.__get_words(**{f"rel_{_lookup_related_code[rel]}": word})
|
|
92
|
+
|
|
93
|
+
def suggestions(self, s: Word):
|
|
94
|
+
"""
|
|
95
|
+
sugesstions from prefix hint string `s`
|
|
96
|
+
|
|
97
|
+
:param s: prefix hint string
|
|
98
|
+
"""
|
|
99
|
+
return self.__get_suggestions(s=s)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: datamuse
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: datamuse is a simple wrapper around the datamuse api https://www.datamuse.com/api/
|
|
5
|
+
Author-email: Bivas Kumar <thetrotfreak@yahoo.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://pypi.org/project/datamuse
|
|
8
|
+
Project-URL: Source, https://github.com/thetrotfreak/datamuse
|
|
9
|
+
Project-URL: Documentation, https://thetrotfreak.github.io/datamuse
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Requires-Python: >=3.11
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Requires-Dist: certifi>=2026.1.4
|
|
16
|
+
Requires-Dist: urllib3>=2.6.3
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# datamuse
|
|
20
|
+
|
|
21
|
+
`datamuse` is a simple wrapper around the [datamuse](https://www.datamuse.com/) [api](https://www.datamuse.com/api/)
|
|
22
|
+
|
|
23
|
+
## Installing
|
|
24
|
+
|
|
25
|
+
You can install `datamuse` via `pip` / `pypi`:
|
|
26
|
+
|
|
27
|
+
```shell
|
|
28
|
+
pip install datamuse
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Acknowledgements
|
|
32
|
+
|
|
33
|
+
- [Harvey Beeferman, 1942–2024](https://beeferman.org/harvey/)
|
|
34
|
+
- [datamuse](https://www.datamuse.com/)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
datamuse/__init__.py
|
|
5
|
+
datamuse/annotations.py
|
|
6
|
+
datamuse/datamuse.py
|
|
7
|
+
datamuse.egg-info/PKG-INFO
|
|
8
|
+
datamuse.egg-info/SOURCES.txt
|
|
9
|
+
datamuse.egg-info/dependency_links.txt
|
|
10
|
+
datamuse.egg-info/requires.txt
|
|
11
|
+
datamuse.egg-info/top_level.txt
|
|
12
|
+
tests/test_datamuse.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
datamuse
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "datamuse"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
authors = [
|
|
5
|
+
{ name="Bivas Kumar", email="thetrotfreak@yahoo.com" },
|
|
6
|
+
]
|
|
7
|
+
description = "datamuse is a simple wrapper around the datamuse api https://www.datamuse.com/api/"
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
requires-python = ">=3.11"
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Programming Language :: Python :: 3",
|
|
12
|
+
"Operating System :: OS Independent",
|
|
13
|
+
]
|
|
14
|
+
license = "MIT"
|
|
15
|
+
license-files = ["LICEN[CS]E*"]
|
|
16
|
+
dependencies = [
|
|
17
|
+
"certifi>=2026.1.4",
|
|
18
|
+
"urllib3>=2.6.3",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://pypi.org/project/datamuse"
|
|
23
|
+
Source = "https://github.com/thetrotfreak/datamuse"
|
|
24
|
+
Documentation = "https://thetrotfreak.github.io/datamuse"
|
|
25
|
+
|
|
26
|
+
[build-system]
|
|
27
|
+
requires = ["setuptools"]
|
|
28
|
+
build-backend = "setuptools.build_meta"
|
|
29
|
+
|
|
30
|
+
[dependency-groups]
|
|
31
|
+
dev = [
|
|
32
|
+
"mkdocs-material>=9.7.1",
|
|
33
|
+
"mkdocstrings-python>=2.0.1",
|
|
34
|
+
"pytest>=9.0.2",
|
|
35
|
+
"pytest-cov>=7.0.0",
|
|
36
|
+
"pytest-mock>=3.15.1",
|
|
37
|
+
]
|
datamuse-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from datamuse.annotations import _lookup_related_code
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class TestDatamuse:
|
|
7
|
+
def test_synonyms(self, word_mock, datamuse_mock):
|
|
8
|
+
mock = datamuse_mock(
|
|
9
|
+
method="GET",
|
|
10
|
+
url="/words",
|
|
11
|
+
response=[{"word": word_mock}],
|
|
12
|
+
match_query={"ml": word_mock},
|
|
13
|
+
)
|
|
14
|
+
synonyms = mock.synonyms(word_mock)
|
|
15
|
+
assert word_mock in synonyms
|
|
16
|
+
|
|
17
|
+
@pytest.mark.parametrize("start, end", [("", ""), ("s", "e")])
|
|
18
|
+
def test_associations(self, word_mock, datamuse_mock, start, end):
|
|
19
|
+
mock = datamuse_mock(
|
|
20
|
+
method="GET",
|
|
21
|
+
url="/words",
|
|
22
|
+
response=[{"word": word_mock}],
|
|
23
|
+
match_query={"ml": word_mock, "sp": start + end},
|
|
24
|
+
)
|
|
25
|
+
associations = mock.associations(word_mock, start, end)
|
|
26
|
+
assert word_mock in associations
|
|
27
|
+
|
|
28
|
+
def test_homophones(self, word_mock, datamuse_mock):
|
|
29
|
+
mock = datamuse_mock(
|
|
30
|
+
method="GET",
|
|
31
|
+
url="/words",
|
|
32
|
+
response=[{"word": word_mock}],
|
|
33
|
+
match_query={"sl": word_mock},
|
|
34
|
+
)
|
|
35
|
+
homopohones = mock.homophones(word_mock)
|
|
36
|
+
assert word_mock in homopohones
|
|
37
|
+
|
|
38
|
+
def test_pattern(self, words_mock, datamuse_mock):
|
|
39
|
+
start, end = words_mock(2)
|
|
40
|
+
mock = datamuse_mock(
|
|
41
|
+
method="GET",
|
|
42
|
+
url="/words",
|
|
43
|
+
response=[{"word": start}, {"word": end}],
|
|
44
|
+
match_query={"sp": start[0] + "?" * 2 + end[0]},
|
|
45
|
+
)
|
|
46
|
+
pattern = mock.pattern(start, end, 2)
|
|
47
|
+
assert start in pattern
|
|
48
|
+
assert end in pattern
|
|
49
|
+
|
|
50
|
+
def test_orthographic_neighbours(self, word_mock, datamuse_mock):
|
|
51
|
+
mock = datamuse_mock(
|
|
52
|
+
method="GET",
|
|
53
|
+
url="/words",
|
|
54
|
+
response=[{"word": word_mock}],
|
|
55
|
+
match_query={"sp": word_mock},
|
|
56
|
+
)
|
|
57
|
+
homopohones = mock.orthographic_neighbours(word_mock)
|
|
58
|
+
assert word_mock in homopohones
|
|
59
|
+
|
|
60
|
+
def test_suggestions(self, words_mock, datamuse_mock):
|
|
61
|
+
words = words_mock(10)
|
|
62
|
+
search_prefix = words[0]
|
|
63
|
+
|
|
64
|
+
mock = datamuse_mock(
|
|
65
|
+
method="GET",
|
|
66
|
+
url="/sug",
|
|
67
|
+
response=[{"word": word} for word in words],
|
|
68
|
+
match_query={"s": search_prefix},
|
|
69
|
+
)
|
|
70
|
+
suggestions = mock.suggestions(search_prefix)
|
|
71
|
+
assert suggestions == words
|
|
72
|
+
|
|
73
|
+
@pytest.mark.parametrize(
|
|
74
|
+
"parameter, code",
|
|
75
|
+
[(parameter, code) for parameter, code in _lookup_related_code.items()],
|
|
76
|
+
)
|
|
77
|
+
def test_related(self, datamuse_mock, word_mock, parameter, code):
|
|
78
|
+
mock = datamuse_mock(
|
|
79
|
+
method="GET",
|
|
80
|
+
url="/words",
|
|
81
|
+
response=[{"word": word_mock}],
|
|
82
|
+
match_query={f"rel_{code}": word_mock},
|
|
83
|
+
)
|
|
84
|
+
related = mock.related(word_mock, parameter)
|
|
85
|
+
assert word_mock in related
|