Skip to content

Commit

Permalink
ss.SwapWordAndLemma(); rename some JS files
Browse files Browse the repository at this point in the history
  • Loading branch information
e-gun committed Oct 22, 2023
1 parent 78ac455 commit 4f09691
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# HipparchiaGoServer

### STATUS (v1.2.14):
### STATUS (v1.2.15):

* 25%-700% faster than HipparchiaServer depending on the function. Uses c. 60% as much RAM.
* monolithic binary: no need for extra files/folders; no need to chase dependencies
Expand Down
2 changes: 1 addition & 1 deletion constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "time"
const (
MYNAME = "Hipparchia Golang Server"
SHORTNAME = "HGS"
VERSION = "1.2.14"
VERSION = "1.2.15"
AVGWORDSPERLINE = 8 // hard coding a suspect assumption
BLACKANDWHITE = false
CHARSPERLINE = 60 // used by vector to preallocate memory: set it closer to a max than a real average
Expand Down
8 changes: 4 additions & 4 deletions emb/frontpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,11 @@
{{index . "authhtm"}}

<!-- load uielementlists first: others will use its values -->
<script src="/emb/js/uielementlists_go.js"></script>
<script src="/emb/js/uielementlists.js"></script>
<script src="/emb/js/autocomplete.js"></script>
<script src="/emb/js/browser.js"></script>
<script src="/emb/js/coreinterfaceclicks_go.js"></script>
<script src="/emb/js/radioclicks_go.js"></script>
<script src="/emb/js/coreinterfaceclicks.js"></script>
<script src="/emb/js/radioclicks.js"></script>

<!-- blank divs just to hold scripts for injection later -->
<div id="browserclickscriptholder"> </div>
Expand All @@ -479,7 +479,7 @@
<div id="lexicaljsscriptholder"> </div>

<!-- load documentready last: relies on the existence of much of the above -->
<script src="/emb/js/documentready_go.js"></script>
<script src="/emb/js/documentready.js"></script>

</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ $('#endpointbutton-isopen').click(function(){
});

//
// COMPLEX SEARCH BUTTONS (the clicks are in documentready_go.js; the code is here
// COMPLEX SEARCH BUTTONS (the clicks are in documentready.js; the code is here
//

let tol = $('#termoneisalemma');
Expand Down
2 changes: 1 addition & 1 deletion emb/js/documentready_go.js → emb/js/documentready.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ $(document).ready( function () {
return Array.from(arr, dec2hex).join('');
}

// setoptions() defined in coreinterfaceclicks_go.js
// setoptions() defined in coreinterfaceclicks.js
$('#searchlines').click( function(){ setoptions('searchscope', 'lines'); });
$('#searchwords').click( function(){ setoptions('searchscope', 'words'); });

Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/e-gun/nlp v0.0.0-20230418221101-577c2209ffcc
github.com/e-gun/tsnemp v0.0.0
github.com/e-gun/wego v0.0.11
github.com/go-echarts/go-echarts/v2 v2.2.7
github.com/go-echarts/go-echarts/v2 v2.3.1
github.com/google/uuid v1.3.1
github.com/gorilla/websocket v1.5.0
github.com/jackc/pgx/v5 v5.4.3
Expand All @@ -30,7 +30,7 @@ require (
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions rt-getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type JSStruct struct {

// RtGetJSSession - return the JSON for the session values for parsing by client JS
func RtGetJSSession(c echo.Context) error {
// see hipparchiajs/coreinterfaceclicks_go.js
// see hipparchiajs/coreinterfaceclicks.js

user := readUUIDCookie(c)
s := AllSessions.GetSess(user)
Expand Down Expand Up @@ -161,7 +161,7 @@ func RtGetJSWorksStruct(c echo.Context) error {
return c.JSONPretty(http.StatusOK, lvls, JSONINDENT)
}

// RtGetJSHelpdata - populate <div id="helptabs"> on frontpage.html via $('#helpbutton').click in documentready_go.js
// RtGetJSHelpdata - populate <div id="helptabs"> on frontpage.html via $('#helpbutton').click in documentready.js
func RtGetJSHelpdata(c echo.Context) error {
cat := []string{"Interface", "Browsing", "Dictionaries", "MakingSearchLists", "BasicSyntax", "RegexSearching",
"LemmaSearching", "Oddities", "Extending", "IncludedMaterials", "PDFFiles"}
Expand Down
49 changes: 40 additions & 9 deletions searchstructs.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ func (s *SearchStruct) Optimize() {
return
}

// a single word should be faster than a lemma
if s.HasLemmaBoxA && !s.HasPhraseBoxB {
s.SwapWordAndLemma()
}

// consider looking for the string with more characters in it first
if len(s.Seeking) > 0 && len(s.Proximate) > 0 {
s.SearchQuickestFirst()
Expand Down Expand Up @@ -322,15 +327,8 @@ func (s *SearchStruct) PickFastestLemma() {
}
}

// SwapPhraseAndLemma - if BoxA has a lemma and BoxB has a phrase, it very likely faster to search B, then A...
func (s *SearchStruct) SwapPhraseAndLemma() {
// we will swap elements and reset the relevant elements of the SearchStruct

// no SwapPhraseAndLemma(): [Δ: 4.564s] lemma near phrase: 'γαῖα' near 'ἐϲχάτη χθονόϲ'
// yes SwapPhraseAndLemma(): [Δ: 1.276s] lemma near phrase: 'γαῖα' near 'ἐϲχάτη χθονόϲ'

msg("SwapPhraseAndLemma() was called", MSGPEEK)

// LemmaBoxSwap - swap 'seeking' and 'proximate' to do a lemma as the second search (in the name of speed)
func (s *SearchStruct) LemmaBoxSwap() {
boxa := s.LemmaOne
boxb := s.Proximate
s.Seeking = boxb
Expand All @@ -354,6 +352,39 @@ func (s *SearchStruct) SwapPhraseAndLemma() {
s.SetType()
}

// SwapPhraseAndLemma - if BoxA has a lemma and BoxB has a phrase, it very likely faster to search B, then A...
func (s *SearchStruct) SwapPhraseAndLemma() {
// we will swap elements and reset the relevant elements of the SearchStruct

// no SwapPhraseAndLemma(): [Δ: 4.564s] lemma near phrase: 'γαῖα' near 'ἐϲχάτη χθονόϲ'
// yes SwapPhraseAndLemma(): [Δ: 1.276s] lemma near phrase: 'γαῖα' near 'ἐϲχάτη χθονόϲ'

const (
CALLED = `SwapPhraseAndLemma() was called: lemmatized '%s' swapped with '%s'`
)

msg(fmt.Sprintf(CALLED, s.LemmaOne, s.Proximate), MSGPEEK)
s.LemmaBoxSwap()
}

// SwapWordAndLemma - if BoxA has a lemma and BoxB has a single word, it very likely faster to search B, then A...
func (s *SearchStruct) SwapWordAndLemma() {
// [swapped]
// Sought »χρηματα« within 1 lines of all 45 forms of »ἄνθρωποϲ«
// Searched 7,461 works and found 298 passages (2.86s)

// [unswapped]
// Sought all 45 forms of »ἄνθρωποϲ« within 1 lines of »χρηματα«
// Searched 7,461 works and found 1 passages (8.89s)

const (
CALLED = `SwapWordAndLemma() was called: lemmatized '%s' swapped with '%s'`
)

msg(fmt.Sprintf(CALLED, s.LemmaOne, s.Proximate), MSGPEEK)
s.LemmaBoxSwap()
}

// SearchQuickestFirst - look for the string with more characters in it first; it will typically generate fewer initial hits
func (s *SearchStruct) SearchQuickestFirst() {
const (
Expand Down

0 comments on commit 4f09691

Please sign in to comment.