Skip to content

Commit

Permalink
Start to make components easier to deploy (See #64).
Browse files Browse the repository at this point in the history
  • Loading branch information
hscells committed Aug 26, 2020
1 parent 5bef34d commit e61a0ac
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 60 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ document_frequency/None/
objective_qf/params/None/
top_subheadings/None/
None/
statistics/None/
statistics/None/

resources/quickrank
19 changes: 15 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
plugin_dirs := $(wildcard plugin/*/)
plugin_obs := $(foreach plugin,$(plugin_dirs),$(plugin)plugin.so)
plugin_src := $(patsubst %plugin.so,%*.go,$(plugin_obs))
quicklearn_bin := resources/quickrank/bin/quicklearn
go_source = *.go cmd/searchrefiner/*.go

SERVER = server

plugin: $(plugin_obs)
PHONEY: run all plugin clean
PHONEY: run all plugin clean quicklearn

# These compile the quicklearn binary, which are required for the QueryLens plugin.
$(quicklearn_bin):
@git clone --recursive https://github.com/hpclab/quickrank.git
@cd quickrank && mkdir build_ && cd build_ && cmake .. -DCMAKE_CXX_COMPILER=g++-5 -DCMAKE_BUILD_TYPE=Release && make
@mv quickrank quickrank/resources

quicklearn: $(quicklearn_bin)

# The main server compilation step. It depends on the compilation of any plugins that exist.
$(SERVER): $(plugin_obs) $(go_source)
go build -o server cmd/searchrefiner/server.go

# The plugins are just shared object files that should only need to be recompiled if changed.
.SECONDEXPANSION:
$(plugin_obs): $$(patsubst %plugin.so,%*.go,$$@)
go build -buildmode=plugin -o $@ $^

run: clean $(SERVER)
# Running the server may optionally depend on quicklearn.
run: quicklearn $(SERVER)
@./server

clean:
@[ -f server ] && rm $(foreach plugin,$(plugin_obs),$(plugin)) server] || true
@[ -f server ] && rm $(foreach plugin,$(plugin_obs),$(plugin)) server || true
6 changes: 5 additions & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ import (
type searchResponse struct {
Start int
TotalHits int64
RelRet float64
TookInMillis float64
OriginalQuery string
QueryString string
TransformedQuery string
PreviousQueries []Query
Documents []guru.MedlineDocument
Expand All @@ -41,6 +42,9 @@ type searchResponse struct {
MeshExploded float64
MeshAvgDepth float64
MeshMaxDepth float64

Plugins []InternalPluginDetails
PluginTitle string
}

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

fmt.Println("loading quiche...")
quicheCache, err := quiche.Load(c.Options.Quiche)
quicheCache, err := quiche.Load(c.Resources.Quiche)
if err != nil {
panic(err)
}
fmt.Println("loading cui2vec mapping...")
cuiMapping, err := cui2vec.LoadCUIMapping(c.Options.Cui2VecMappings)
cuiMapping, err := cui2vec.LoadCUIMapping(c.Resources.Cui2VecMappings)
if err != nil {
panic(err)
}
fmt.Println("loading cui2vec model...")
cui2vecf, err := os.Open(c.Options.Cui2VecEmbeddings)
cui2vecf, err := os.Open(c.Resources.Cui2VecEmbeddings)
if err != nil {
panic(err)
}
Expand Down
34 changes: 33 additions & 1 deletion components/util.tmpl.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{define "version"}}
30.June.2020
25.Aug.2020
{{end}}

{{define "footer"}}
Expand All @@ -22,4 +22,36 @@
<div class="hero-lg bg-primary " style="width: 100%;position:fixed;bottom: 0;padding: 1%;z-index: 10000">
{{template "footer"}}
</div>
{{ end }}


{{ define "send_query" }}
{{ $query := .QueryString }}
{{ $lang := .Language }}
{{ $title := .PluginTitle }}
{{ range $plugin := .Plugins }}
{{ if $plugin.AcceptsQueryPosts }}
{{ if ne $title $plugin.Title }}
<form action="/{{ $plugin.URL }}" method="post">
<input type="hidden" name="query" v-bind:value="textQuery" value="{{ $query }}">
<input type="hidden" name="lang" value="{{ $lang }}">
<button class="btn btn-link">{{ $plugin.Title }} <i class="icon icon-arrow-right"></i></button>
</form>
{{ end }}
{{ end }}
{{ end }}
<button class="btn btn-link" v-on:click="sendToPolyglot()" onclick="sendToPolyglot()">Polyglot (external tool)<i class="icon icon-arrow-right"></i></button>
<script>
sendToPolyglot = function () {
var request = new XMLHttpRequest();
request.addEventListener("load", function (ev) {
if (ev.currentTarget.status === 200) {
window.open("https://sr-accelerator.com/#/polyglot?token=" + ev.target.responseText, target = "_blank");
}
});
request.open("POST", "https://ielab-sysrev3.uqcloud.net/exchange", true);
request.setRequestHeader('Content-Type', 'application/json');
request.send(JSON.stringify({data: {query: {{ $query }}}, referrer: "searchrefiner"}));
}
</script>
{{ end }}
23 changes: 14 additions & 9 deletions configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ type OtherServiceAddresses struct {
}

type Config struct {
Host string
AdminEmail string
Admins []string
Entrez EntrezConfig
Options Options // TODO: This should be merged into the Services struct.
Mode string
EnableAll bool
Services Services
Host string
AdminEmail string
Admins []string
Entrez EntrezConfig
Resources Resources // TODO: This should be merged into the Services struct.
Mode string
EnableAll bool
Services Services
ExchangeServerAddress string
OtherServiceAddresses OtherServiceAddresses
}

type Options struct {
type Resources struct {
Cui2VecEmbeddings string
Cui2VecMappings string
Quiche string
Expand All @@ -83,6 +83,9 @@ type Query struct {
NumRet int64 `csv:"num_ret"`
NumRelRet int64 `csv:"num_rel_ret"`
Relevant []string `csv:"relevant"`

Plugins []InternalPluginDetails
PluginTitle string
}

type ErrorPage struct {
Expand Down Expand Up @@ -124,6 +127,8 @@ type PluginDetails struct {
Author string
Version string
ProjectURL string

AcceptsQueryPosts bool
}

// InternalPluginDetails contains details about a plugin which are vital in rendering the plugin page.
Expand Down
9 changes: 6 additions & 3 deletions plugin/queryvis/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,10 @@
<button class="btn btn nav-height" id="btn-update-tree" v-on:click="updateTree('none')">
<i class="icon icon-refresh"></i> Visualise
</button>
<button class="btn btn-link" v-on:click="sendToPolyglot()" type="button">
Open Query in Polyglot <i class="icon icon-arrow-right"></i>
</button>
{{ template "send_query" .}}
{{/* <button class="btn btn-link" v-on:click="sendToPolyglot()" type="button">*/}}
{{/* Open Query in Polyglot <i class="icon icon-arrow-right"></i>*/}}
{{/* </button>*/}}
</div>
</div>
<div class="form-group p-2">
Expand Down Expand Up @@ -926,6 +927,8 @@
document.body.appendChild(form);
form.submit();
};
sendToPolyglot = function () {
}
</script>
</body>
</html>
15 changes: 8 additions & 7 deletions plugin/queryvis/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func handleTree(s searchrefiner.Server, c *gin.Context, relevant ...combinator.D
if len(relevant) == 0 {
relevant = s.Settings[username].Relevant
}

var root combinator.LogicalTree
root, err = combinator.NewShallowLogicalTree(gpipeline.NewQuery("searchrefiner", "0", repr.(cqr.CommonQueryRepresentation)), s.Entrez, relevant)
if err != nil {
Expand Down Expand Up @@ -147,7 +147,7 @@ func (QueryVisPlugin) Serve(s searchrefiner.Server, c *gin.Context) {
c.Render(http.StatusOK, searchrefiner.RenderPlugin(searchrefiner.TemplatePlugin("plugin/queryvis/index.html"), struct {
searchrefiner.Query
View string
}{searchrefiner.Query{QueryString: rawQuery, Language: lang}, c.Query("view")}))
}{searchrefiner.Query{QueryString: rawQuery, Language: lang, Plugins: s.Plugins, PluginTitle: "QueryVis"}, c.Query("view")}))
return
}

