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
+9.5k Golang : interface - when and where to use examples
+14.8k Golang : How do I get the local IP (non-loopback) address ?
+5.6k Golang : Find change in a combination of coins example
+36.1k Golang : Converting a negative number to positive number
+17.7k Golang : Get all upper case or lower case characters from string example
+11.1k Android Studio : Create custom icons for your application example
+5.8k PHP : How to check if an array is empty ?
+7.3k Golang : How to stop user from directly running an executable file?
+8.6k Golang : Accept any number of function arguments with three dots(...)
+26.3k Golang : Encrypt and decrypt data with AES crypto
+6.3k Golang : Combine slices of complex numbers and operation example
+6k Apt-get to install and uninstall Golang