Skip to content

Commit

Permalink
add faceted search to web UI (close #69)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimus committed Dec 12, 2021
1 parent 43096dc commit 0646d82
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 26 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [v0.6.2]

- Add [#69]: add faceted search to web UI.
- Add [#61]: add faceted search to CLI app.

## [v0.6.1]

- Add [#67]: score details for web-UI.
Expand Down Expand Up @@ -99,6 +104,8 @@

This document follows [changelog guidelines]

[v0.6.2]: https://github.com/gnames/gnverifier/compare/v0.6.1...v1.6.2
[v0.6.1]: https://github.com/gnames/gnverifier/compare/v0.6.0...v1.6.1
[v0.6.0]: https://github.com/gnames/gnverifier/compare/v0.5.2...v1.6.0
[v0.5.2]: https://github.com/gnames/gnverifier/compare/v0.5.1...v0.5.2
[v0.5.1]: https://github.com/gnames/gnverifier/compare/v0.5.0...v0.5.1
Expand All @@ -117,6 +124,16 @@ This document follows [changelog guidelines]
[v0.2.0]: https://github.com/gnames/gnverifier/compare/v0.1.0...v0.2.0
[v0.1.0]: https://github.com/gnames/gnverifier/tree/v0.1.0

[#80]: https://github.com/gnames/gnverifier/issues/80
[#79]: https://github.com/gnames/gnverifier/issues/79
[#78]: https://github.com/gnames/gnverifier/issues/78
[#77]: https://github.com/gnames/gnverifier/issues/77
[#76]: https://github.com/gnames/gnverifier/issues/76
[#75]: https://github.com/gnames/gnverifier/issues/75
[#74]: https://github.com/gnames/gnverifier/issues/74
[#73]: https://github.com/gnames/gnverifier/issues/73
[#72]: https://github.com/gnames/gnverifier/issues/72
[#71]: https://github.com/gnames/gnverifier/issues/71
[#70]: https://github.com/gnames/gnverifier/issues/70
[#69]: https://github.com/gnames/gnverifier/issues/69
[#68]: https://github.com/gnames/gnverifier/issues/68
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ gnverifier file.txt

### Advanced Search Query Language

Example: `g:M. sp:gallop. au:Oliv. y:1750-1799`

Query language allows searching for scientific names using name components
like genus name, specific epithet, infraspecific epithet, author, year.
It includes following operators:
Expand Down
20 changes: 2 additions & 18 deletions gnverifier/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"strings"
"sync"
"time"
"unicode"

"github.com/dustin/go-humanize"
"github.com/gnames/gnfmt"
vlib "github.com/gnames/gnlib/ent/verifier"
"github.com/gnames/gnquery"
"github.com/gnames/gnquery/ent/search"
"github.com/gnames/gnsys"
"github.com/gnames/gnverifier"
"github.com/gnames/gnverifier/config"
Expand Down Expand Up @@ -321,29 +321,13 @@ func verify(gnv gnverifier.GNverifier, str string) {
}
verifyFile(gnv, f)
f.Close()
} else if isQuery(str) {
} else if search.IsQuery(str) {
searchQuery(gnv, str)
} else {
verifyString(gnv, str)
}
}

func isQuery(s string) bool {
s = strings.TrimSpace(s)
idx := strings.Index(s, ":")
if idx == -1 {
return false
}

rs := []rune(s[0:idx])
for i := range rs {
if !unicode.IsLower(rs[i]) {
return false
}
}
return true
}

func verifyFile(gnv gnverifier.GNverifier, f io.Reader) {
batch := gnv.Config().Batch
in := make(chan []string)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/dustin/go-humanize v1.0.0
github.com/gnames/gnfmt v0.2.0
github.com/gnames/gnlib v0.6.6
github.com/gnames/gnquery v0.1.14
github.com/gnames/gnquery v0.2.0
github.com/gnames/gnsys v0.2.2
github.com/gnames/gnuuid v0.1.1
github.com/labstack/echo/v4 v4.6.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ github.com/gnames/gnparser v1.5.5/go.mod h1:prvrAYGrtT/LxN8ovG3LFojgjR7VDcao/cNW
github.com/gnames/gnparser v1.5.7 h1:Spn1Zvm9FEpAGlV7L380x3DdCWmX8X3YGORC7jGDd0U=
github.com/gnames/gnparser v1.5.7/go.mod h1:prvrAYGrtT/LxN8ovG3LFojgjR7VDcao/cNWYjUyYw0=
github.com/gnames/gnquery v0.1.2/go.mod h1:Jm0ZiyZ8nd4+7Pu9xdGRi5F8q6XsCADUfDIfeH+oAjs=
github.com/gnames/gnquery v0.1.14 h1:FtAwykap5xt/kl33/CsFIZRIH3cQ08EllCQ5ETOg5rU=
github.com/gnames/gnquery v0.1.14/go.mod h1:FuY6vibVjaR6AZpi1+dXBzE5c6POyu8Bwb0hgR/OqGQ=
github.com/gnames/gnquery v0.2.0 h1:GW9ShVG1t0wJTCZb0A4JtDpgWCfAmciMhw2wX/0VtLc=
github.com/gnames/gnquery v0.2.0/go.mod h1:FuY6vibVjaR6AZpi1+dXBzE5c6POyu8Bwb0hgR/OqGQ=
github.com/gnames/gnsys v0.2.2 h1:7IG4aKdCQzzP1tBFp6I9s75QSwM/qhMjpyQVQsedQUY=
github.com/gnames/gnsys v0.2.2/go.mod h1:xCjepsCm9yJWTpIfDGt0sUJBLoFRGzH0I3F6ast+Bow=
github.com/gnames/gnuuid v0.1.1 h1:UMRHYUSlD19qo8oVz1JyU57kg4yu+SJ/b+yvWYeqRiA=
Expand Down
31 changes: 30 additions & 1 deletion io/web/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ import (

"github.com/gnames/gnfmt"
vlib "github.com/gnames/gnlib/ent/verifier"
"github.com/gnames/gnquery"
"github.com/gnames/gnquery/ent/search"
"github.com/gnames/gnuuid"
"github.com/gnames/gnverifier"
"github.com/gnames/gnverifier/config"
"github.com/gnames/gnverifier/ent/output"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/labstack/gommon/log"
)

const withLogs = false
Expand Down Expand Up @@ -249,7 +253,32 @@ func verificationResults(
}
gnv = gnv.ChangeConfig(opts...)

data.Verified = gnv.VerifyBatch(names)
if search.IsQuery(names[0]) {
var err error
inp := gnquery.New().Parse(names[0])
ds := gnv.Config().DataSources
if len(ds) > 0 {
if ds[0] == 0 {
inp.WithAllResults = true
} else {
inp.DataSourceIDs = ds
}
}
data.Verified, err = gnv.Search(inp)
if err != nil {
log.Warn(err)
}
if len(data.Verified) == 0 {
data.Verified = []vlib.Name{
{
ID: gnuuid.New(inp.Query).String(),
Name: inp.Query,
},
}
}
} else {
data.Verified = gnv.VerifyBatch(names)
}
if prefOnly {
for i := range data.Verified {
data.Verified[i].BestResult = nil
Expand Down
7 changes: 5 additions & 2 deletions io/web/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ func addFuncs(tmpl *template.Template) {
},
"scoreDetails": func(sd vlib.ScoreDetails) template.HTML {
curSrc := "Curated Source"
rank := "Rank Matched"
sds := []struct {
name string
val float32
}{
{"Rank Matched", sd.InfraSpecificRankScore},
{rank, sd.InfraSpecificRankScore},
{"Not Fuzzy", sd.FuzzyLessScore},
{curSrc, sd.CuratedDataScore},
{"Authors/Year Match", sd.AuthorMatchScore},
Expand All @@ -120,7 +121,7 @@ func addFuncs(tmpl *template.Template) {
var res []string
for _, v := range sds {
switch {
case v.val < 0.3:
case (v.name == rank && v.val < 1.0) || v.val < 0.3:
color = "#aaa"
case (v.name == curSrc && v.val > 0.5) || v.val == 1:
color = "#080"
Expand All @@ -145,6 +146,8 @@ func addFuncs(tmpl *template.Template) {
switch mt {
case vlib.Exact:
res = fmt.Sprintf("<span style='color: %s'>✔</span> %s match by canonical form", clr["green"], mt)
case vlib.FacetedSearch:
res = fmt.Sprintf("<span style='color: %s'>✔</span> %s match", clr["green"], mt)
case vlib.NoMatch:
res = fmt.Sprintf("<span style='color: %s'>✕</span> %s", clr["red"], mt)
case vlib.Fuzzy, vlib.PartialFuzzy:
Expand Down
8 changes: 7 additions & 1 deletion io/web/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ <h5>From selected Data Sources:</h5>
Optionally, it can also return matches from data-sources selected by a user.
</p>
<div id='resolver-form'>
<p>Paste Scientific Names, one per line (up to 5,000 names)</p>
<p>
Paste Scientific Names, one per line (up to 5,000 names) <br/>or write an
<a href='https://github.com/gnames/gnverifier#advanced-search-query-language'
target='_blank'>Advanced Search Query</a>
(ex:
<code style='background-color: #ddd; padding: 0.2em'>g:B. sp:bubo au:Linn.</code>).
</p>
<form action='/' method='POST'>
<div>
<label for='format'>Output format</label>
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package gnverifier

var (
// Version of the gnverifier
Version = "v0.6.1+"
Version = "v0.6.2+"
// Build timestamp
Build = "n/a"
)

0 comments on commit 0646d82

Please sign in to comment.