Skip to content

Commit

Permalink
Merge pull request #347 from hellohaptik/develop
Browse files Browse the repository at this point in the history
Merge develop to master
  • Loading branch information
chiragjn authored Feb 28, 2020
2 parents da12170 + 06364c5 commit 5d697bd
Show file tree
Hide file tree
Showing 67 changed files with 95 additions and 48 deletions.
1 change: 1 addition & 0 deletions chatbot_ner/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import logging.handlers
import os

Expand Down
1 change: 1 addition & 0 deletions chatbot_ner/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
from __future__ import absolute_import
import os
import sys

Expand Down
2 changes: 1 addition & 1 deletion chatbot_ner/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
For more information on this file, see
https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/
"""

from __future__ import absolute_import
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "chatbot_ner.settings")

Expand Down
1 change: 1 addition & 0 deletions datastore/commands/create_datastore.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from django.core.management.base import BaseCommand
from datastore import DataStore

Expand Down
1 change: 1 addition & 0 deletions datastore/commands/delete_datastore.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from django.core.management.base import BaseCommand
from datastore import DataStore

Expand Down
1 change: 1 addition & 0 deletions datastore/commands/delete_entity_data_datastore.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from django.core.management.base import BaseCommand
from datastore import DataStore

Expand Down
3 changes: 1 addition & 2 deletions datastore/commands/populate_datastore.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import absolute_import
import os

from django.core.management.base import BaseCommand

from datastore import DataStore


Expand Down
3 changes: 1 addition & 2 deletions datastore/commands/repopulate_datastore.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import absolute_import
import os

from django.core.management.base import BaseCommand

from datastore import DataStore


Expand Down
1 change: 1 addition & 0 deletions datastore/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import elasticsearch
import os
from chatbot_ner.settings import BASE_DIR
Expand Down
4 changes: 2 additions & 2 deletions datastore/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
from datastore.exceptions import (DataStoreSettingsImproperlyConfiguredException, EngineNotImplementedException,
EngineConnectionException, NonESEngineTransferException, IndexNotFoundException)
from lib.singleton import Singleton
import six


class DataStore(object):
class DataStore(six.with_metaclass(Singleton, object)):
"""
Singleton class to connect to engine storing entity related data
Expand All @@ -34,7 +35,6 @@ class DataStore(object):
_store_name: Name of the database/index to query on the engine server
_client_or_connection: Low level connection object to the engine, None at initialization
"""
__metaclass__ = Singleton

def __init__(self):
"""
Expand Down
1 change: 1 addition & 0 deletions datastore/elastic_search/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from __future__ import absolute_import
from . import connect, create, populate, query, transfer
1 change: 1 addition & 0 deletions datastore/elastic_search/connect.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from elasticsearch import Elasticsearch
from chatbot_ner.config import CHATBOT_NER_DATASTORE
from datastore.elastic_search.transfer import ESTransfer
Expand Down
1 change: 1 addition & 0 deletions datastore/elastic_search/transfer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import requests
import json
from elasticsearch import Elasticsearch, RequestsHttpConnection
Expand Down
1 change: 1 addition & 0 deletions datastore/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import csv
import os
from collections import defaultdict
Expand Down
1 change: 1 addition & 0 deletions external_api/api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import json
from django.http import HttpResponse
from datastore.datastore import DataStore
Expand Down
2 changes: 1 addition & 1 deletion initial_setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import
import os
import time

import nltk

BASE_DIR = os.path.dirname(__file__)
Expand Down
16 changes: 13 additions & 3 deletions language_utilities/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from language_utilities.constant import ENGLISH_LANG
from language_utilities.constant import TRANSLATED_TEXT
from chatbot_ner.config import ner_logger, GOOGLE_TRANSLATE_API_KEY
import urllib
import six.moves.urllib.request
import six.moves.urllib.parse
import six.moves.urllib.error
import requests