Expand All @@ -157,11 +157,12 @@ func (QueryVisPlugin) PermissionType() searchrefiner.PluginPermission {

func (QueryVisPlugin) Details() searchrefiner.PluginDetails {
return searchrefiner.PluginDetails{
Title: "QueryVis",
Description: "Visualise queries as a syntax tree overlaid with retrieval statistics and other understandability visualisations.",
Author: "ielab",
Version: "12.Feb.2019",
ProjectURL: "ielab.io/searchrefiner",
Title: "QueryVis",
Description: "Visualise queries as a syntax tree overlaid with retrieval statistics and other understandability visualisations.",
Author: "ielab",
Version: "26.Aug.2020",
ProjectURL: "ielab.io/searchrefiner",
AcceptsQueryPosts: true,
}
}

Expand Down
17 changes: 7 additions & 10 deletions sample.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
"Email": "[email protected]",
"APIKey": "1234abcde"
},
"Mode": "",
"EnableAll": true,
"Options": {
"Cui2VecEmbeddings": "path/to/cui2vec_precomputed.bin",
"Cui2VecMappings": "path/to/cuis.csv",
"Quiche": "path/to/quiche.cache",
"QuickRank": "path/to/quicklearn"
"Mode": "",
"Resources": {
"Cui2VecEmbeddings": "resources/cui2vec_precomputed.bin",
"Cui2VecMappings": "resources/cuis.csv",
"Quiche": "resources/quiche.cache",
"QuickRank": "resources/quickrank/bin/quicklearn"
},
"Services": {
"MetaMapURL": "ielab-metamap",
Expand All @@ -32,8 +32,5 @@
"Merged": false,
"Sources": "cui,es"
},
"ExchangeServerAddress": "https://abc.com/exchange",
"OtherServiceAddresses": {
"SRA": ""
}
"ExchangeServerAddress": "https://ielab-sysrev3.uqcloud.net/exchange"
}
45 changes: 29 additions & 16 deletions views.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (s Server) HandleResults(c *gin.Context) {
Start: len(docs),
TotalHits: int64(size),
TookInMillis: float64(time.Since(start).Nanoseconds()) / 1e-6,
OriginalQuery: rawQuery,
QueryString: rawQuery,
TransformedQuery: q,
Documents: docs,
Language: lang,
Expand Down Expand Up @@ -143,32 +143,45 @@ func (s Server) HandleQuery(c *gin.Context) {
sr := searchResponse{
TotalHits: int64(size),
TookInMillis: float64(time.Since(start).Nanoseconds()) / 1e-6,
OriginalQuery: rawQuery,
QueryString: rawQuery,
TransformedQuery: transformed,
Language: lang,

PluginTitle: "searchrefiner",
}

gq := gpipeline.NewQuery("searchrefiner", "0", repr.(cqr.CommonQueryRepresentation))
sr.BooleanClauses, err = analysis.BooleanClauses.Execute(gq, s.Entrez)
sr.BooleanFields, _ = analysis.BooleanFields.Execute(gq, s.Entrez)
sr.BooleanKeywords, _ = analysis.BooleanKeywords.Execute(gq, s.Entrez)
sr.MeshKeywords, _ = analysis.MeshKeywordCount.Execute(gq, s.Entrez)
sr.MeshExploded, _ = analysis.MeshExplodedCount.Execute(gq, s.Entrez)
sr.MeshAvgDepth, _ = analysis.MeshAvgDepth.Execute(gq, s.Entrez)
sr.MeshMaxDepth, _ = analysis.MeshMaxDepth.Execute(gq, s.Entrez)

username := s.Perm.UserState().Username(c.Request)

// Reverse the list of previous queries.
rev := make([]Query, len(s.Queries[username]))
j := 0
for i := len(s.Queries[username]) - 1; i >= 0; i-- {
rev[j] = s.Queries[username][i]
j++
if s.Perm.UserState().UserRights(c.Request) {
username := s.Perm.UserState().Username(c.Request)
t, err := combinator.NewShallowLogicalTree(gq, s.Entrez, s.Settings[username].Relevant)
if err != nil {
c.HTML(http.StatusInternalServerError, "error.html", ErrorPage{Error: err.Error(), BackLink: "/"})
return
}
switch q := t.Root.(type) {
case combinator.Combinator:
sr.RelRet = q.R
case combinator.Atom:
sr.RelRet = q.R
}

// Reverse the list of previous queries.
rev := make([]Query, len(s.Queries[username]))
j := 0
for i := len(s.Queries[username]) - 1; i >= 0; i-- {
rev[j] = s.Queries[username][i]
j++
}
sr.PreviousQueries = rev

s.Queries[username] = append(s.Queries[username], Query{QueryString: rawQuery, Language: lang, NumRet: sr.TotalHits})
}
sr.PreviousQueries = rev

s.Queries[username] = append(s.Queries[username], Query{QueryString: rawQuery, Language: lang, NumRet: sr.TotalHits})
sr.Plugins = s.Plugins
c.HTML(http.StatusOK, "query.html", sr)
}

Expand Down
10 changes: 5 additions & 5 deletions web/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<h3>Query Analysis</h3>
<form action="/query" method="post" accept-charset="UTF-8">
<div class="form-group">
<textarea name="query" id="query" class="form-input" placeholder="Enter query here." rows="10" required>{{ .OriginalQuery }}</textarea>
<textarea name="query" id="query" class="form-input" placeholder="Enter query here." rows="10" required>{{ .QueryString }}</textarea>
</div>
<div class="form-group">
<label>Query Language
Expand Down Expand Up @@ -66,13 +66,13 @@ <h3>Query Analysis</h3>
<h4>Statistics</h4>
<ul>
<li><b>{{ .TotalHits }}</b> results.</li>
<li><b>{{ .RelRet }}</b> seed studies retrieved.</li>
<li><b>{{ .BooleanClauses }}</b> clauses.</li>
<li><b>{{ .BooleanKeywords }}</b> keywords.</li>
<li><b>{{ .MeshKeywords }}</b> MeSH Term keywords.</li>
<li><b>{{ .MeshExploded }}</b> MeSH Term keywords (exploded).</li>
<li><b>{{ .MeshAvgDepth }}</b> MeSH Term average depth.</li>
<li><b>{{ .MeshMaxDepth }}</b> MeSH Term maximum depth.</li>
</ul>
<h4>Send this query to...</h4>
{{ template "send_query" .}}
</div>
</div>
<div class="divider"></div>
Expand Down Expand Up @@ -121,7 +121,7 @@ <h4>Statistics</h4>
Query Analysis
</label>
<div class="accordion-body">
<pre id="original" class="code" data-lang="Original">{{ .OriginalQuery }}</pre>
<pre id="original" class="code" data-lang="Original">{{ .QueryString }}</pre>
<pre id="transformed" class="code" data-lang="Transformed">{{ .TransformedQuery }}</pre>
</div>
</div>
Expand Down

0 comments on commit e61a0ac

Please sign in to comment.