-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e59ce1
commit 6a3e1a3
Showing
5 changed files
with
258 additions
and
138 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,5 @@ scikit-learn | |
nltk | ||
numpy | ||
scipy | ||
redis | ||
redis | ||
rq |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
|
||
# import nltk.corpus | ||
# from nltk.corpus import wordnet | ||
# import nltk.tokenize.punkt | ||
# import nltk.stem.snowball | ||
|
||
# Source: http://nbviewer.jupyter.org/urls/gist.github.com/mjbommar/e2a019e346b879c13d3d/raw/74a206c2629d6e661645e18369f05f6c79d15b65/fuzzy-sentence-matching-python.ipynb | ||
# class FuzzyMatcher(): | ||
# def __init__(self): | ||
# self.stopwords = nltk.corpus.stopwords.words('english') | ||
# self.stopwords.extend(string.punctuation) | ||
# self.stopwords.append('') | ||
|
||
# # Create tokenizer and stemmer | ||
# self.tokenizer = nltk.tokenize.punkt.PunktSentenceTokenizer() | ||
# self.lemmatizer = nltk.stem.wordnet.WordNetLemmatizer() | ||
# self.sentences = [] | ||
# self.corpusDict = {} | ||
|
||
# self.matches = {} | ||
# self.matchingDict = {} | ||
|
||
# def generateSentences(self, corpusDict): | ||
# self.corpusDict = corpusDict | ||
# for diagramid, desc in corpusDict.items(): | ||
# self.sentences.append(desc) | ||
|
||
|
||
# def get_wordnet_pos(self, pos_tag): | ||
# if pos_tag[1].startswith('J'): | ||
# return (pos_tag[0], wordnet.ADJ) | ||
# elif pos_tag[1].startswith('V'): | ||
# return (pos_tag[0], wordnet.VERB) | ||
# elif pos_tag[1].startswith('N'): | ||
# return (pos_tag[0], wordnet.NOUN) | ||
# elif pos_tag[1].startswith('R'): | ||
# return (pos_tag[0], wordnet.ADV) | ||
# else: | ||
# return (pos_tag[0], wordnet.NOUN) | ||
|
||
# def is_ci_partial_seq_token_stopword_lemma_match(self,a, b): | ||
# """Check if a and b are matches.""" | ||
# pos_a = map(self.get_wordnet_pos, nltk.pos_tag(self.tokenizer.tokenize(a))) | ||
# pos_b = map(self.get_wordnet_pos, nltk.pos_tag(self.tokenizer.tokenize(b))) | ||
# lemmae_a = [self.lemmatizer.lemmatize(token.lower().strip(string.punctuation), pos) for token, pos in pos_a \ | ||
# if token.lower().strip(string.punctuation) not in self.stopwords] | ||
# lemmae_b = [self.lemmatizer.lemmatize(token.lower().strip(string.punctuation), pos) for token, pos in pos_b \ | ||
# if token.lower().strip(string.punctuation) not in self.stopwords] | ||
# s = difflib.SequenceMatcher(None, lemmae_a, lemmae_b) | ||
|
||
# return (s.ratio() > 0.66) | ||
|
||
# # def is_ci_partial_noun_set_token_stopword_lemma_match(self,a, b): | ||
# # """Check if a and b are matches.""" | ||
# # pos_a = map(self.get_wordnet_pos, nltk.pos_tag(self.tokenizer.tokenize(a))) | ||
# # pos_b = map(self.get_wordnet_pos, nltk.pos_tag(self.tokenizer.tokenize(b))) | ||
# # lemmae_a = [self.lemmatizer.lemmatize(token.lower().strip(string.punctuation), pos) for token, pos in pos_a \ | ||
# # if pos == wordnet.NOUN and token.lower().strip(string.punctuation) not in self.stopwords] | ||
# # lemmae_b = [self.lemmatizer.lemmatize(token.lower().strip(string.punctuation), pos) for token, pos in pos_b \ | ||
# # if pos == wordnet.NOUN and token.lower().strip(string.punctuation) not in self.stopwords] | ||
# # try: | ||
# # ratio = len(set(lemmae_a).intersection(lemmae_b)) / float(len(set(lemmae_a).union(lemmae_b))) | ||
# # except ZeroDivisionError as ze: | ||
# # ratio = 0 | ||
# # return (ratio > 0.66) | ||
|
||
# def doFuzzyMatching(self): | ||
# print (self.sentences) | ||
# for idx, t in enumerate(self.sentences): | ||
# cDictList = list(self.corpusDict.items()) | ||
# matchlist = [] | ||
# sourcediagramid = cDictList[idx][0] | ||
# target_sentence = t | ||
|
||
# for sid, sentence in enumerate(self.sentences): | ||
|
||
# if (self.is_ci_partial_seq_token_stopword_lemma_match(target_sentence, sentence)): | ||
# targetdiagramid = cDictList[sid][0] | ||
# matchlist.append(targetdiagramid) | ||
# else: | ||
# matchlist.append(0) | ||
# self.matchingDict[sourcediagramid] = matchlist | ||
|
||
# return self.matchingDict | ||
# # return 0 |
Oops, something went wrong.