-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharticleAnalyser.go
62 lines (51 loc) · 1.26 KB
/
articleAnalyser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"errors"
"fmt"
"net/url"
"time"
)
// ErrRequestLimitMet error
var ErrRequestLimitMet = errors.New("Request limit met")
// ArticleAnalyser interface
type ArticleAnalyser interface {
Analyse(u *ArticleURL) *TextRazorResult
}
// Analyser struct
type Analyser struct {
apiKey string
downloadUserAgent string
}
// NewAnalyser Analyser constructor
func NewAnalyser(key string) *Analyser {
return &Analyser{
apiKey: key,
downloadUserAgent: fmt.Sprintf("NuseAgent Article Downloader v1.0 (%s)", url.QueryEscape("http://nuseagent.com/")),
}
}
// Analyse method
func (a *Analyser) Analyse(u *ArticleURL) (*TextRazorResult, error) {
if config.RequestLimitMet() {
return nil, ErrRequestLimitMet
}
c := NewTimeoutClient(time.Duration(config.timeout) * time.Second)
tr := NewTextRazorRequest(a.apiKey)
tr.DownloadUserAgent = a.downloadUserAgent
tr.URL = u.String()
tr.CleanupMode = ModeCleanHTML
tr.CleanupReturnCleaned = false
tr.CleanupReturnRaw = false
tr.SetExtractors(
ExtractorTopics,
ExtractorEntities,
ExtractorWords,
ExtractorPhrases,
ExtractorDependancyTrees,
ExtractorRelations,
ExtractorEntailments,
ExtractorSenses,
)
result, err := tr.Analysis(c)
config.IncRequestCount()
return result, err
}