Expand All @@ -18,8 +20,16 @@ def unicode_urlencode(params):
(str): url string with params encoded
"""
if isinstance(params, dict):
params = params.items()
return urllib.urlencode([(k, isinstance(v, unicode) and v.encode('utf-8') or v) for k, v in params])
params = list(params.items())
return six.moves.urllib.parse.urlencode(
[(
k, isinstance(
v,
six.text_type
) and v.encode('utf-8') or v
) for (k, v) in params
]
)


def translate_text(text, source_language_code, target_language_code=ENGLISH_LANG):
Expand Down
1 change: 1 addition & 0 deletions lib/aws_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import boto
import boto3
from chatbot_ner.config import ner_logger
Expand Down
1 change: 1 addition & 0 deletions lib/nlp/const.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import os
from lib.nlp.etc import store_data_in_list
from lib.nlp.ngram import Ngram
Expand Down
7 changes: 4 additions & 3 deletions lib/nlp/etc.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import csv


Expand Down Expand Up @@ -36,10 +37,10 @@ def filter_list(list_to_filter, remove_elements):
Returns:
list of str: The list of elements in first list but not in second
For example output = remove_one_list_to_another(list1=['hi', 'hello', 'bye'],['hi', 'bye'])
print output
For example, output = filter_list(['hi', 'hello', 'bye'],['hi', 'bye'])
print(output)
>> ['hello']
"""
return filter(lambda token: token not in remove_elements, list_to_filter)
return [item for item in list_to_filter if item not in remove_elements]


6 changes: 3 additions & 3 deletions lib/nlp/lemmatizer.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from __future__ import absolute_import
from nltk.stem import WordNetLemmatizer

# constants
from lib.singleton import Singleton
import six

WORDNET_LEMMATIZER = 'WORDNET_LEMMATIZER'


class Lemmatizer(object):
class Lemmatizer(six.with_metaclass(Singleton, object)):
"""
Detects the lemma of a word.
Its a wrapper class which can be used to call respective lemmatizer library. Currently, It has been integrated
Expand Down Expand Up @@ -41,8 +43,6 @@ class Lemmatizer(object):
"""

__metaclass__ = Singleton

def __init__(self, lemmatizer_selected=WORDNET_LEMMATIZER):
"""Initializes a Lemmatizer object
Expand Down
3 changes: 2 additions & 1 deletion lib/nlp/ngram.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import nltk


Expand Down Expand Up @@ -39,7 +40,7 @@ def ngram_list(n, word_list, stop_word_list=None):
all_ngrams = nltk.ngrams(word_list, n)
ngram_list = []
for ngram in all_ngrams:
lowered_ngram_tokens = map(lambda token: token.lower(), ngram)
lowered_ngram_tokens = [token.lower() for token in ngram]
if any(token not in stop_word_set for token in lowered_ngram_tokens):
ngram_list.append(' '.join(ngram))
return ngram_list
5 changes: 3 additions & 2 deletions lib/nlp/pos.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import absolute_import
import nltk

# constants
from lib.singleton import Singleton
import six

DEFAULT_NLTK_TAGGER_PATH = 'taggers/maxent_treebank_pos_tagger/english.pickle'
NLTK_MAXENT_TAGGER = 'NLTK_MAXENT_TAGGER'
Expand All @@ -18,8 +20,7 @@ def tag(self, tokens, tagset=None):
return tagged_tokens


class POS(object):
__metaclass__ = Singleton
class POS(six.with_metaclass(Singleton, object)):

def __init__(self, tagger_selected=NLTK_AP_TAGGER, tagger=None):
self.tagger_dict = {
Expand Down
1 change: 1 addition & 0 deletions lib/nlp/regexreplace.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import re


Expand Down
6 changes: 3 additions & 3 deletions lib/nlp/stemmer.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from __future__ import absolute_import
from nltk.stem.porter import PorterStemmer

# constants
from lib.singleton import Singleton
import six

PORTER_STEMMER = 'PORTER_STEMMER'


class Stemmer(object):
class Stemmer(six.with_metaclass(Singleton, object)):
"""
Detects the stemmer of a word.
Its a wrapper class which can be used to call respective stemmer library. Currently, It has been integrated
Expand Down Expand Up @@ -35,8 +37,6 @@ class Stemmer(object):
"""

__metaclass__ = Singleton

def __init__(self, stemmer_selected=PORTER_STEMMER):
"""Initializes a Stemmer object
Expand Down
7 changes: 3 additions & 4 deletions lib/nlp/tokenizer.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
from __future__ import absolute_import
import re

import nltk
import regex

# constants
from lib.singleton import Singleton
import six

NLTK_TOKENIZER = 'WORD_TOKENIZER'
PRELOADED_NLTK_TOKENIZER = 'PRELOADED_NLTK_TOKENIZER'
LUCENE_STANDARD_TOKENIZER = 'LUCENE_STANDARD_TOKENIZER'
WHITESPACE_TOKENIZER = 'WHITESPACE_TOKENIZER'


class Tokenizer(object):
class Tokenizer(six.with_metaclass(Singleton, object)):
"""
Returns the list of the tokens from the text
Its a wrapper class which can be used to call respective tokenizer library. Currently, It has been integrated
Expand All @@ -31,8 +32,6 @@ class Tokenizer(object):
"""

