Skip to content

Repository files navigation

Unsupervised Text Classifier

This project is a simple text classifier based on Pearson correlation and F1 score for similarity selection. It makes use of the Combine Framework provided by the Apple SDK.

Usage:

import UnsupervisedTextClassifier

Article Protocol

A protocol Article is provided to interoperate with the package functions. It can be used as shown:

protocolArticle:Codable{vartext:String?{getset}varkeywords:[String]?{getset}varurl:URL?{getset}}
structTestArticle:Article{vartext:String?varkeywords:[String]?varurl:URL?varoptionalFields:....}

Cluster Definition

The Cluster struct:

structCluster{init(articles:[Article], maxSimilarity:Double=0.5)varpublisher:AnyPublisher<SegmentResultGroup,Never>}

The Cluster struct publishes the SegmentResultGroup which contains the groupped Articles.

Articles ingestion example

@PublishedvarsegmentResults:[SegmentResultGroup]=[]...letsampleHeadlines=["How many people can I have a drink with? And other questions","Full interview: Hillary Clinton, January 17","Covid lockdown eases: Celebrations as pub gardens and shops reopen","Chauvin Trial Judge Denies Request For Jury Sequestration After Police Shooting","Psaki says Biden 'does not spend his time tweeting conspiracy theories' after a GOP senator criticized the president's social-media use","Police release bodycam footage from officer involved shooting in Minnesota"]letarticles= sampleHeadlines.map{ headline inletkeywords:Set<String>=UnsupervisedTextClassifier.extractKeywords(text: headline)returnTestArticle(text: headline, keywords:Array(keywords))}letcluster=Cluster(articles: articles)
cluster
.publisher
.collect().assign(to:&$segmentResults)

SegmentResultGroup Definition

Each SegmentResultGroup represents a cluster with similar elements based on keywords matching.

structResultGroup:Identifiable{publicvarsimilarity:Doublepublicvararticle:Articlepublicvarrow:Int}publicstructCorrelationResult{publicvarscore:Doublepublicvartokens:(a:Int, b:Int)}structSegmentResultGroup:Identifiable{publicvarcorrelation:CorrelationResultpublicvarresultGroup:[ResultGroup]}

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages