pda-nlp-lab 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.
- pda_nlp_lab-0.1.0/PKG-INFO +55 -0
- pda_nlp_lab-0.1.0/README.md +46 -0
- pda_nlp_lab-0.1.0/nlp_lab/__init__.py +123 -0
- pda_nlp_lab-0.1.0/nlp_lab/my_corpus.txt +2 -0
- pda_nlp_lab-0.1.0/nlp_lab/programs/__init__.py +1 -0
- pda_nlp_lab-0.1.0/nlp_lab/programs/my_corpus.txt +2 -0
- pda_nlp_lab-0.1.0/nlp_lab/programs/p1.py +30 -0
- pda_nlp_lab-0.1.0/nlp_lab/programs/p2.py +25 -0
- pda_nlp_lab-0.1.0/nlp_lab/programs/p3.py +36 -0
- pda_nlp_lab-0.1.0/nlp_lab/programs/p4.py +32 -0
- pda_nlp_lab-0.1.0/nlp_lab/programs/p5.py +35 -0
- pda_nlp_lab-0.1.0/nlp_lab/programs/p6.py +45 -0
- pda_nlp_lab-0.1.0/nlp_lab/programs/p7.py +18 -0
- pda_nlp_lab-0.1.0/pda_nlp_lab.egg-info/PKG-INFO +55 -0
- pda_nlp_lab-0.1.0/pda_nlp_lab.egg-info/SOURCES.txt +18 -0
- pda_nlp_lab-0.1.0/pda_nlp_lab.egg-info/dependency_links.txt +1 -0
- pda_nlp_lab-0.1.0/pda_nlp_lab.egg-info/requires.txt +2 -0
- pda_nlp_lab-0.1.0/pda_nlp_lab.egg-info/top_level.txt +1 -0
- pda_nlp_lab-0.1.0/pyproject.toml +22 -0
- pda_nlp_lab-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pda-nlp-lab
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: NLP Lab programs package and Jupyter Notebook dynamic code loader
|
|
5
|
+
Requires-Python: >=3.8
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: nltk>=3.8.1
|
|
8
|
+
Requires-Dist: ipython>=8.0.0
|
|
9
|
+
|
|
10
|
+
# PDA NLP Lab (`pda-nlp-lab`)
|
|
11
|
+
|
|
12
|
+
An installable Python library for NLP Lab programs with dynamic source code injection for Jupyter Notebooks.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
Install from PyPI:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install pda-nlp-lab
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or install in editable mode for local development:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install -e .
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick Start & Usage
|
|
29
|
+
|
|
30
|
+
### Inside Jupyter Notebook
|
|
31
|
+
|
|
32
|
+
Import `nlp_lab` and invoke any program function (`p1()` through `p7()`). The function loads the full source code directly into a new cell right below your active cell:
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
import nlp_lab
|
|
36
|
+
|
|
37
|
+
# List all available programs and their descriptions
|
|
38
|
+
nlp_lab.list_programs()
|
|
39
|
+
|
|
40
|
+
# Injects the p1 program code into a new cell below
|
|
41
|
+
nlp_lab.p1()
|
|
42
|
+
|
|
43
|
+
# Injects the p7 program code into a new cell below
|
|
44
|
+
nlp_lab.p7()
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Outside Jupyter (Terminal / Standard Python)
|
|
48
|
+
|
|
49
|
+
When executed in a standard script or terminal, calling any program function prints the source code cleanly to standard output:
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
import nlp_lab
|
|
53
|
+
|
|
54
|
+
nlp_lab.p1()
|
|
55
|
+
```
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# PDA NLP Lab (`pda-nlp-lab`)
|
|
2
|
+
|
|
3
|
+
An installable Python library for NLP Lab programs with dynamic source code injection for Jupyter Notebooks.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install from PyPI:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install pda-nlp-lab
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or install in editable mode for local development:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install -e .
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start & Usage
|
|
20
|
+
|
|
21
|
+
### Inside Jupyter Notebook
|
|
22
|
+
|
|
23
|
+
Import `nlp_lab` and invoke any program function (`p1()` through `p7()`). The function loads the full source code directly into a new cell right below your active cell:
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
import nlp_lab
|
|
27
|
+
|
|
28
|
+
# List all available programs and their descriptions
|
|
29
|
+
nlp_lab.list_programs()
|
|
30
|
+
|
|
31
|
+
# Injects the p1 program code into a new cell below
|
|
32
|
+
nlp_lab.p1()
|
|
33
|
+
|
|
34
|
+
# Injects the p7 program code into a new cell below
|
|
35
|
+
nlp_lab.p7()
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Outside Jupyter (Terminal / Standard Python)
|
|
39
|
+
|
|
40
|
+
When executed in a standard script or terminal, calling any program function prints the source code cleanly to standard output:
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
import nlp_lab
|
|
44
|
+
|
|
45
|
+
nlp_lab.p1()
|
|
46
|
+
```
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""
|
|
2
|
+
nlp_lab: NLP Lab Programs and Dynamic Code Loader for Jupyter Notebooks.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import importlib.resources
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Optional
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"p1",
|
|
11
|
+
"p2",
|
|
12
|
+
"p3",
|
|
13
|
+
"p4",
|
|
14
|
+
"p5",
|
|
15
|
+
"p6",
|
|
16
|
+
"p7",
|
|
17
|
+
"load_program",
|
|
18
|
+
"get_program_code",
|
|
19
|
+
"list_programs",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
PROGRAM_NAMES = [f"p{i}" for i in range(1, 8)]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _get_program_resource(name: str):
|
|
26
|
+
"""Retrieve the Traversable or Path for a program file."""
|
|
27
|
+
filename = f"{name}.py"
|
|
28
|
+
try:
|
|
29
|
+
return importlib.resources.files("nlp_lab.programs").joinpath(filename)
|
|
30
|
+
except Exception:
|
|
31
|
+
return Path(__file__).resolve().parent / "programs" / filename
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def get_program_code(name: str) -> str:
|
|
35
|
+
"""
|
|
36
|
+
Read the raw source code of the specified program (e.g. 'p1').
|
|
37
|
+
Reads directly dynamically so any updates to the file are immediately reflected.
|
|
38
|
+
"""
|
|
39
|
+
resource = _get_program_resource(name)
|
|
40
|
+
try:
|
|
41
|
+
return resource.read_text(encoding="utf-8")
|
|
42
|
+
except AttributeError:
|
|
43
|
+
return Path(resource).read_text(encoding="utf-8")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def load_program(name: str) -> None:
|
|
47
|
+
"""
|
|
48
|
+
Loads the full source code of the program.
|
|
49
|
+
- In IPython / Jupyter Notebook: injects the code into a new cell directly below the active cell.
|
|
50
|
+
- Outside IPython: prints the code cleanly to stdout.
|
|
51
|
+
"""
|
|
52
|
+
code = get_program_code(name).strip()
|
|
53
|
+
|
|
54
|
+
ip = None
|
|
55
|
+
try:
|
|
56
|
+
from IPython import get_ipython
|
|
57
|
+
|
|
58
|
+
ip = get_ipython()
|
|
59
|
+
except (ImportError, Exception):
|
|
60
|
+
ip = None
|
|
61
|
+
|
|
62
|
+
if ip is not None:
|
|
63
|
+
ip.set_next_input(code, replace=False)
|
|
64
|
+
else:
|
|
65
|
+
print(code)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def p1() -> None:
|
|
69
|
+
"""Load Program 1."""
|
|
70
|
+
load_program("p1")
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def p2() -> None:
|
|
74
|
+
"""Load Program 2."""
|
|
75
|
+
load_program("p2")
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def p3() -> None:
|
|
79
|
+
"""Load Program 3."""
|
|
80
|
+
load_program("p3")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def p4() -> None:
|
|
84
|
+
"""Load Program 4."""
|
|
85
|
+
load_program("p4")
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def p5() -> None:
|
|
89
|
+
"""Load Program 5."""
|
|
90
|
+
load_program("p5")
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def p6() -> None:
|
|
94
|
+
"""Load Program 6."""
|
|
95
|
+
load_program("p6")
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def p7() -> None:
|
|
99
|
+
"""Load Program 7."""
|
|
100
|
+
load_program("p7")
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def list_programs() -> None:
|
|
104
|
+
"""
|
|
105
|
+
Prints all available program functions and their first-line comments.
|
|
106
|
+
"""
|
|
107
|
+
print("Available NLP Lab Programs:")
|
|
108
|
+
print("-" * 50)
|
|
109
|
+
for name in PROGRAM_NAMES:
|
|
110
|
+
try:
|
|
111
|
+
code = get_program_code(name)
|
|
112
|
+
first_line = ""
|
|
113
|
+
for line in code.splitlines():
|
|
114
|
+
stripped = line.strip()
|
|
115
|
+
if stripped:
|
|
116
|
+
first_line = stripped
|
|
117
|
+
break
|
|
118
|
+
comment = first_line if first_line.startswith("#") else f"(Comment: {first_line})"
|
|
119
|
+
print(f"nlp_lab.{name}() -> {comment}")
|
|
120
|
+
except Exception as e:
|
|
121
|
+
print(f"nlp_lab.{name}() -> [Error reading program: {e}]")
|
|
122
|
+
print("-" * 50)
|
|
123
|
+
print("In Jupyter Notebook: call nlp_lab.p<N>() to insert code into the next cell.")
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""NLP Lab Programs Package."""
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#program 1
|
|
2
|
+
import re
|
|
3
|
+
import nltk
|
|
4
|
+
from nltk.tokenize import word_tokenize
|
|
5
|
+
from nltk.corpus import stopwords
|
|
6
|
+
from nltk.stem import PorterStemmer
|
|
7
|
+
|
|
8
|
+
nltk.download('punkt')
|
|
9
|
+
nltk.download('stopwords')
|
|
10
|
+
|
|
11
|
+
text = """Natural Language Processing is a fascinating field of AI.
|
|
12
|
+
It involves processing human languages, like English!"""
|
|
13
|
+
print(f"Original Text:\n{text}\n")
|
|
14
|
+
|
|
15
|
+
t = word_tokenize(text)
|
|
16
|
+
print(f"Tokens:\n{t}\n")
|
|
17
|
+
|
|
18
|
+
f = [w for w in [re.sub(r'[^\w\s]', '', x) for x in t] if w.isalpha()]
|
|
19
|
+
print(f"Filtered Tokens:\n{f}\n")
|
|
20
|
+
|
|
21
|
+
v = [w for w in f if re.match(r'^[a-zA-Z]+$', w)]
|
|
22
|
+
print(f"Validated Tokens (English Only):\n{v}\n")
|
|
23
|
+
|
|
24
|
+
sw = set(stopwords.words('english'))
|
|
25
|
+
ns = [w for w in v if w.lower() not in sw]
|
|
26
|
+
print(f"Tokens after Stop Word Removal:\n{ns}\n")
|
|
27
|
+
|
|
28
|
+
ps = PorterStemmer()
|
|
29
|
+
s = [ps.stem(w) for w in ns]
|
|
30
|
+
print(f"Stemmed Tokens:\n{s}")
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#program 2
|
|
2
|
+
import nltk
|
|
3
|
+
from nltk.util import ngrams
|
|
4
|
+
from collections import Counter
|
|
5
|
+
|
|
6
|
+
nltk.download('punkt')
|
|
7
|
+
|
|
8
|
+
sentences = [
|
|
9
|
+
"The quick brown fox jumps over the lazy dog",
|
|
10
|
+
"The dog barks at the fox",
|
|
11
|
+
"The fox is quick and the dog is lazy",
|
|
12
|
+
"The quick dog jumps over the lazy fox"
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
toks = [nltk.word_tokenize(s.lower()) for s in sentences]
|
|
16
|
+
|
|
17
|
+
for n in [1, 2, 3]:
|
|
18
|
+
print(f"\n{n}-Gram Probabilities:")
|
|
19
|
+
g = [x for t in toks for x in ngrams(t, n)]
|
|
20
|
+
p = [x for t in toks for x in ngrams(t, n-1)] if n > 1 else []
|
|
21
|
+
cg, cp = Counter(g), Counter(p)
|
|
22
|
+
|
|
23
|
+
for k, v in cg.items():
|
|
24
|
+
prob = v / sum(cg.values()) if n == 1 else v / cp[k[:-1]]
|
|
25
|
+
print(f"{' '.join(k)}: {prob:.4f}")
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#program 3
|
|
2
|
+
def med(w1, w2):
|
|
3
|
+
m, n = len(w1), len(w2)
|
|
4
|
+
dp = [[0] * (n + 1) for _ in range(m + 1)]
|
|
5
|
+
|
|
6
|
+
for i in range(m + 1):
|
|
7
|
+
for j in range(n + 1):
|
|
8
|
+
if i == 0:
|
|
9
|
+
dp[i][j] = j
|
|
10
|
+
elif j == 0:
|
|
11
|
+
dp[i][j] = i
|
|
12
|
+
elif w1[i-1] == w2[j-1]:
|
|
13
|
+
dp[i][j] = dp[i-1][j-1]
|
|
14
|
+
else:
|
|
15
|
+
dp[i][j] = 1 + min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1])
|
|
16
|
+
|
|
17
|
+
print(f"Comparing: '{w1}' -> '{w2}'\nMinimum Edit Distance: {dp[-1][-1]}\n")
|
|
18
|
+
print("Edit Distance Table:")
|
|
19
|
+
print(" #" + "".join(f"{'#'+c:>5}" for c in w2))
|
|
20
|
+
|
|
21
|
+
for i in range(m + 1):
|
|
22
|
+
ch = '#' if i == 0 else w1[i-1]
|
|
23
|
+
print(f"{ch:<4}" + "".join(f"{x:>5}" for x in dp[i]))
|
|
24
|
+
print()
|
|
25
|
+
|
|
26
|
+
pairs = [
|
|
27
|
+
("kitten", "sitting"),
|
|
28
|
+
("flaw", "lawn"),
|
|
29
|
+
("intention", "execution"),
|
|
30
|
+
("apple", "aple"),
|
|
31
|
+
("", "hello"),
|
|
32
|
+
("hello", "")
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
for w1, w2 in pairs:
|
|
36
|
+
med(w1, w2)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#program 4
|
|
2
|
+
g = [('S', ['NP', 'VP']), ('NP', ['Det', 'N']), ('VP', ['V', 'NP']), ('VP', ['V']),
|
|
3
|
+
('Det', ['a']), ('Det', ['the']), ('N', ['cat']), ('N', ['dog']),
|
|
4
|
+
('V', ['chases']), ('V', ['eats'])]
|
|
5
|
+
|
|
6
|
+
rules = {}
|
|
7
|
+
for k, v in g:
|
|
8
|
+
rules.setdefault(k, []).append(v)
|
|
9
|
+
|
|
10
|
+
def top_down_parse(s):
|
|
11
|
+
return None
|
|
12
|
+
|
|
13
|
+
def bottom_up_parse(s, stack=None):
|
|
14
|
+
if stack is None: stack = []
|
|
15
|
+
if not s: return stack or None
|
|
16
|
+
|
|
17
|
+
w, s = s[0], s[1:]
|
|
18
|
+
for l, rhs in rules.items():
|
|
19
|
+
if [w] in rhs:
|
|
20
|
+
stack.append(l)
|
|
21
|
+
break
|
|
22
|
+
|
|
23
|
+
for l, rhs in rules.items():
|
|
24
|
+
for r in rhs:
|
|
25
|
+
if stack[-len(r):] == r:
|
|
26
|
+
return bottom_up_parse(s, stack[:-len(r)] + [l])
|
|
27
|
+
|
|
28
|
+
return bottom_up_parse(s, stack)
|
|
29
|
+
|
|
30
|
+
sen = ['the', 'cat', 'chases', 'a', 'dog']
|
|
31
|
+
print("Top-Down Parse Result:", top_down_parse(sen))
|
|
32
|
+
print("Bottom-Up Parse Result:", bottom_up_parse(sen))
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#program 5
|
|
2
|
+
reviews = [
|
|
3
|
+
("fun, couple, love, love", "comedy"),
|
|
4
|
+
("fast, furious, shoot", "action"),
|
|
5
|
+
("couple, fly, fast, fun", "comedy"),
|
|
6
|
+
("furious, shoot, shoot, fun", "action"),
|
|
7
|
+
("fly, fast, shoot, love", "action")
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
c_words, a_words = [], []
|
|
11
|
+
c_docs, a_docs = 0, 0
|
|
12
|
+
|
|
13
|
+
for text, label in reviews:
|
|
14
|
+
if label == "comedy":
|
|
15
|
+
c_words.extend(text.split(", "))
|
|
16
|
+
c_docs += 1
|
|
17
|
+
else:
|
|
18
|
+
a_words.extend(text.split(", "))
|
|
19
|
+
a_docs += 1
|
|
20
|
+
|
|
21
|
+
V = len(set(c_words + a_words))
|
|
22
|
+
post_c = c_docs / (c_docs + a_docs)
|
|
23
|
+
post_a = a_docs / (c_docs + a_docs)
|
|
24
|
+
|
|
25
|
+
for word in ["fast", "couple", "shoot", "fly"]:
|
|
26
|
+
post_c *= (c_words.count(word) + 1) / (len(c_words) + V)
|
|
27
|
+
post_a *= (a_words.count(word) + 1) / (len(a_words) + V)
|
|
28
|
+
|
|
29
|
+
print(f"Posterior for comedy: {post_c}")
|
|
30
|
+
print(f"Posterior for action: {post_a}")
|
|
31
|
+
|
|
32
|
+
if post_c > post_a:
|
|
33
|
+
print("\nThe most likely class for the document is: Comedy")
|
|
34
|
+
else:
|
|
35
|
+
print("\nThe most likely class for the document is: Action")
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#program 6
|
|
2
|
+
import nltk
|
|
3
|
+
from nltk.corpus import brown, inaugural, reuters, udhr
|
|
4
|
+
from nltk.probability import FreqDist, ConditionalFreqDist
|
|
5
|
+
from nltk import word_tokenize
|
|
6
|
+
from nltk.tag import UnigramTagger, RegexpTagger
|
|
7
|
+
|
|
8
|
+
nltk.download(['brown', 'inaugural', 'reuters', 'udhr', 'punkt'])
|
|
9
|
+
|
|
10
|
+
print(f"Brown Corpus Categories: {brown.categories()}")
|
|
11
|
+
print(f"Brown Corpus Words: {brown.words(categories='news')[:10]}")
|
|
12
|
+
print(f"Brown Corpus Sentences: {brown.sents(categories='news')[:2]}")
|
|
13
|
+
print(f"\nInaugural Corpus Raw Text: {inaugural.raw('1789-Washington.txt')[:100]}")
|
|
14
|
+
print(f"\nReuters Corpus Categories: {reuters.categories()}")
|
|
15
|
+
print(f"Reuters Corpus Words: {reuters.words(categories='trade')[:10]}")
|
|
16
|
+
|
|
17
|
+
with open('my_corpus.txt', 'w') as f:
|
|
18
|
+
f.write("This is a simple corpus\nIt contains simple sentences\n")
|
|
19
|
+
|
|
20
|
+
custom_corpus = open('my_corpus.txt', 'r').read()
|
|
21
|
+
word_tokenize(custom_corpus)
|
|
22
|
+
|
|
23
|
+
cfd = ConditionalFreqDist((c, w) for c in brown.categories() for w in brown.words(categories=c))
|
|
24
|
+
|
|
25
|
+
ts = brown.tagged_sents(categories='news')
|
|
26
|
+
tw = brown.tagged_words(categories='news')
|
|
27
|
+
freq_dist_nouns = FreqDist(tag for word, tag in tw if tag.startswith('NN'))
|
|
28
|
+
|
|
29
|
+
patterns = [(r'.*ed$', 'VBD'), (r'.*ing$', 'VBG'), (r'\b\w{3,}\b', 'NN')]
|
|
30
|
+
rule_based_tagger = RegexpTagger(patterns)
|
|
31
|
+
unigram_tagger = UnigramTagger(ts)
|
|
32
|
+
|
|
33
|
+
text = "fastcoupleshootfly"
|
|
34
|
+
corpus_set = set(brown.words())
|
|
35
|
+
words = []
|
|
36
|
+
i = 0
|
|
37
|
+
|
|
38
|
+
while i < len(text):
|
|
39
|
+
for j in range(i + 1, len(text) + 1):
|
|
40
|
+
if text[i:j] in corpus_set:
|
|
41
|
+
words.append(text[i:j])
|
|
42
|
+
i = j
|
|
43
|
+
break
|
|
44
|
+
else:
|
|
45
|
+
i += 1
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#program 7
|
|
2
|
+
import nltk
|
|
3
|
+
from nltk.corpus import wordnet
|
|
4
|
+
|
|
5
|
+
nltk.download('wordnet')
|
|
6
|
+
nltk.download('omw-1.4')
|
|
7
|
+
|
|
8
|
+
synonyms = set()
|
|
9
|
+
antonyms = set()
|
|
10
|
+
|
|
11
|
+
for syn in wordnet.synsets('active'):
|
|
12
|
+
for lemma in syn.lemmas():
|
|
13
|
+
synonyms.add(lemma.name())
|
|
14
|
+
if lemma.antonyms():
|
|
15
|
+
antonyms.add(lemma.antonyms()[0].name())
|
|
16
|
+
|
|
17
|
+
print("Synonyms of 'active':", list(synonyms))
|
|
18
|
+
print("Antonyms of 'active':", list(antonyms))
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pda-nlp-lab
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: NLP Lab programs package and Jupyter Notebook dynamic code loader
|
|
5
|
+
Requires-Python: >=3.8
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: nltk>=3.8.1
|
|
8
|
+
Requires-Dist: ipython>=8.0.0
|
|
9
|
+
|
|
10
|
+
# PDA NLP Lab (`pda-nlp-lab`)
|
|
11
|
+
|
|
12
|
+
An installable Python library for NLP Lab programs with dynamic source code injection for Jupyter Notebooks.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
Install from PyPI:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install pda-nlp-lab
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or install in editable mode for local development:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install -e .
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick Start & Usage
|
|
29
|
+
|
|
30
|
+
### Inside Jupyter Notebook
|
|
31
|
+
|
|
32
|
+
Import `nlp_lab` and invoke any program function (`p1()` through `p7()`). The function loads the full source code directly into a new cell right below your active cell:
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
import nlp_lab
|
|
36
|
+
|
|
37
|
+
# List all available programs and their descriptions
|
|
38
|
+
nlp_lab.list_programs()
|
|
39
|
+
|
|
40
|
+
# Injects the p1 program code into a new cell below
|
|
41
|
+
nlp_lab.p1()
|
|
42
|
+
|
|
43
|
+
# Injects the p7 program code into a new cell below
|
|
44
|
+
nlp_lab.p7()
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Outside Jupyter (Terminal / Standard Python)
|
|
48
|
+
|
|
49
|
+
When executed in a standard script or terminal, calling any program function prints the source code cleanly to standard output:
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
import nlp_lab
|
|
53
|
+
|
|
54
|
+
nlp_lab.p1()
|
|
55
|
+
```
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
nlp_lab/__init__.py
|
|
4
|
+
nlp_lab/my_corpus.txt
|
|
5
|
+
nlp_lab/programs/__init__.py
|
|
6
|
+
nlp_lab/programs/my_corpus.txt
|
|
7
|
+
nlp_lab/programs/p1.py
|
|
8
|
+
nlp_lab/programs/p2.py
|
|
9
|
+
nlp_lab/programs/p3.py
|
|
10
|
+
nlp_lab/programs/p4.py
|
|
11
|
+
nlp_lab/programs/p5.py
|
|
12
|
+
nlp_lab/programs/p6.py
|
|
13
|
+
nlp_lab/programs/p7.py
|
|
14
|
+
pda_nlp_lab.egg-info/PKG-INFO
|
|
15
|
+
pda_nlp_lab.egg-info/SOURCES.txt
|
|
16
|
+
pda_nlp_lab.egg-info/dependency_links.txt
|
|
17
|
+
pda_nlp_lab.egg-info/requires.txt
|
|
18
|
+
pda_nlp_lab.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
nlp_lab
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pda-nlp-lab"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "NLP Lab programs package and Jupyter Notebook dynamic code loader"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"nltk>=3.8.1",
|
|
13
|
+
"ipython>=8.0.0",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[tool.setuptools.packages.find]
|
|
17
|
+
where = ["."]
|
|
18
|
+
include = ["nlp_lab*"]
|
|
19
|
+
|
|
20
|
+
[tool.setuptools.package-data]
|
|
21
|
+
"nlp_lab" = ["*.txt"]
|
|
22
|
+
"nlp_lab.programs" = ["*.py", "*.txt"]
|