Skip to content

Commit

Permalink
migrate to NotoSansDisplay
Browse files Browse the repository at this point in the history
  • Loading branch information
e-gun committed Jan 20, 2024
1 parent e4d2e2e commit 881c423
Show file tree
Hide file tree
Showing 37 changed files with 85 additions and 53 deletions.
7 changes: 6 additions & 1 deletion configatlaunch.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os"
"runtime"
"strconv"
"strings"
"text/template"
)

Expand Down Expand Up @@ -191,6 +192,8 @@ func ConfigAtLaunch() {
cwd = "(unknown)"
}

kff := StringMapKeysIntoSlice(ServableFonts)

m := map[string]interface{}{
"badchars": Config.BadChars,
"confauth": CONFIGAUTH,
Expand All @@ -210,7 +213,9 @@ func ConfigAtLaunch() {
"port": Config.HostPort,
"projurl": PROJURL,
"vmodel": Config.VectorModel,
"workers": Config.WorkerCount}
"workers": Config.WorkerCount,
"knownfnts": strings.Join(kff, "C0, C3"),
"deffnt": Config.Font}

t := template.Must(template.New("").Parse(HELPTEXTTEMPLATE))

Expand Down
8 changes: 4 additions & 4 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ const (
C1-dvC0 disable semantic vector searching
C1-elC0 C2{num}C0 set echo server log level (C10-3C0) [C6currentC0: C3{{.echoll}}C0]
C1-exC0 extract the data to an archive folder in the same directory as the application; data sent to: "C3{{.cwd}}C0"
C1-ftC0 C2{string}C0 force a client-side font instead of serving a font [C6served font:C0 C3NotoSansC0]
C1-ftC0 C2{string}C0 change the font [C6built-in:C0 C3{{.knownfnts}}C0][C6currentC0: C3{{.deffnt}}C0]
names with spaces need quotes around them: "C4Gentium Plus CompactC0"
C1-glC0 C2{num}C0 set golang log level (C10-5C0) [C6currentC0: C3{{.hgsll}}C0]
C1-gzC0 enable gzip compression of the server's output
C1-hC0 print this help information
C1-mdC0 C2{string}C0 set the default vector model type; available: C3gloveC0, C3lexvecC0, & C3w2vC0 [C6currentC0: C3{{.vmodel}}C0]
C1-mdC0 C2{string}C0 set the default vector model type; available: C3gloveC0, C3lexvecC0, and C3w2vC0 [C6currentC0: C3{{.vmodel}}C0]
C1-miC0 C2{num}C0 maximum number of concurrent searches per IP address [C6currentC0: C3{{.maxipsrch}}C0]
C1-msC0 C2{num}C0 maximum total number of concurrent searches [C6currentC0: C3{{.maxtotscrh}}C0]
C1-pcC0 enable CPU profiling run
Expand All @@ -172,7 +172,7 @@ const (
C1-uiC0 C2{string}C0 unacceptable input characters [C6currentC0: C3{{.badchars}}C0]
C1-vC0 print version info and exit
C1-vvC0 print full version info and exit
C1-wcC0 C2{int}C0 number of workers [C6currentC0: C3{{.workers}}C0][C1cpu_countC0 is C3{{.cpus}}C0]
C1-wcC0 C2{int}C0 number of workers [C1cpu_countC0 is C3{{.cpus}}C0][C6currentC0: C3{{.workers}}C0]
C1-zlC0 zap lunate sigmas and replace them with C1σ/ςC0
C1-00C0 completely erase the database and reset the tables
the application cannot run again until you restore its data from an archive
Expand All @@ -181,7 +181,7 @@ const (
C4"{\"Pass\": \"YOURPASSWORDHERE\" ,\"Host\": \"127.0.0.1\", \"Port\": 5432, \"DBName\": \"hipparchiaDB\" ,\"User\": \"hippa_wr\"}"C0
S1NB:S0 a properly formatted version of "C3{{.conffile}}C0" in "C3{{.home}}C0" configures everything for you.
See 'C3sample_hgs-prolix-conf.jsonC0' as well as other sample configuration files at
See "C3sample_hgs-prolix-conf.jsonC0"" as well as other sample configuration files at
C3{{.projurl}}C0
`
LEXFINDJS = `
Expand Down
8 changes: 4 additions & 4 deletions dbworklines.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ func (wlb *WorkLineBundle) AppendOne(toadd DbWorkline) {
// QUERY FUNCTIONS
//

// WorklineQuery - use a PrerolledQuery to acquire a WorkLineBundle
func WorklineQuery(prq PrerolledQuery, dbconn *pgxpool.Conn) WorkLineBundle {
// SearchForDBWorklines - use a PrerolledQuery to acquire a WorkLineBundle
func SearchForDBWorklines(prq PrerolledQuery, dbconn *pgxpool.Conn) WorkLineBundle {
// NB: you have to use a dbconn.Exec() and can't use SQLPool.Exex() because with the latter the temp table will
// get separated from the main query:
// ERROR: relation "{ttname}" does not exist (SQLSTATE 42P01)
Expand Down Expand Up @@ -336,7 +336,7 @@ func GrabOneLine(table string, line int) DbWorkline {
var prq PrerolledQuery
prq.TempTable = ""
prq.PsqlQuery = fmt.Sprintf(QTMPL, WORLINETEMPLATE, table, line)
foundlines := WorklineQuery(prq, dbconn)
foundlines := SearchForDBWorklines(prq, dbconn)
if foundlines.Len() != 0 {
// "index = %d" in QTMPL ought to mean you can never have len(foundlines) > 1 because index values are unique
return foundlines.FirstLine()
Expand All @@ -361,7 +361,7 @@ func SimpleContextGrabber(table string, focus int, context int) WorkLineBundle {
prq.TempTable = ""
prq.PsqlQuery = fmt.Sprintf(QTMPL, WORLINETEMPLATE, table, low, high)

foundlines := WorklineQuery(prq, dbconn)
foundlines := SearchForDBWorklines(prq, dbconn)

return foundlines
}
13 changes: 8 additions & 5 deletions echoserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,14 @@ func StartEchoServer() {

// JSONresponse - send the JSON; this function lets one test and document different strategies; jsr should be a json-ready struct
func JSONresponse(c echo.Context, jsr any) error {
const (
RESPONDER = 1
)

return c.JSON(http.StatusOK, jsr)

// note that JSONPretty will end up strikingly prominent on the profiler: a waste of memory and cycles unless
// you are debugging and want to be able to inspect the json manually

// [1] "vanilla"; and it turns out there is nothing wrong with vanilla; seems like the best choice
opt1 := func() error { return c.JSON(http.StatusOK, jsr) }
//opt1 := func() error { return c.JSON(http.StatusOK, jsr) }

// [2] "costs a lot of RAM in return for what?"
//opt2 := func() error { return c.JSONPretty(http.StatusOK, jsr, JSONINDENT) }
Expand All @@ -255,6 +254,10 @@ func JSONresponse(c echo.Context, jsr any) error {
// return c.JSONBlob(http.StatusOK, b)
//}

//const (
// RESPONDER = 1
//)
//
//switch RESPONDER {
//case 1:
// return opt1()
Expand All @@ -268,5 +271,5 @@ func JSONresponse(c echo.Context, jsr any) error {
// return opt1()
//}

return opt1()
//return opt1()
}
Binary file removed emb/otf/NotoSans-Bold.otf
Binary file not shown.
Binary file removed emb/otf/NotoSans-BoldItalic.otf
Binary file not shown.
Binary file removed emb/otf/NotoSans-Condensed.otf
Binary file not shown.
Binary file removed emb/otf/NotoSans-CondensedItalic.otf
Binary file not shown.
Binary file removed emb/otf/NotoSans-CondensedSemiBold.otf
Binary file not shown.
Binary file removed emb/otf/NotoSans-ExtraLight.otf
Binary file not shown.
Binary file removed emb/otf/NotoSans-Italic.otf
Binary file not shown.
Binary file removed emb/otf/NotoSans-Regular.otf
Binary file not shown.
Binary file removed emb/otf/NotoSans-SemiBold.otf
Binary file not shown.
Binary file removed emb/otf/NotoSans-SemiCondensed.otf
Binary file not shown.
Binary file removed emb/otf/NotoSans-SemiCondensedItalic.otf
Binary file not shown.
Binary file removed emb/otf/NotoSans-Thin.otf
Binary file not shown.
Binary file removed emb/otf/NotoSansMono-SemiCondensed.otf
Binary file not shown.
Binary file added emb/ttf/NotoSansDisplay-Bold.ttf
Binary file not shown.
Binary file added emb/ttf/NotoSansDisplay-BoldItalic.ttf
Binary file not shown.
Binary file added emb/ttf/NotoSansDisplay-ExtraLight.ttf
Binary file not shown.
Binary file added emb/ttf/NotoSansDisplay-Italic.ttf
Binary file not shown.
Binary file added emb/ttf/NotoSansDisplay-Regular.ttf
Binary file not shown.
Binary file added emb/ttf/NotoSansDisplay-SemiBold.ttf
Binary file not shown.
Binary file added emb/ttf/NotoSansDisplay-Thin.ttf
Binary file not shown.
Binary file added emb/ttf/NotoSansDisplay_Condensed-Italic.ttf
Binary file not shown.
Binary file added emb/ttf/NotoSansDisplay_Condensed-Regular.ttf
Binary file not shown.
Binary file added emb/ttf/NotoSansDisplay_Condensed-SemiBold.ttf
Binary file not shown.
Binary file added emb/ttf/NotoSansDisplay_SemiCondensed-Italic.ttf
Binary file not shown.
Binary file not shown.
Binary file added emb/ttf/NotoSansMono_Condensed-Regular.ttf
Binary file not shown.
File renamed without changes.
2 changes: 1 addition & 1 deletion fyi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ self-test with vectors can be deceptive because `-wc` flag will not override con

## profiling

`HipparchiaGoServer -st -st -st` called to generate
`HipparchiaGoServer -st` called to generate
* `default.pgo`
* `MEMProfile.pdf`
* `CPUProfile.pdf`
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ require (
github.com/go-echarts/go-echarts/v2 v2.3.3
github.com/google/uuid v1.5.0
github.com/gorilla/websocket v1.5.1
github.com/jackc/pgx/v5 v5.5.1
github.com/jackc/pgx/v5 v5.5.2
github.com/labstack/echo/v4 v4.11.4
github.com/pkg/profile v1.7.0
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a
golang.org/x/text v0.14.0
gonum.org/v1/gonum v0.14.0
)
Expand All @@ -22,7 +22,7 @@ require (
github.com/e-gun/sparse v0.0.0-20230418220937-07063da15582 // indirect
github.com/felixge/fgprof v0.9.3 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/google/pprof v0.0.0-20231229205709-960ae82b1e42 // indirect
github.com/google/pprof v0.0.0-20240117000934-35fc243c5815 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect
Expand Down
11 changes: 7 additions & 4 deletions goroutinesearcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// THE MANAGER
//

// SearchAndInsertResults - fan out db queries and collect the results; insert a WorkLineBundle into the SearchStruct
// SearchAndInsertResults - take a SearchStruct; fan out its []PrerolledQuery; collect the results; insert a WorkLineBundle into the SearchStruct
func SearchAndInsertResults(ss *SearchStruct) {
// see https://go.dev/blog/pipelines : see Parallel digestion & Fan-out, fan-in & Explicit cancellation
// https://medium.com/amboss/applying-modern-go-concurrency-patterns-to-data-pipelines-b3b5327908d4
Expand All @@ -24,8 +24,11 @@ func SearchAndInsertResults(ss *SearchStruct) {
// https://pranav93.github.io/blog/golang-fan-inout-pattern/
// https://github.com/luk4z7/go-concurrency-guide

// theoretically possible to yield up the interim results while the search is in progress; but a pain/gain problem
// specifically, two-part searches will always need a lot of fussing... websocket is perhaps the way to go

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
defer cancel() // nobody sends "<-ctx.Done()" as seen below; but this gives you that

emitqueries, err := SrchFeeder(ctx, ss)
chke(err)
Expand Down Expand Up @@ -99,7 +102,7 @@ func SrchConsumer(ctx context.Context, prq <-chan PrerolledQuery) (<-chan WorkLi
case <-ctx.Done():
return
default:
wlb := WorklineQuery(q, dbconn)
wlb := SearchForDBWorklines(q, dbconn)
emitfinds <- wlb
}
}
Expand Down Expand Up @@ -137,7 +140,7 @@ func ResultAggregator(ctx context.Context, findchannels ...<-chan WorkLineBundle
return emitaggregate
}

// ResultCollation - return the actual []DbWorkline results after pulling them from the ResultAggregator channel
// ResultCollation - return the actual WorkLineBundle results after pulling them from the ResultAggregator channel
func ResultCollation(ctx context.Context, ss *SearchStruct, maxhits int, foundbundle <-chan WorkLineBundle) WorkLineBundle {
var collated WorkLineBundle

Expand Down
4 changes: 2 additions & 2 deletions initializeglobals.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var (
WkLocs = make(map[string]bool)
TheCorpora = []string{GREEKCORP, LATINCORP, INSCRIPTCORP, CHRISTINSC, PAPYRUSCORP}
TheLanguages = []string{"greek", "latin"}
ServableFonts = map[string]FontTempl{"Noto": NotoFont, "Roboto": RobotoFont, "Fira": FiraFont}
ServableFonts = map[string]FontTempl{"Noto": NotoFont, "Roboto": RobotoFont, "Fira": FiraFont} // cf rt-embhcss.go
LaunchTime = time.Now()
WebsocketPool = WSFillNewPool()
)
Expand Down Expand Up @@ -211,7 +211,7 @@ func (dbw *DbWork) FindValidLevelValues(locc []string) LevelValues {

dbconn := GetDBConnection()
defer dbconn.Release()
wlb := WorklineQuery(prq, dbconn)
wlb := SearchForDBWorklines(prq, dbconn)

// [c] extract info from the hitlines returned
var vals LevelValues
Expand Down
32 changes: 16 additions & 16 deletions rt-embhcss.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,25 +118,25 @@ type FontTempl struct {
}

// the fonts we know how to serve
// NB: Inter and Ubuntu have been toyed with: Inter lacks both condensed and semi-condensed
// NB: Inter, SourceSans and Ubuntu have been toyed with: Inter lacks both condensed and semi-condensed

var (
NotoFont = FontTempl{
Type: "opentype",
ShrtType: "otf",
Bold: "NotoSans-Bold.otf",
BoldItalic: "NotoSans-BoldItalic.otf",
CondensedBold: "NotoSans-CondensedSemiBold.otf",
CondensedItalic: "NotoSans-CondensedItalic.otf",
CondensedRegular: "NotoSans-Condensed.otf",
SemiCondRegular: "NotoSans-SemiCondensed.otf",
SemiCondItalic: "NotoSans-SemiCondensedItalic.otf",
Italic: "NotoSans-Italic.otf",
Light: "NotoSans-ExtraLight.otf",
Mono: "NotoSansMono-SemiCondensed.otf",
Regular: "NotoSans-Regular.otf",
SemiBold: "NotoSans-SemiBold.otf",
Thin: "NotoSans-Thin.otf",
Type: "truetype",
ShrtType: "ttf",
Bold: "NotoSansDisplay-Bold.ttf",
BoldItalic: "NotoSansDisplay-BoldItalic.ttf",
CondensedBold: "NotoSansDisplay_Condensed-SemiBold.ttf",
CondensedItalic: "NotoSansDisplay_Condensed-Italic.ttf",
CondensedRegular: "NotoSansDisplay_Condensed-Regular.ttf",
SemiCondRegular: "NotoSansDisplay_SemiCondensed-Regular.ttf",
SemiCondItalic: "NotoSansDisplay_SemiCondensed-Italic.ttf",
Italic: "NotoSansDisplay-Italic.ttf",
Light: "NotoSansDisplay-ExtraLight.ttf",
Mono: "NotoSansMono_Condensed-Regular.ttf",
Regular: "NotoSansDisplay-Regular.ttf",
SemiBold: "NotoSansDisplay-SemiBold.ttf",
Thin: "NotoSansDisplay-Thin.ttf",
}
FiraFont = FontTempl{
Type: "truetype",
Expand Down
47 changes: 34 additions & 13 deletions searchformatting.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ const (

// FormatNoContextResults - build zero context search results table
func FormatNoContextResults(ss *SearchStruct) SearchOutputJSON {
// EXAMPLE
// <tr class="nthrow">
// <td>
// <span class="findnumber">[3]</span>&nbsp;
// <span class="foundauthor">Theophilus</span>,&nbsp; <span class="foundwork">Ad Autolycum</span>: <browser id="index/gr1725/001/3"><span class="foundlocus">1.1.2</span></browser> <br>
// </td>
// <td class="leftpad">
// <span class="foundtext">ἔπαινον πρὸϲ κενὴν δόξαν ἀθλίοιϲ ἀνθρώποιϲ ἔχουϲι τὸν νοῦν κατε-</span>
// </td>
// </tr>

const (
TABLEROW = `
<tr class="{{.TRClass}}">
Expand Down Expand Up @@ -134,12 +145,19 @@ type ResultPassageLine struct {
IsHighlight bool
}

// FormatWithContextResults - build n-lines of context search results table
// FormatWithContextResults - build n-lines of context search results as a list
func FormatWithContextResults(thesearch *SearchStruct) SearchOutputJSON {
// profiling will show that the bulk of your time is spent on (in descending order):
// lemmaintoregexslice(), regexp.Compile(strings.Join(re, "|")), and highlightsearchterm()
// the cost is not outlandish, but regex is fairly expensive

// EXAMPLE:
// <locus>
// <span class="findnumber">[1]</span>&nbsp;
// <span class="foundauthor">Caelius, Marcus Rufus</span>,&nbsp;<span class="foundwork">orationes</span>
// <browser id="index/lt0444/002/1"><span class="foundlocus">17.t</span></browser>
// </locus>

const (
FINDTEMPL = `
<locus>
Expand Down Expand Up @@ -624,12 +642,12 @@ func gethighlighter(ss *SearchStruct) *regexp.Regexp {
// "s", "sp", "spa", ... will mean html gets highlighting: `<span class="xyz" ...>`
// there has to be a more clever way to do this...
const (
FAILRE = "MATCH_NOTHING"
SKIP1 = "^s$|^sp$|^spa$|^span$|^hmu$"
SKIP2 = "|^c$|^cl$|^cla$|^clas$|^class$"
SKIP3 = "|^a$|^as$|^ass$"
SKIP4 = "|^l$|^la$|^lat$|^lati$|^latin$"
SKIP = SKIP1 + SKIP2 + SKIP3 + SKIP4
FAILURE = "MATCH_NOTHING"
SKIP1 = "^s$|^sp$|^spa$|^span$|^hmu$"
SKIP2 = "|^c$|^cl$|^cla$|^clas$|^class$"
SKIP3 = "|^a$|^as$|^ass$"
SKIP4 = "|^l$|^la$|^lat$|^lati$|^latin$"
SKIP = SKIP1 + SKIP2 + SKIP3 + SKIP4
)

var re *regexp.Regexp
Expand All @@ -639,7 +657,7 @@ func gethighlighter(ss *SearchStruct) *regexp.Regexp {

skip := regexp.MustCompile(SKIP)
if skip.MatchString(skg) || skip.MatchString(prx) {
return regexp.MustCompile(FAILRE)
return regexp.MustCompile(FAILURE)
}

if ss.SkgRewritten {
Expand All @@ -662,7 +680,7 @@ func gethighlighter(ss *SearchStruct) *regexp.Regexp {
} else {
// FAIL = "gethighlighter() cannot find anything to highlight\n\t%ss"
// msg(fmt.Sprintf(FAIL, ss.InitSum), MSGFYI)
re = regexp.MustCompile(FAILRE)
re = regexp.MustCompile(FAILURE)
}
return re
}
Expand All @@ -679,10 +697,11 @@ func lemmahighlighter(lm string) *regexp.Regexp {
// tp := `[\^\s;]%s[\s\.,;·’$]`

const (
FAIL = "lemmahighlighter() could not compile lemma into regex"
JOINER = ")✃✃✃("
SNIP = "✃✃✃"
TP = `%s` // move from match $1 to $0 in highlightsearchterm() yielded this shift...
FAIL = "lemmahighlighter() could not compile lemma into regex"
FAILURE = "MATCH_NOTHING"
JOINER = ")✃✃✃("
SNIP = "✃✃✃"
TP = `%s` // move from match $1 to $0 in highlightsearchterm() yielded this shift...
)

lemm := AllLemm[lm].Deriv
Expand All @@ -698,6 +717,8 @@ func lemmahighlighter(lm string) *regexp.Regexp {
r, e := regexp.Compile(rec)
if e != nil {
msg(FAIL, MSGFYI)
} else {
return regexp.MustCompile(FAILURE)
}
return r
}

0 comments on commit 881c423

Please sign in to comment.