Skip to content

Commit

Permalink
Merge pull request #14 from JesusIslam/fix-11
Browse files Browse the repository at this point in the history
add go module support, simplify things, empty rank not return error, v0.6.0
  • Loading branch information
didasy authored Apr 17, 2019
2 parents c9bcea2 + b88618b commit 68ecf53
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module github.com/JesusIslam/tldr

require (
github.com/alixaxel/pagerank v0.0.0-20160306110729-14bfb4c1d88c
github.com/onsi/ginkgo v1.7.0
github.com/onsi/gomega v1.4.3
)
25 changes: 25 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
github.com/alixaxel/pagerank v0.0.0-20160306110729-14bfb4c1d88c h1:UUHM6/UM34ESICar/DWOhLt2rqYabsvfjmupiY9z+iE=
github.com/alixaxel/pagerank v0.0.0-20160306110729-14bfb4c1d88c/go.mod h1:e7Vic/xXDZAQ8ftWoLnVrXseAAvt54SVYrcirjCKcX0=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
18 changes: 8 additions & 10 deletions tldr.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ WARNING: This package is not thread safe, so you cannot use *Bag from many gorou
package tldr

import (
"errors"
"encoding/json"
"sort"
"strings"
"unicode"
Expand Down Expand Up @@ -38,9 +38,14 @@ type Bag struct {
vectorLength int
}

func (b *Bag) String() string {
r, _ := json.MarshalIndent(b, "", " ")
return string(r)
}

// The default values of each settings
const (
VERSION = "0.5.0"
VERSION = "0.6.0"
DEFAULT_ALGORITHM = "pagerank"
DEFAULT_WEIGHING = "hamming"
DEFAULT_DAMPING = 0.85
Expand All @@ -55,7 +60,6 @@ func defaultWordTokenizer(sentence string) []string {
for i, word := range words {
words[i] = SanitizeWord(word)
}

return words
}

Expand Down Expand Up @@ -125,21 +129,18 @@ func (bag *Bag) Summarize(text string, num int) ([]string, error) {
switch bag.Algorithm {
case "centrality":
bag.centrality()
break
case "pagerank":
bag.pageRank()
break
case "custom":
bag.Ranks = bag.customAlgorithm(bag.Edges)
break
default:
bag.pageRank()
}

// if no ranks, return error
lenRanks := len(bag.Ranks)
if lenRanks == 0 {
return nil, errors.New("Ranks is empty")
return nil, nil
}

// guard so it won't crash but return only the highest rank sentence
Expand Down Expand Up @@ -263,14 +264,11 @@ func (bag *Bag) createEdges() {
case "jaccard":
commonElements := Intersection(src.vector, dst.vector)
weight = 1.0 - float64(len(commonElements))/((float64(bag.vectorLength)*2)-float64(len(commonElements)))
break
case "hamming":
differentElements := SymmetricDifference(src.vector, dst.vector)
weight = float64(len(differentElements))
break
case "custom":
weight = bag.customWeighing(src.vector, dst.vector)
break
default:
differentElements := SymmetricDifference(src.vector, dst.vector)
weight = float64(len(differentElements))
Expand Down
2 changes: 1 addition & 1 deletion util.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func Intersection(src, dst []int) []int {
}
}
var result []int
for k, _ := range intersect {
for k := range intersect {
result = append(result, k)
}
return result
Expand Down

0 comments on commit 68ecf53

Please sign in to comment.