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
+7.6k Golang : get the current working directory of a running program
+11.3k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+13k Golang : Convert(cast) int to int64
+7.4k SSL : How to check if current certificate is sha1 or sha2 from command line
+24.1k Golang : How to validate URL the right way
+5.4k Python : Print unicode escape characters and string
+6.5k Golang : How to validate ISBN?
+10.3k Golang : Generate random integer or float number
+17.9k Golang : Convert IPv4 address to decimal number(base 10) or integer
+3.5k Java : Get FX sentiment from website example
+4.9k Linux : How to set root password in Linux Mint
+13.7k Golang : Gin framework accept query string by post request example