eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'BayesClassifier':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: BayesClassifier


Inheritance:

   Object
   |
   +--TextClassifier
      |
      +--BayesClassifier

Package:
stx:libbasic2
Category:
Collections-Text-Support
Version:
rev: 1.5 date: 2021/01/20 15:39:45
user: cg
file: BayesClassifier.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


an initial experiment in bayes text classification.
see BayesClassifierTest
This is possibly unfinished and may need more work.

copyright

COPYRIGHT (c) 2016 by eXept Software AG All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Instance protocol:

text handling
o  classify: string
assume that it is a regular text.
split first into lines...

o  classify: string asCategory: categoryName

o  tokenProbabilityOf: token inCategory: category
Calculate probability that a `token` belongs to a `category`


Examples:


|b|

b := BayesClassifier new.
'teach it positive phrases'.
b classify:'amazing, awesome movie!! Yeah!!' asCategory: 'positive'.
b classify:'Sweet, this is incredibly, amazing, perfect, great!!' asCategory: 'positive'.

'teach it a negative phrase'.
b classify:'terrible, shitty thing. Damn. Sucks!!' asCategory: 'negative'.

'teach it a neutral phrase'.
b classify:'I dont really know what to make of this.' asCategory: 'neutral'.

'now test it to see that it correctly categorizes a new document'.
self assert:(b classify:'awesome, cool, amazing!! Yay.')= 'positive'.


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 21 Dec 2024 16:26:25 GMT