def test_get_sentences_fail(): """ Test that get_sentences fails when passed None. """ get_sentences(None)
def test_get_sentences_fail(): """ Test that get_sentences fails when passed None. """ get_sentences(None)
def extract_aspects(reviews): """ INPUT: iterable of strings (pd Series, list) OUTPUT: list of aspects Return the aspects from the set of reviews """ # import the aspect extraction functions from opinion_mining.extract_aspects import get_sentences, tokenize, pos_tag, aspects_from_tagged_sents # put all the sentences in all reviews in one stream #sentences = [] #for review in reviews: # sentences.extend(get_sentences(review)) tokenized_sentences = [ tokenize(sentence) for sentence in [sentences for sentences in get_sentences(reviews)] ] # tokenize each sentence #tokenized_sentences = [tokenize(sentence) for sentence in sentences] # pos tag each sentence tagged_sentences = [pos_tag(sentence) for sentence in tokenized_sentences] # from the pos tagged sentences, get a list of aspects aspects = aspects_from_tagged_sents(tagged_sentences) return aspects
def test_get_sentences(): """ Test that the get_sentences method works (Sentence tokenization). """ text = """ This is a test review. I love the sushi at this place! It is really amazing stuff, I swear. I also enjoy the service here. This is a really long and complicated sentence just to make sure that this is working. """ empty = "" null = None sentences = get_sentences(text) assert sentences[0].strip() == "This is a test review." assert len(sentences) == 5
def test_get_sentences(): """ Test that the get_sentences method works (Sentence tokenization). """ text = """ This is a test review. I love the sushi at this place! It is really amazing stuff, I swear. I also enjoy the service here. This is a really long and complicated sentence just to make sure that this is working. """ empty = "" null = None sentences = get_sentences(text) assert sentences[0].strip()=="This is a test review." assert len(sentences)==5
def get_sentences_by_aspect(aspect, reviews): """ INPUT: string (aspect), iterable of strings (full reviews) OUTPUT: iterable of strings Given an aspect and a list of reviews, return a list sof all sentences that mention that aspect. """ # THIS CODE IS TOTALLY COPIED FROM MAIN FILE function 'extract_aspects' # TODO: REFACTOR THIS IN AN INTELLIGENT WAY. from opinion_mining.extract_aspects import get_sentences, tokenize, pos_tag, aspects_from_tagged_sents # get ''' sentences = [] if type(reviews)==str: sentences.append(reviews) else: for review in reviews: sentences.extend(get_sentences(review)) ''' sentences = get_sentences(reviews) # tokenize each sentence tokenized_sentences = [tokenize(sentence) for sentence in sentences] sent_set = [] for i in aspect: for j in tokenized_sentences: if i in j: if i not in sent_set: sent_set.append(j) return sent_set
""" Test that the get_sentences method works (Sentence tokenization). """ text = """ This is a test review. I love the sushi at this place! It is really amazing stuff, I swear. I also enjoy the service here. This is a really long and complicated sentence just to make sure that this is working. """ empty = "" null = None sentences = get_sentences(text) assert sentences[0].strip()=="This is a test review." assert len(sentences)==5 @raises(TypeError) def test_get_sentences_fail(): """ Test that get_sentences fails when passed None. """ get_sentences(None) def test_tokenize(): """"