<filename>examples/news_classifier.py
#!/usr/bin/env python3
"""Suppose you have some texts of news and know their categories.

You want to train a system with this pre-categorized/pre-classified
texts. So, you have better call this data your training set.
"""
import nbc

news_trainer = nbc.Trainer()

# You need to train the system passing each text one by one to the trainer module.
news_set = [
    {'text': 'not to eat too much is not enough to lose weight', 'category': 'health'},
    {'text': 'Russia try to invade Ukraine', 'category': 'politics'},
    {'text': 'do not neglect exercise', 'category': 'health'},
    {'text': 'Syria is the main issue, Obama says', 'category': 'politics'},
    {'text': 'eat to lose weight', 'category': 'health'},
    {'text': 'you should not eat much', 'category': 'health'}
]

for news in news_set:
    news_trainer.train(news['text'], news['category'])

# When you have sufficient trained data, you are almost done and can start to use a classifier.
trained_data = news_trainer.export()
news_classifier = nbc.Classifier(trained_data)

# Now you have a classifier which can try to classifiy news text of which the category is unknown.
classification = news_classifier.classify('Obama is')

print(classification)

<filename>examples/news_classifier.py
#!/usr/bin/env python3
"""Suppose you have some texts of news and know their categories.

You want to train a system with this pre-categorized/pre-classified
texts. So, you have better call this data your training set.
"""
import nbc

news_trainer = nbc.Trainer()

# You need to train the system passing each text one by one to the trainer module.
news_set = [
    {'text': 'not to eat too much is not enough to lose weight', 'category': 'health'},
    {'text': 'Russia try to invade Ukraine', 'category': 'politics'},
    {'text': 'do not neglect exercise', 'category': 'health'},
    {'text': 'Syria is the main issue, Obama says', 'category': 'politics'},
    {'text': 'eat to lose weight', 'category': 'health'},
    {'text': 'you should not eat much', 'category': 'health'}
]

for news in news_set:
    news_trainer.train(news['text'], news['category'])

# When you have sufficient trained data, you are almost done and can start to use a classifier.
trained_data = news_trainer.export()
news_classifier = nbc.Classifier(trained_data)

# Now you have a classifier which can try to classifiy news text of which the category is unknown.
classification = news_classifier.classify('Obama is')

print(classification)

#!/usr/bin/env python3 Suppose you have some texts of news and know their categories.  You want to train a system with this pre-categorized/pre-classified texts. So, you have better call this data your training set. # You need to train the system passing each text one by one to the trainer module. # When you have sufficient trained data, you are almost done and can start to use a classifier. # Now you have a classifier which can try to classifiy news text of which the category is unknown.