Golang : Use NLP to get sentences for each paragraph example
Instead of reading ALL the news with human eyes to find out what's going on with the economy or market trend, it would be a good idea to get the computer to do the heavy lifting and only alert us humans on important news. The program can pickup certain verbs or person names( such as reserve banks governors ) and weight how important the news article is according to some criteria. If ... let say the news article hit certain scores, then generate an alert or trigger an action to either LONG or SHORT a trading instrument.
Below is part of a larger program that uses natural language processing(NLP) to break down a given news article into individual paragraph and each sentences in the paragraph.
Here you go!
package main
import (
"fmt"
"log"
"strings"
"gopkg.in/jdkato/prose.v2"
)
func main() {
text := `EURUSD’s uptrend may be accelerated if US consumer confidence comes in below the 131.0 estimate and Fed Chairman Jerome Powell’s economic outlook bolsters market expectations of rate cuts. Overnight index swaps are pricing in a 100 percent probability of a cut from the July meeting through year-end. However, rhetoric from the central bank has not indicated that policymakers are feeling dovish to that degree.
However, hawkish members of the Fed are finding it increasingly difficult to justify their position in light of US growth. Since February, economic activity out of the US has been broadly underperforming relative to economists’ expectations – signaling that analysts are over estimating the economy’s strength. Inflationary pressure has also been waning alongside a deterioration in global trade due to the US-China trade war.`
// count how many paragraph
paragraph := strings.Split(text, "\n")
//fmt.Println("Paragraph 0 : ", paragraph[0])
//fmt.Println("Paragraph 1 : ", paragraph[1])
// Create a new document for each paragraph
for k, v := range paragraph {
fmt.Println("Processing paragraph ", k, " : ")
doc, err := prose.NewDocument(v)
if err != nil {
log.Fatal(err)
}
// Iterate over the doc's sentences:
for _, sent := range doc.Sentences() {
fmt.Println("["+sent.Text)
}
}
}
Processing paragraph 0 :
[EURUSD’s uptrend may be accelerated if US consumer confidence comes in below the 131.0 estimate and Fed Chairman Jerome Powell’s economic outlook bolsters market expectations of rate cuts.]
[Overnight index swaps are pricing in a 100 percent probability of a cut from the July meeting through year-end.]
[However, rhetoric from the central bank has not indicated that policymakers are feeling dovish to that degree.]
Processing paragraph 1 :
[However, hawkish members of the Fed are finding it increasingly difficult to justify their position in light of US growth.]
[Since February, economic activity out of the US has been broadly underperforming relative to economists’ expectations – signaling that analysts are over estimating the economy’s strength.]
[Inflationary pressure has also been waning alongside a deterioration in global trade due to the US-China trade war.]
See also : Golang : Get FX sentiment from website example
By Adam Ng(黃武俊)
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+12.8k Golang : List objects in AWS S3 bucket
+7.9k Golang : HTTP Server Example
+6.1k Unix/Linux : Use netstat to find out IP addresses served by your website server
+5.5k Golang : Struct field tags and what is their purpose?
+19.8k Golang : Convert seconds to human readable time format example
+22.4k Golang : Round float to precision example
+10.1k Golang : Simple Jawi(Yawi) to Rumi(Latin/Romanize) converter
+7.6k Setting $GOPATH environment variable for Unix/Linux and Windows
+19.1k Golang : Fix cannot download, $GOPATH not set error
+21.5k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload
+14.3k Golang : Execute function at intervals or after some delay
+41.1k Golang : How do I convert int to uint8?