barkha2 commited on
Commit
d8a8a49
·
verified ·
1 Parent(s): ece0539

Create nlp.py

Browse files
Files changed (1) hide show
  1. nlp.py +34 -0
nlp.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+
4
+ # In[18]:
5
+
6
+
7
+ #get_ipython().system('pip install --upgrade nltk')
8
+ import nltk
9
+ from sklearn.feature_extraction.text import TfidfVectorizer
10
+ nltk.download('punkt')
11
+ d=[
12
+ "ShivShakti represents the divine union of Shiva and Shakti.",
13
+ "Shiva is consciousness, and Shakti is energy.",
14
+ "Together, they symbolize balance and creation."
15
+ ]
16
+ v=TfidfVectorizer()
17
+ X=v.fit_transform(d)
18
+ def search_text(energy):
19
+ qv=v.transform([energy])
20
+ scores=(X*qv.T).toarray()
21
+ bm=d[scores.argmax()]
22
+ return bm
23
+
24
+
25
+ # In[22]:
26
+
27
+
28
+ print(search_text("energy"))
29
+
30
+
31
+ # In[ ]:
32
+
33
+
34
+