From a22147a90f7759d4890dffc8d8f98fbb034e551a Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Tue, 26 Nov 2024 13:42:23 +0700 Subject: [PATCH] Create natural_language_processing.py --- .../src/ai/natural_language_processing.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 QuantumNexusProtocol/src/ai/natural_language_processing.py diff --git a/QuantumNexusProtocol/src/ai/natural_language_processing.py b/QuantumNexusProtocol/src/ai/natural_language_processing.py new file mode 100644 index 000000000..8016a26bd --- /dev/null +++ b/QuantumNexusProtocol/src/ai/natural_language_processing.py @@ -0,0 +1,22 @@ +import nltk +from nltk.tokenize import word_tokenize +from nltk.corpus import stopwords + +class NaturalLanguageProcessor: + def __init__(self, text): + self.text = text + nltk.download('punkt') + nltk.download('stopwords') + self.stop_words = set(stopwords.words('english')) + + def process(self): + tokens = word_tokenize(self.text) + filtered_tokens = [word for word in tokens if word.lower() not in self.stop_words] + return filtered_tokens + +# Example usage +if __name__ == "__main__": + text = "This is an example sentence for natural language processing." + processor = NaturalLanguageProcessor(text) + processed_text = processor.process() + print("Processed Text:", processed_text)