This is a Go library for summarizing text and websites and optionally saving the data to a local file
go get github.com/ktodorov/go-summarizer
var unsummarizedText = "unsummarized text"
var s = CreateFromText(unsummarizedText)
var urlToSummarize = "http://testurl.test/"
var s = CreateFromURL(urlToSummarize)
var customNewsStoryURL = `https://techcrunch.com/2017/01/14/spacex-successfully-returns-to-launch-with-iridium-1-next-falcon-9-mission/`
var s = CreateFromURL(customNewsStoryURL)
summary, err := s.Summarize()
if err != nil {
fmt.Println("Error occurred: ", err.Error())
return
}
fmt.Println(summary)
Output*:
SpaceX successfully returns to launch with Iridium-1 NEXT Falcon 9 mission
It’s a huge victory for SpaceX, which has had to delay its launch schedule since the explosion. The launch also resulted in a successful recovery of the Falcon 9 rocket’s first stage, which marks the seventh time SpaceX has succeed in landing this stage back for potential later re-use It’s also a green light for SpaceX in terms of the company pursuing its aggressive launch schedule, which is something the private launch provider needs to do in order to continue locking in new contracts and working towards its goal of decreasing the cost of launches even further still. In 2016, SpaceX completed only 8 of a planned 20 launches, due to the September 1 explosion that halted all new launches for four months SpaceX also had to push back its timelines for test launches of its Dragon crew capsule as a result of the September incident It also sets the stage for SpaceX’s future goals of providing missions to Mars, with a target initial date for those aspirations still set for 2024. All satellites were successfully deployed as of 11:13 AM PT / 2:12 PM PT, signalling a successful mission for the space company’s first flight back.
*Note that it first prints the title of the web page if there is such
var s = CreateFromText("first sentence. second sentence")
s.Summarize()
summaryInfo, err := s.GetSummaryInfo()
if err != nil {
fmt.Println("Error occurred: ", err.Error())
}
fmt.Println(summaryInfo)
Output:
Summary info:
- Original length: 31 symbols
- Summary length: 14 symbols
- Summary ratio: 54.84%
var s = CreateFromText("first sentence. second sentence")
fmt.Println("Before summarizing: ", s.IsSummarized())
s.Summarize()
fmt.Println("After summarizing: ", s.IsSummarized())
Output:
Before summarizing: false
After summarizing: true
var s = CreateFromText("first sentence. second sentence")
s.Summarize()
stored, err := s.StoreToFile("some/path/to/file.txt")
if err != nil {
fmt.Println("Error occurred: ", err.Error())
}
fmt.Println(stored)
Output:
true
*Currently supported file types: txt and pdf