Beispiel #1
0
def main():
    """ Main entry point into PySum """
    try:
        inputURL = sys.argv[1]
    except IndexError:
        inputURL = 'https://en.wikipedia.org/wiki/Natural_language_processing'

    try:
        percentReduction = int(sys.argv[2])
    except IndexError:
        percentReduction = 40

    rawArticleText = scraper.scrapeArticle(inputURL)
    (articleText,
     articleTextReduced) = preprocess.cleanAndFormat(rawArticleText)

    articleSummary = nlp.summarize(articleText, articleTextReduced,
                                   percentReduction)

    print(articleText)
    print('\n')
    # print(articleTextReduced)
    print('\n')
    print('| ----------------------------------------------- |')
    print('|                 Article Summary                 |')
    print('| ----------------------------------------------- |')
    print('|                  Reduced to %d%%                 |' %
          percentReduction)
    print('| ----------------------------------------------- |')
    print('\n')
    print(articleSummary)
Beispiel #2
0
 def set_summary(self):
     max_sents = 5
     print('senol AKkas')
     summary_sents = nlp.summarize(title=self.title, text=self.text, max_sents=max_sents)
     summary = '\n'.join(summary_sents)
     print(summary)
     self.summary = summary
Beispiel #3
0
 def set_summary(self):
     max_sents = 5
     summary_sents = nlp.summarize(title=self.title,
                                   text=self.text,
                                   max_sents=max_sents)
     summary = '\n'.join(summary_sents)
     self.summary = summary
Beispiel #4
0
def from_cities(*names, **options):
    seeds = filter(None,map(find_city_by_name, names))
    guide = nlp.summarize(
        '\n'.join(s['guide'] for s in seeds),
        max_sentence_count=5)
    options['weathers'] = options.get('weathers') or [s['weather'] for s in seeds]
    options['ignore_cids'] = options.get('ignore_cids',[]) + [s['cid'] for s in seeds]
    return from_guide(guide, **options)
Beispiel #5
0
def analyze_user(user):
    topics = collections.Counter()
    cities = collections.Counter()
    for place in user.pop('places',[]):
        topics.update(place.get('topics') or [])
        cities[place['city']] += 1
    topics = remove_counter_long_tail(topics)
    events = [nlp.translate(e['description']) for e in user.pop('events',[])]
    return {
        'cities':[c for c,_ in cities.most_common(10)],
        'topics':list(topics.elements()),
        'events':nlp.summarize(u'\n'.join(events), max_sentence_count=5)
        }
def nlp(dict_url):
    np.load_stopwords()
    text_keyws = list(np.keywords(dict_url['article']).keys())
    title_keyws = list(np.keywords(dict_url['title']).keys())
    keyws = list(set(title_keyws + text_keyws))
    dict_url['keywords'] = keyws
    max_sents = 5

    summary_sents = np.summarize(dict_url['title'], dict_url['article'],
                                 max_sents)
    summary = '\n'.join(summary_sents)
    dict_url['summary'] = summary
    return dict_url
Beispiel #7
0
def callback(ch, method, properties, body):
    # print('routing key: ' + method.routing_key)
    # print('correlation id: ' + properties.correlation_id)
    # print('reply to: ' + properties.reply_to)
    try:
        body = json.loads(body.decode("utf-8"))
    except Exception as e:
        print("Could not properly load message: %s" % e)
    results = nlp.summarize(body["text"])
    ch.basic_publish(exchange='nlp',
                     routing_key=(properties.reply_to),
                     properties=pika.BasicProperties(correlation_id=properties.correlation_id),
                     body=json.dumps(results, ensure_ascii=False))
    ch.basic_ack(delivery_tag=method.delivery_tag)
Beispiel #8
0
    def nlp(self):
        """Keyword extraction wrapper
        """
        if not self.is_downloaded or not self.is_parsed:
            print 'You must download and parse an article before parsing it!'
            raise ArticleException()

        text_keyws = nlp.keywords(self.text).keys()
        title_keyws = nlp.keywords(self.title).keys()
        keyws = list(set(title_keyws + text_keyws))
        self.set_keywords(keyws)

        summary_sents = nlp.summarize(title=self.title, text=self.text)
        summary = '\n'.join(summary_sents)
        self.set_summary(summary)
Beispiel #9
0
# -*- coding: utf-8 -*-

import nlp

if __name__ == "__main__":
    title = "Philippines phá hủy để cứu vãn thành phố bị phiến quân chiếm đóng"
    content = "Cuộc giao tranh bước sang tuần thứ tư ở Marawi đến nay đã khiến hơn 200 người thiệt mạng và khiến hạ tầng ở thành phố này bị hư hại nghiêm trọng. Trong bối cảnh, phiến quân Hồi giáo Maute tiếp tục cố thủ ở một số khu vực của Marawi, quân đội Philippines những ngày gần đây đã tăng cường các cuộc không kích vào các mục tiêu của chúng. New York Times bình luận, quân đội Philippines dường như đang áp dụng chiến lược phá hủy để cứu vãn Marawi với việc ném bom các mục tiêu phiến quân ít nhất 2 lần mỗi ngày. Bị tàn phá trên diện rộng trong khi hầu hết cư dân đã phải sơ tán để tránh các cuộc giao tranh khiến Marawi giờ đây giống như một thành phố ma. Giới chức địa phương hiện đã lên kế hoạch cho một chương trình khôi phục Marawi sau khi chiến sự kết thúc song công việc tái thiết thành phố được dự đoán là một thách thức vô cùng lớn. Trong khi đó, các tay súng Hồi giáo hiện vẫn chiếm giữ một phần khu vực trung tâm Marawi, nắm các chốt kiểm soát ở một số cây cầu và gài các tay súng bắn tỉa ở một số nhà thờ trong thành phố. Do hàng trăm dân thường vẫn còn mắc kẹt ở Marawi khiến chiến dịch tiêu diệt phiến quân của quân đội trở nên khó khăn hơn. Ngoài ra, các tay súng phiến quân cố thủ trên các tòa nhà cao tầng cũng là yếu tố buộc binh sĩ Philippines phải giữ khoảng cách.Một tư lệnh quân đội cho biết, phiến quân Maute hiện kiểm soát khoảng 20% thành phố ở phía đông nam sông A gus, song chiến sự chỉ diễn ra ác liệt nhất ở khu vực khoảng 500m2.Đây là một cuộc chiến ở thành thị, một cuộc chiến mặt đối mặt. Chúng vẫn cố thủ. Cuộc chiến là hết nhà này đến nhà kia, tòa này đến tòa khác, Christopher Tampus, một tư lệnh đơn vị bộ binh, cho biết.Với việc kiểm soát vùng trời, quân đội Philippines đã tiến hành các cuộc không kích nhằm vào phiến quân. Các cuộc không kích đã hủy hoại nhiều cơ sở hạ tầng ở Marawi nhưng đến nay vẫn chưa thể đẩy lùi hoàn toàn phiến quân khỏi đây. Quân đội Philippines cho biết, phiến quân dùng các nhà thờ hoặc trường học công giáo để làm căn cứ chiến đấu, trong khi quân đội buộc phải tránh tấn công vì đây là những công trình tôn giáo được bảo vệ.Cuộc chiến ở Marawi cũng đánh dấu lần đầu tiên nhóm khủng bố Abu Sayyaf do tên Isnilon Hapilon đứng đầu và nhóm Maute bắt tay tiến hành một chiến dịch lớn. Ngoài ra, các tay súng ngoại quốc từ Indonesia, Malaysia, Ả rập Xê út, Yemen và Chechnya được cho là cũng tham gia vào cuộc chiến ở đây."

    title_segmentation = nlp.tokenizer_content(content=title)
    segmentation = nlp.tokenizer_content(content=content)

    keywords = nlp.keywords(segmentation)
    print keywords

    summary_sents = nlp.summarize(title=title_segmentation, text=segmentation)
    summary = '\n'.join(summary_sents)
    print summary