Moved everything to jarvis/... and added spacy for stopwords
This commit is contained in:
parent
3bf6737f45
commit
ab86509e61
2
.gitignore
vendored
2
.gitignore
vendored
@ -135,4 +135,4 @@ dmypy.json
|
|||||||
|
|
||||||
|
|
||||||
/ffmpeg/
|
/ffmpeg/
|
||||||
/config/secrets.json
|
/jarvis/config/secrets.json
|
||||||
|
@ -2,7 +2,7 @@ import nltk
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from nltk.stem.porter import PorterStemmer
|
from nltk.stem.porter import PorterStemmer
|
||||||
|
|
||||||
from utils import languages_utils
|
from jarvis.utils import languages_utils
|
||||||
|
|
||||||
stemmer = PorterStemmer()
|
stemmer = PorterStemmer()
|
||||||
|
|
@ -3,9 +3,9 @@ import os
|
|||||||
import torch
|
import torch
|
||||||
from unidecode import unidecode
|
from unidecode import unidecode
|
||||||
|
|
||||||
import get_path_file
|
from jarvis import get_path_file
|
||||||
from ia.model import NeuralNet
|
from jarvis.ia.model import NeuralNet
|
||||||
from ia.nltk_utils import bag_of_words, tokenize
|
from jarvis.ia.nltk_utils import bag_of_words, tokenize
|
||||||
|
|
||||||
print("Loading, might take a few seconds...")
|
print("Loading, might take a few seconds...")
|
||||||
|
|
@ -5,10 +5,10 @@ import torch
|
|||||||
import torch.nn as nn
|
import torch.nn as nn
|
||||||
from torch.utils.data import Dataset, DataLoader
|
from torch.utils.data import Dataset, DataLoader
|
||||||
|
|
||||||
import get_path_file
|
from jarvis import get_path_file
|
||||||
from ia.model import NeuralNet
|
from jarvis.ia.model import NeuralNet
|
||||||
from ia.nltk_utils import bag_of_words, tokenize, stem
|
from jarvis.ia.nltk_utils import bag_of_words, tokenize, stem
|
||||||
from utils import intents_utils
|
from jarvis.utils import intents_utils
|
||||||
|
|
||||||
path = os.path.dirname(get_path_file.__file__)
|
path = os.path.dirname(get_path_file.__file__)
|
||||||
|
|
@ -1,7 +1,6 @@
|
|||||||
import flask
|
import flask
|
||||||
from flask import Flask, request, jsonify, Response
|
from flask import Flask, request, jsonify, Response
|
||||||
|
|
||||||
import ia.process
|
|
||||||
from utils import config_utils, flask_utils, intents_utils, utils
|
from utils import config_utils, flask_utils, intents_utils, utils
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
@ -15,7 +14,7 @@ def process_request():
|
|||||||
flask.abort(Response('You must provide a \'sentence\' parameter (not empty aswell)!'))
|
flask.abort(Response('You must provide a \'sentence\' parameter (not empty aswell)!'))
|
||||||
|
|
||||||
sentence = data['sentence']
|
sentence = data['sentence']
|
||||||
tag_for_request = ia.process.get_tag_for_sentence(sentence)
|
tag_for_request = src.ia.process.get_tag_for_sentence(sentence)
|
||||||
|
|
||||||
print("SENTENCE : " + sentence + " /// TAG : " + tag_for_request)
|
print("SENTENCE : " + sentence + " /// TAG : " + tag_for_request)
|
||||||
|
|
@ -1,7 +1,7 @@
|
|||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from utils import config_utils, intents_utils
|
from jarvis.utils import intents_utils, config_utils
|
||||||
|
|
||||||
|
|
||||||
def what_time_is_it():
|
def what_time_is_it():
|
0
jarvis/skills/entertainement/__init__.py
Normal file
0
jarvis/skills/entertainement/__init__.py
Normal file
0
jarvis/skills/entertainement/jokes/__init__.py
Normal file
0
jarvis/skills/entertainement/jokes/__init__.py
Normal file
@ -1,6 +1,6 @@
|
|||||||
import requests as requests
|
import requests as requests
|
||||||
|
|
||||||
from utils import languages_utils, config_utils
|
from jarvis.utils import languages_utils, config_utils
|
||||||
|
|
||||||
|
|
||||||
def tell_me_a_joke():
|
def tell_me_a_joke():
|
0
jarvis/skills/research/__init__.py
Normal file
0
jarvis/skills/research/__init__.py
Normal file
0
jarvis/skills/research/wikipedia_search/__init__.py
Normal file
0
jarvis/skills/research/wikipedia_search/__init__.py
Normal file
0
jarvis/utils/__init__.py
Normal file
0
jarvis/utils/__init__.py
Normal file
@ -3,7 +3,7 @@ import json
|
|||||||
import requests
|
import requests
|
||||||
from requests.structures import CaseInsensitiveDict
|
from requests.structures import CaseInsensitiveDict
|
||||||
|
|
||||||
from utils import config_utils
|
from jarvis.utils import config_utils
|
||||||
|
|
||||||
client_url = config_utils.get_in_config("CLIENT_URL")
|
client_url = config_utils.get_in_config("CLIENT_URL")
|
||||||
|
|
@ -1,7 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import get_path_file
|
from jarvis import get_path_file
|
||||||
|
|
||||||
path = os.path.dirname(get_path_file.__file__)
|
path = os.path.dirname(get_path_file.__file__)
|
||||||
|
|
@ -3,8 +3,8 @@ import json
|
|||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
|
||||||
import get_path_file
|
from jarvis import get_path_file
|
||||||
from utils import languages_utils
|
from jarvis.utils import languages_utils
|
||||||
|
|
||||||
all_intents = dict()
|
all_intents = dict()
|
||||||
path = os.path.dirname(get_path_file.__file__)
|
path = os.path.dirname(get_path_file.__file__)
|
@ -1,8 +1,8 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import get_path_file
|
from jarvis import get_path_file
|
||||||
from utils import config_utils
|
from jarvis.utils import config_utils
|
||||||
|
|
||||||
path = os.path.dirname(get_path_file.__file__)
|
path = os.path.dirname(get_path_file.__file__)
|
||||||
|
|
27
jarvis/utils/nlp_utils.py
Normal file
27
jarvis/utils/nlp_utils.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import spacy
|
||||||
|
from nltk.corpus import stopwords
|
||||||
|
|
||||||
|
|
||||||
|
def get_spacy_nlp():
|
||||||
|
"""
|
||||||
|
|
||||||
|
:return: spacy
|
||||||
|
"""
|
||||||
|
nlp = spacy.load("en_core_web_sm")
|
||||||
|
return nlp
|
||||||
|
|
||||||
|
|
||||||
|
def get_text_without_stopwords(sentence):
|
||||||
|
stopwords_spacy = get_spacy_nlp().Defaults.stop_words
|
||||||
|
|
||||||
|
stop_words = set(stopwords_spacy)
|
||||||
|
filtered_sentence = [w for w in sentence.lower().split() if w not in stop_words]
|
||||||
|
filtered_sentence = " ".join(filtered_sentence)
|
||||||
|
return filtered_sentence
|
||||||
|
|
||||||
|
|
||||||
|
def get_text_without_stopwords_nltk(sentence, language='english'):
|
||||||
|
stop_words = set(stopwords.words(language))
|
||||||
|
filtered_sentence = [w for w in sentence.lower().split() if w not in stop_words]
|
||||||
|
filtered_sentence = " ".join(filtered_sentence)
|
||||||
|
return filtered_sentence
|
@ -1,18 +0,0 @@
|
|||||||
from nltk.corpus import stopwords
|
|
||||||
|
|
||||||
from utils.languages_utils import get_language_full_name
|
|
||||||
|
|
||||||
|
|
||||||
def get_text_without_stopwords(sentence, language='english'):
|
|
||||||
# if the language given is something like en-us, get the full variant (english)
|
|
||||||
if '-' in language:
|
|
||||||
language = get_language_full_name(language)
|
|
||||||
|
|
||||||
stop_words = set(stopwords.words(language))
|
|
||||||
filtered_sentence = [w for w in sentence.lower().split() if w not in stop_words]
|
|
||||||
filtered_sentence = " ".join(filtered_sentence)
|
|
||||||
return filtered_sentence
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
print(get_text_without_stopwords("Hey give me some info about Elon Musk please"))
|
|
Reference in New Issue
Block a user