__metaclass__ = Singleton

def __init__(self, tokenizer_selected=NLTK_TOKENIZER):
"""Initializes a Tokenizer object
Expand Down
1 change: 1 addition & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
from __future__ import absolute_import
import os
import sys

Expand Down
1 change: 1 addition & 0 deletions models/crf/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from chatbot_ner.config import CITY_MODEL_TYPE, DATE_MODEL_TYPE
from .constant import CRF_MODEL_TYPE, CITY_ENTITY_TYPE, DATE_ENTITY_TYPE
from .test import PredictCRF
Expand Down
1 change: 1 addition & 0 deletions models/crf/output_generation/city.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import models.crf.constant as model_constant


Expand Down
1 change: 1 addition & 0 deletions models/crf/output_generation/date.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import models.crf.constant as model_constant


Expand Down
1 change: 1 addition & 0 deletions models/crf/test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from chatbot_ner.config import ner_logger, CITY_MODEL_PATH, DATE_MODEL_PATH
from lib.nlp.const import nltk_tokenizer
from lib.nlp.pos import POS
Expand Down
1 change: 1 addition & 0 deletions models/crf_v2/crf_detect_entity.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from lib.nlp.tokenizer import Tokenizer, NLTK_TOKENIZER
from .crf_preprocess_data import CrfPreprocessData
from .get_crf_tagger import CrfModel
Expand Down
1 change: 1 addition & 0 deletions models/crf_v2/crf_preprocess_data.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import numpy as np
from lib.nlp.pos import POS
import re
Expand Down
1 change: 1 addition & 0 deletions models/crf_v2/crf_train.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import pycrfsuite
from chatbot_ner.config import ner_logger, CRF_MODEL_S3_BUCKET_NAME, CRF_MODEL_S3_BUCKET_REGION, CRF_MODELS_PATH
from datastore.datastore import DataStore
Expand Down
5 changes: 3 additions & 2 deletions models/crf_v2/get_crf_tagger.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from __future__ import absolute_import
from lib.singleton import Singleton
from chatbot_ner.config import CRF_MODEL_S3_BUCKET_REGION, CRF_MODEL_S3_BUCKET_NAME, ner_logger
from lib.aws_utils import read_model_dict_from_s3
import pycrfsuite
import six


class CrfModel(object):
class CrfModel(six.with_metaclass(Singleton, object)):
"""
This class is used to load the crf tagger for a given entity
"""
__metaclass__ = Singleton

def __init__(self, entity_name):
"""
Expand Down
5 changes: 3 additions & 2 deletions models/crf_v2/load_word_embeddings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
import numpy as np
from lib.singleton import Singleton
import pickle
Expand All @@ -6,13 +7,13 @@
import json
from models.crf_v2.constants import TEXT_LIST, CRF_WORD_EMBEDDINGS_LIST
from chatbot_ner.config import ner_logger
import six


class LoadWordEmbeddings(object):
class LoadWordEmbeddings(six.with_metaclass(Singleton, object)):
"""
This method is used to load the word_embeddings into the memory
"""
__metaclass__ = Singleton

def __init__(self):
"""
Expand Down
3 changes: 1 addition & 2 deletions ner_v1/chatbot/combine_detection_logic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import absolute_import
from collections import defaultdict

from six import iteritems

from lib.nlp.const import TOKENIZER
from lib.nlp.regexreplace import RegexReplace
from ner_constants import ORIGINAL_TEXT, DETECTION_METHOD, FROM_MESSAGE, FROM_MODEL_VERIFIED, FROM_MODEL_NOT_VERIFIED
Expand Down
2 changes: 1 addition & 1 deletion ner_v1/chatbot/entity_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ def output_entity_dict_list(entity_value_list, original_text_list, detection_met

entity_list = []
for i, entity_value in enumerate(entity_value_list):
if type(entity_value) in [str, unicode]:
if type(entity_value) in [str, six.text_type]:
entity_value = {
ENTITY_VALUE_DICT_KEY: entity_value
}
Expand Down
1 change: 1 addition & 0 deletions ner_v1/chatbot/tag_message.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from ner_v1.chatbot.combine_detection_logic import combine_output_of_detection_logic_and_tag
from ner_v1.chatbot.entity_detection import get_text, get_city, get_date, get_time, get_email, \
get_phone_number, get_budget, get_number, get_pnr, get_shopping_size
Expand Down
Loading

0 comments on commit 5d697bd

Please sign in to comment.