Created
February 5, 2024 01:44
-
-
Save dheerajinampudi/3e3183e48ffbf2cc933111cb743b3292 to your computer and use it in GitHub Desktop.
search examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Full-Text Search Example | |
import re | |
text = "Exploring the universe of AI and ML." | |
search_term = "universe" | |
result = re.findall(search_term, text) | |
print(result) | |
# Semantic Search Example (using spaCy) | |
import spacy | |
nlp = spacy.load("en_core_web_sm") | |
doc = nlp("The cat sat on the mat.") | |
for token in doc: | |
print(token.text, token.has_vector, token.vector_norm, token.is_oov) | |
# Vector Search Example (using scikit-learn) | |
from sklearn.feature_extraction.text import TfidfVectorizer | |
docs = ["AI advancements", "The future of ML"] | |
tfidf = TfidfVectorizer() | |
tfidf_matrix = tfidf.fit_transform(docs) | |
print(tfidf_matrix.toarray()) | |
# Lexical Search Example | |
text = "Artificial intelligence in healthcare" | |
search_pattern = r"\bA[a-z]*" | |
matches = re.findall(search_pattern, text) | |
print(matches) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment