Skip to content

Commit

Permalink
Rip visualisation out of core into plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
hscells committed Feb 12, 2019
1 parent 91b7244 commit b594996
Show file tree
Hide file tree
Showing 13 changed files with 692 additions and 720 deletions.
105 changes: 16 additions & 89 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package searchrefiner

import (
"github.com/gin-gonic/gin"
"github.com/hscells/cqr"
"github.com/hscells/groove/combinator"
gpipeline "github.com/hscells/groove/pipeline"
"github.com/hscells/groove/stats"
"github.com/hscells/transmute"
tpipeline "github.com/hscells/transmute/pipeline"
Expand All @@ -30,76 +27,6 @@ type searchResponse struct {
MeshMaxDepth float64
}

type node struct {
ID int `json:"id"`
Value int `json:"value"`
Level int `json:"level"`
Label string `json:"label"`
Shape string `json:"shape"`
}

type edge struct {
From int `json:"from"`
To int `json:"to"`
Value int `json:"value"`
Label string `json:"label"`
}

type tree struct {
Nodes []node `json:"nodes"`
Edges []edge `json:"edges"`
relevant map[combinator.Document]struct{}
NumRelRet int
NumRel int
}

func (s Server) ApiTree(c *gin.Context) {
rawQuery := c.PostForm("query")
lang := c.PostForm("lang")

p := make(map[string]tpipeline.TransmutePipeline)
p["medline"] = transmute.Medline2Cqr
p["pubmed"] = transmute.Pubmed2Cqr

compiler := p["medline"]
if v, ok := p[lang]; ok {
compiler = v
} else {
lang = "medline"
}

cq, err := compiler.Execute(rawQuery)
if err != nil {
c.AbortWithError(500, err)
return
}

if err != nil {
c.AbortWithError(500, err)
return
}
repr, err := cq.Representation()
if err != nil {
c.AbortWithError(500, err)
return
}

var root combinator.LogicalTree
root, _, err = combinator.NewLogicalTree(gpipeline.NewQuery("searchrefiner", "0", repr.(cqr.CommonQueryRepresentation)), s.Entrez, QueryCacher)
if err != nil {
c.AbortWithError(500, err)
return
}

t := buildTree(root.Root, s.Entrez, getSettings(s, c).Relevant...)

username := s.Perm.UserState().Username(c.Request)
t.NumRel = len(s.Settings[username].Relevant)
t.NumRelRet = len(t.relevant)

c.JSON(200, t)
}

func (s Server) ApiScroll(c *gin.Context) {
rawQuery := c.PostForm("query")
lang := c.PostForm("lang")
Expand All @@ -116,7 +43,7 @@ func (s Server) ApiScroll(c *gin.Context) {
startString := c.PostForm("start")
scroll, err := strconv.ParseInt(startString, 10, 64)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
c.String(http.StatusInternalServerError, err.Error())
return
}

Expand All @@ -135,37 +62,37 @@ func (s Server) ApiScroll(c *gin.Context) {

cq, err := compiler.Execute(rawQuery)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
c.String(http.StatusInternalServerError, err.Error())
return
}

cqString, err := cq.String()
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
c.String(http.StatusInternalServerError, err.Error())
return
}

pubmedQuery, err := transmute.Cqr2Pubmed.Execute(cqString)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
c.String(http.StatusInternalServerError, err.Error())
return
}

q, err := pubmedQuery.String()
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
c.String(http.StatusInternalServerError, err.Error())
return
}

pmids, err := s.Entrez.Search(q, s.Entrez.SearchStart(int(scroll)), s.Entrez.SearchSize(10))
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
c.String(http.StatusInternalServerError, err.Error())
return
}

docs, err := s.Entrez.Fetch(pmids)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
c.String(http.StatusInternalServerError, err.Error())
return
}

Expand Down Expand Up @@ -194,16 +121,16 @@ func ApiTransform(c *gin.Context) {

cq, err := compiler.Execute(rawQuery)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
c.String(http.StatusInternalServerError, err.Error())
return
}

q, err := cq.StringPretty()
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
c.String(http.StatusInternalServerError, err.Error())
return
}
c.Data(200, "text/plain", []byte(q))
c.Data(http.StatusOK, "text/plain", []byte(q))
}

func ApiCQR2Query(c *gin.Context) {
Expand All @@ -223,17 +150,17 @@ func ApiCQR2Query(c *gin.Context) {

cq, err := compiler.Execute(rawQuery)
if err != nil {
c.AbortWithError(500, err)
c.String(http.StatusInternalServerError, err.Error())
return
}

s, err := cq.StringPretty()
if err != nil {
c.AbortWithError(500, err)
c.String(http.StatusInternalServerError, err.Error())
return
}

c.Data(200, "application/json", []byte(s))
c.Data(http.StatusOK, "application/json", []byte(s))
}

func ApiQuery2CQR(c *gin.Context) {
Expand All @@ -253,15 +180,15 @@ func ApiQuery2CQR(c *gin.Context) {

cq, err := compiler.Execute(rawQuery)
if err != nil {
c.AbortWithError(500, err)
c.String(http.StatusInternalServerError, err.Error())
return
}

s, err := cq.StringPretty()
if err != nil {
c.AbortWithError(500, err)
c.String(http.StatusInternalServerError, err.Error())
return
}

c.Data(200, "application/json", []byte(s))
c.Data(http.StatusOK, "application/json", []byte(s))
}
11 changes: 0 additions & 11 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,20 @@ func (s Server) ApiAccountLogin(c *gin.Context) {
username = v
} else {
c.HTML(http.StatusUnauthorized, "error.html", ErrorPage{Error: "no username supplied", BackLink: "/account/login"})
c.AbortWithStatus(http.StatusUnauthorized)
return
}

if v, ok := c.GetPostForm("password"); ok {
password = v
} else {
c.HTML(http.StatusUnauthorized, "error.html", ErrorPage{Error: "no password supplied", BackLink: "/account/login"})
c.AbortWithStatus(http.StatusUnauthorized)
return
}

if s.Perm.UserState().CorrectPassword(username, password) {
err := s.Perm.UserState().Login(c.Writer, username)
if err != nil {
c.HTML(http.StatusUnauthorized, "error.html", ErrorPage{Error: err.Error(), BackLink: "/account/login"})
c.AbortWithError(http.StatusUnauthorized, err)
return
}
c.Redirect(http.StatusFound, "/")
Expand All @@ -52,35 +49,30 @@ func (s Server) ApiAccountCreate(c *gin.Context) {
username = v
} else {
c.HTML(http.StatusUnauthorized, "error.html", ErrorPage{Error: "no username supplied", BackLink: "/account/create"})
c.AbortWithStatus(http.StatusUnauthorized)
return
}

if v, ok := c.GetPostForm("password"); ok {
password = v
} else {
c.HTML(http.StatusUnauthorized, "error.html", ErrorPage{Error: "passwords do not match", BackLink: "/account/create"})
c.AbortWithStatus(http.StatusUnauthorized)
return
}

if v, ok := c.GetPostForm("password2"); ok {
password2 = v
} else {
c.HTML(http.StatusUnauthorized, "error.html", ErrorPage{Error: "passwords do not match", BackLink: "/account/create"})
c.AbortWithStatus(http.StatusUnauthorized)
return
}

if password != password2 {
c.HTML(http.StatusUnauthorized, "error.html", ErrorPage{Error: "passwords do not match", BackLink: "/account/create"})
c.AbortWithStatus(http.StatusUnauthorized)
return
}

if s.Perm.UserState().HasUser(username) {
c.HTML(http.StatusUnauthorized, "error.html", ErrorPage{Error: "a user with that name already exists", BackLink: "/account/create"})
c.AbortWithStatus(http.StatusUnauthorized)
return
}

Expand All @@ -103,7 +95,6 @@ func (s Server) ApiAccountCreate(c *gin.Context) {
err := s.Perm.UserState().Login(c.Writer, username)
if err != nil {
c.HTML(http.StatusUnauthorized, "error.html", ErrorPage{Error: err.Error(), BackLink: "/account/create"})
c.AbortWithError(http.StatusUnauthorized, err)
return
}
c.Redirect(http.StatusFound, "/")
Expand Down Expand Up @@ -134,7 +125,6 @@ func (s Server) HandleAdmin(c *gin.Context) {
u, err := s.Perm.UserState().AllUnconfirmedUsernames()
if err != nil {
c.HTML(http.StatusUnauthorized, "error.html", ErrorPage{Error: err.Error(), BackLink: "/"})
c.AbortWithError(http.StatusInternalServerError, err)
return
}

Expand All @@ -150,7 +140,6 @@ func (s Server) ApiAdminConfirm(c *gin.Context) {
s.Perm.UserState().Confirm(v)
} else {
c.HTML(http.StatusUnauthorized, "error.html", ErrorPage{Error: "invalid credentials", BackLink: "/"})
c.AbortWithStatus(http.StatusUnauthorized)
return
}

Expand Down
17 changes: 6 additions & 11 deletions cmd/searchrefiner/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ func main() {
}

s := searchrefiner.Server{
Perm: perm,
Config: c,
Queries: make(map[string][]searchrefiner.Query),
Settings: make(map[string]searchrefiner.Settings),
Entrez: ss,
Perm: perm,
Config: c,
Queries: make(map[string][]searchrefiner.Query),
Settings: make(map[string]searchrefiner.Settings),
Entrez: ss,
}

permissionHandler := func(c *gin.Context) {
Expand All @@ -97,7 +97,7 @@ func main() {

g.LoadHTMLFiles(append([]string{
// Views.
"web/query.html", "web/index.html", "web/transform.html", "web/tree.html",
"web/query.html", "web/index.html", "web/transform.html",
"web/account_create.html", "web/account_login.html", "web/admin.html",
"web/help.html", "web/error.html", "web/results.html", "web/settings.html", "web/plugins.html",
}, searchrefiner.Components...)...)
Expand Down Expand Up @@ -189,11 +189,6 @@ func main() {
g.POST("/api/cqr2query", searchrefiner.ApiCQR2Query)
g.POST("/api/query2cqr", searchrefiner.ApiQuery2CQR)

// Visualisation interface.
g.GET("/tree", searchrefiner.HandleTree)
g.POST("/tree", searchrefiner.HandleTree)
g.POST("/api/tree", s.ApiTree)

// Settings page.
g.GET("/settings", s.HandleSettings)
g.POST("/api/settings/relevant", s.ApiSettingsRelevantSet)
Expand Down
4 changes: 1 addition & 3 deletions components/sidebar.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<i class="icon icon-menu"></i> searchrefiner
</a>
<div class="off-canvas">
<ul class="menu off-canvas-sidebar text-center" id="sidebar">
<ul class="menu off-canvas-sidebar" id="sidebar">
<li class="menu-item">
<div class="tile tile-centered">
<div class="tile-icon"><img src="/static/favicon.png" class="avatar" width="32px"></div>
Expand All @@ -13,8 +13,6 @@
</li>
<li class="divider"></li>
<li class="menu-item"><a href="/">Home</a></li>
<li class="menu-item"><a href="/tree">QueryVis</a></li>
<li class="menu-item"><a href="/transform">Transform</a></li>
<li class="menu-item"><a href="/settings">Settings</a></li>
<li class="menu-item"><a href="/plugins">Plugins</a></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion components/util.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{end}}

{{define "footer"}}
<footer>
<footer class="pt-2">
Version {{template "version"}} |
<a href="https://ielab.io/searchrefiner/">about</a> |
<a href="/help">help</a> |
Expand Down
16 changes: 11 additions & 5 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
{
"Host": "http://localhost:4853",
"AdminEmail": "[email protected]",
"Host": "localhost:4853",
"AdminEmail": "[email protected]",
"Admins": [
"admin"
"hscells"
],
"Entrez": {
"Email": "[email protected]",
"APIKey": "1234"
"Email": "[email protected]",
"APIKey": "22a11de46af145ce59bb288e0ede66721f09"
},
"Options": {
"Cui2VecEmbeddings": "/Users/s4558151/Repositories/cui2vec/testdata/cui2vec_precomputed.bin",
"Cui2VecMappings": "/Users/s4558151/Repositories/cui2vec/cuis.csv",
"Quiche": "/Users/s4558151/Repositories/cui2vec/quiche.cache",
"QuickRank": "/Users/s4558151/quickrank/bin/quicklearn"
}
}
Loading

0 comments on commit b594996

Please sign in to comment.