func ListEntries(w http.ResponseWriter, r *http.Request) (gbEntries []GbEntryRetr, report string) { c := appengine.NewContext(r) /* High Replication Datastore: Ancestor queries are strongly consistent. Queries spanning MULTIPLE entity groups are EVENTUALLY consistent. If .Ancestor was omitted from this query, there would be slight chance that recent GB entry would not show up in a query. */ q := ds.NewQuery(GbEntryKind).Ancestor(keyParent(c)).Order("-Date").Limit(10) gbEntries = make([]GbEntryRetr, 0, 10) keys, err := q.GetAll(c, &gbEntries) if fmt.Sprintf("%T", err) == fmt.Sprintf("%T", new(ds.ErrFieldMismatch)) { //s := fmt.Sprintf("%v %T vs %v %T <br>\n",err,err,ds.ErrFieldMismatch{},ds.ErrFieldMismatch{}) loghttp.E(w, r, err, true) err = nil // ignore this one - it's caused by our deliberate differences between gbsaveEntry and gbEntrieRetr } loghttp.E(w, r, err, false) // for investigative purposes, // we var b1 bytes.Buffer var sw string var descrip []string = []string{"class", "path", "key_int_guestbk"} for i0, v0 := range keys { sKey := fmt.Sprintf("%v", v0) v1 := strings.Split(sKey, ",") sw = fmt.Sprintf("key %v", i0) b1.WriteString(sw) for i2, v2 := range v1 { d := descrip[i2] sw = fmt.Sprintf(" \t %v: %q ", d, v2) b1.WriteString(sw) } b1.WriteString("\n") } report = b1.String() for _, gbe := range gbEntries { s := gbe.Comment1 if len(s) > 0 { if pos := strings.Index(s, "0300"); pos > 1 { i1 := util.Max(pos-4, 0) i2 := util.Min(pos+24, len(s)) s1 := s[i1:i2] s1 = strings.Replace(s1, "3", "E", -1) report = fmt.Sprintf("%v -%v", report, s1) } } } return }
// FillHeightFloor is the recommended minimal height // of an amorph to fill in. // func (f Fusion) FillHeightFloor() int { if f.xyx == nil || len(f.xyx) < 2 { return cFusionHeightDefault } if f.xyx[1] > 0 { // lower western flank => max of western or middle flank if f.w == nil || len(f.w) < 1 { return cFusionHeightDefault } return util.Max(f.xyx[1], f.w[0]) } else { // lower eastern flank => max of eastern or middle flank if f.e == nil || len(f.e) < 1 { return cFusionHeightDefault } return util.Max(-f.xyx[1], f.e[0]) } }
// mostAbundant seeks the largest slice. // It then returns the first amorph. func mostAbundant(amorphBlocks [][]Amorph) (chosen *Amorph) { maxFound := 0 for i := 0; i < len(amorphBlocks); i++ { maxFound = util.Max(maxFound, len(amorphBlocks[i])) } for i := 0; i < len(amorphBlocks); i++ { if len(amorphBlocks[i]) == maxFound { if len(amorphBlocks[i]) > 0 { return &amorphBlocks[i][0] } } } return nil }
// mostAbundant seeks the largest slice. // It then returns the first amorph. // Should be replaced by abundantHeightMatch() func (dummy MostAbundant) Filter(amorphBlocks [][]Amorph, fs Fusion) (chosen *Amorph) { maxFound := 0 for i := 0; i < len(amorphBlocks); i++ { maxFound = util.Max(maxFound, len(amorphBlocks[i])) } for i := 0; i < len(amorphBlocks); i++ { if len(amorphBlocks[i]) == maxFound { if len(amorphBlocks[i]) > 0 { return &amorphBlocks[i][0] } } } return nil }
func backend3(w http.ResponseWriter, r *http.Request, m map[string]interface{}) { c := appengine.NewContext(r) var nColsBlock = 4 if r.FormValue("nColsBlock") != "" { nColsBlock = util.Stoi(r.FormValue("nColsBlock")) } var nColsViewport = 6 if r.FormValue("nColsViewport") != "" { nColsViewport = util.Stoi(r.FormValue("nColsViewport")) } myB0.VB1 = X myB0.NumB1 = len(myB0.VB1) myB0.NumB2 = 0 myB0.NColsViewport = nColsViewport // compute basic meta data for i1, _ := range myB0.VB1 { myB0.NumB2 += len(myB0.VB1[i1].VB2) for i2, _ := range myB0.VB1[i1].VB2 { // number of chars ro := myB0.VB1[i1].VB2[i2] // read only myB0.VB1[i1].VB2[i2].Size = len(ro.Linktext) + len(ro.Description) myB0.VB1[i1].VB2[i2].EditorialIndex = i2 } } // compute NCols - NRows for the block for i1, _ := range myB0.VB1 { myB0.VB1[i1].NCols = nColsBlock if myB0.VB1[i1].NColsEditorial > 0 { myB0.VB1[i1].NCols = myB0.VB1[i1].NColsEditorial } if len(myB0.VB1[i1].VB2) < nColsBlock && len(myB0.VB1[i1].VB2) > 0 { myB0.VB1[i1].NCols = len(myB0.VB1[i1].VB2) } myB0.VB1[i1].NRows = complementRowsOrCols(len(myB0.VB1[i1].VB2), myB0.VB1[i1].NCols) myB0.VB1[i1].Discrepancy = myB0.VB1[i1].NCols*myB0.VB1[i1].NRows - len(myB0.VB1[i1].VB2) myB0.MaxNCols = util.Max(myB0.MaxNCols, myB0.VB1[i1].NCols) myB0.MaxNRows = util.Max(myB0.MaxNRows, myB0.VB1[i1].NRows) } // compute NCols - NRows - sizeup to MaxNRows for i1, _ := range myB0.VB1 { if myB0.VB1[i1].NRows < myB0.MaxNRows { myB0.VB1[i1].NRows = myB0.MaxNRows myB0.VB1[i1].NCols = complementRowsOrCols(len(myB0.VB1[i1].VB2), myB0.VB1[i1].NRows) myB0.VB1[i1].Discrepancy = myB0.VB1[i1].NCols*myB0.VB1[i1].NRows - len(myB0.VB1[i1].VB2) } } // is first or last for i1, _ := range myB0.VB1 { for i2, _ := range myB0.VB1[i1].VB2 { myB0.VB1[i1].VB2[i2].IsFirst = false myB0.VB1[i1].VB2[i2].IsLast = false if i2%myB0.VB1[i1].NCols == 0 { myB0.VB1[i1].VB2[i2].IsFirst = true } if i2%myB0.VB1[i1].NCols == (myB0.VB1[i1].NCols - 1) { myB0.VB1[i1].VB2[i2].IsLast = true } //aelog.Infof(c,"first-last %v %v \n", i2, i2%myB0.VB1[i1].NCols) } } // create slices with the data to be sorted for i1, _ := range myB0.VB1 { sh1 := make([]Order, len(myB0.VB1[i1].VB2)) myB0.VB1[i1].BySize = ByInt(sh1) sh2 := make([]Order, len(myB0.VB1[i1].VB2)) myB0.VB1[i1].ByHeading = ByStr(sh2) // fill in the data - to be sorted later for i2, _ := range myB0.VB1[i1].VB2 { ro := myB0.VB1[i1].VB2[i2] // read only myB0.VB1[i1].BySize[i2].IdxSrc = i2 myB0.VB1[i1].BySize[i2].ByI = len(ro.Linktext) + len(ro.Description) myB0.VB1[i1].ByHeading[i2].IdxSrc = i2 myB0.VB1[i1].ByHeading[i2].ByS = strings.ToLower(ro.Linktext) } } // actual rearranging of the sorting date for i1, _ := range myB0.VB1 { sort.Sort(myB0.VB1[i1].BySize) sort.Sort(myB0.VB1[i1].ByHeading) aelog.Infof(c, "-- Sorting %v", myB0.VB1[i1].Heading) // for i, v := range myB0.VB1[i1].BySize { // aelog.Infof(c,"---- %v %v %v", i, v.IdxSrc, v.ByI) // } // for i, v := range myB0.VB1[i1].ByHeading { // aelog.Infof(c,"---- %v %v %v", i, v.IdxSrc, v.ByS) // } } path := m["dir"].(string) + m["base"].(string) cntr, _ := sc.Count(c, path) add, tplExec := tplx.FuncTplBuilder(w, r) add("n_html_title", "Backend", nil) add("n_cont_0", "<style>"+htmlfrag.CSSColumnsWidth(nColsViewport)+"</style>", "") add("n_cont_1", tplx.PrefixLff+"backend3_body", myB0) add("tpl_legend", tplx.PrefixLff+"backend3_body_embed01", "") add("n_cont_2", "<p>{{.}} views</p>", cntr) sDumped := "" //sDumped = spew.Sdump(myB0) add("n_cont_3", "<pre>{{.}} </pre>", sDumped) tplExec(w, r) }
// enhanceLine extends the first segment horizontally westwards. // It then adds a fictional vertical. // Finally we add a horizontal margin. // Eastwards we draw a pit down to vprFloor and then go vertically upwards. // Param stillEmpty draws a bottom between the two vertical axis. // // // ---┐ ┌--- // | | // | | // └---------┐ | // XXXX| | // XXXX| | // | | // └-------┘ // func (m *TransposableMatrix) enhanceLine(stillEmpty bool, line []Point, xm1, xm2 int) []Point { if !m.enforceVPR { return line } // mapping vprmx1, vprmy1 := m.transposeBase2Mapped(m.vPRx1, m.vPRy1) vprmx2, vprmy2 := m.transposeBase2Mapped(m.vPRx2, m.vPRy2) var vpr1, vpr2, vprFloor int // effective limits, depending on perspective if m.persp%2 == 1 { vpr1, vpr2 = vprmx1, vprmx2 vprFloor = util.Max(vprmy1, vprmy2) } else { vpr1, vpr2 = vprmy1, vprmy2 vprFloor = util.Max(vprmx1, vprmx2) } if stillEmpty { line = []Point{ Point{vpr1, vprFloor}, Point{vpr2, vprFloor}, } pf("empty outline => artificial floor %v\n", line) xm1 = vpr1 + 1 // so that forthcoming comparisons apply xm2 = vpr2 - 1 } // westward extension if vpr1 < xm1 { if vprFloor == line[0].y { line[0].x = vpr1 // simply prolong } else { // We could step up/down // but then we get gaps. // Thus we only step up/down eastwards line[0].x = vpr1 } // fictitious vertical upward line = append([]Point{Point{}}, line...) line[0].x = line[1].x line[0].y = line[1].y - fictSegLen // fictitious westward horiz segment line = append([]Point{Point{}}, line...) line[0].x = line[1].x - fictSegLen line[0].y = line[1].y } // eastward extension if vpr2 > xm2 { if xm2 == vpr2-1 { // prolong eastwards one more slot lastIdx := len(line) - 1 line[lastIdx].x = vpr2 } else if vprFloor == line[0].y { // prolong eastwards along x-axis lastIdx := len(line) - 1 line[lastIdx].x = vpr2 } else { // make a full pit/bulge to vprFloor: // up/down ... lastIdx := len(line) - 1 line = append(line, Point{}) line[lastIdx+1].x = line[lastIdx].x line[lastIdx+1].y = vprFloor // ... and east lastIdx = len(line) - 1 line = append(line, Point{}) line[lastIdx+1].x = vpr2 line[lastIdx+1].y = line[lastIdx].y } // fictitious vertical upward lastIdx := len(line) - 1 line = append(line, Point{}) line[lastIdx+1].x = line[lastIdx].x line[lastIdx+1].y = line[lastIdx].y - fictSegLen // fictitious eastw horiz lastIdx = len(line) - 1 line = append(line, Point{}) line[lastIdx+1].x = line[lastIdx].x + fictSegLen line[lastIdx+1].y = line[lastIdx].y } // // if vpr1 > xm1 { // todo: cropping existing outline } if xm2 > vpr2 { // todo: cropping existing outline } return line }
// FuseTwoSections takes an outline with all concavest lowest narrowest sections, // and one or two designated section indize out of clns. // So far mostly *one* section is given, while the second is the // computed right neighbor. Rightmost sect is complemented by the left neighbor. // Those designated sections are fused. // Param l => outline // Param clns => concavest, lowest, narrowest sections // sct1 => index to clns for which to find a pair // Returns: Fusion func (ar *Reservoir) FuseTwoSections(l []Point, clns [][]int, sct1 []int) (Fusion, error) { fs := NewFusion() var err error // find the two sections - westward or eastward west, east := findYourNeighbor(clns, sct1) var sct2 []int if sct1[1] == 0 { // only fuse eastw possible if east < 0 { err = epf("NO EASTW NEIGHBOR 1 to %v", sct1) return fs, err } sct2 = clns[east] } else if sct1[1] == len(l)-1 { // only fuse westw possible if west < 0 { err = epf("NO WESTW NEIGHBOR 1 to %v", sct1) return fs, err } sct2 = sct1 sct1 = clns[west] } else { if util.Abs(sct1[3]) > 0 && util.Abs(sct1[3]) < util.Abs(sct1[6]) { // east flank higher than west flank? // => fuse westwards sct2 = sct1 if west < 0 { err = epf("NO WESTW NEIGHBOR 2 to %v", sct1) return fs, err } sct1 = clns[west] } else { // fuse eastwards if east < 0 { err = epf("NO EASTW NEIGHBOR 2 to %v", sct1) return fs, err } sct2 = clns[east] } } // PrintSectOfCLNS(sct1) // PrintSectOfCLNS(sct2) fs.idxL = append(fs.idxL, sct1[0], sct1[1], sct2[0], sct2[1]) fs.xyx = append(fs.xyx, sct1[2], sct1[6], sct2[2]) fs.w = append(fs.w, sct1[3], sct1[4], sct1[5]) fs.e = append(fs.e, sct2[6], sct2[7], sct2[8]) sdgN := ar.SmallestDesirableHeight sdgWE := ar.SmallestDesirableWidth pW, pE, pN := Permissiveness(sdgN, sdgWE, fs.xyx, fs.w, fs.e) fs.pm = []int{pW, pE, pN} // // base point // always bottom left fs.base.x = l[sct1[0]].x // x-coord taken from beginning baseY1 := l[sct1[0]].y // y-coord taken either from beginning baseY2 := l[sct2[1]].y // or taken from end fs.base.y = util.Max(baseY1, baseY2) // take lowest y - meaning Max(), not Min() dyw := sct1[3] // correction for concave angles if dyw > 0 { fs.base.x++ } switch { case fs.pm[0] < 0 && fs.pm[1] < 0: // eastw, westw blocked, concave fs.curveDesc = cncave fs.dirIdx, fs.maxOffs = -1, 0 case fs.pm[0] > 0 && fs.pm[1] < 0: // westwards fs.curveDesc = stairW fs.dirIdx, fs.maxOffs = 0, fs.pm[0] case fs.pm[0] < 0 && fs.pm[1] > 0: // eastwards fs.curveDesc = stairE fs.dirIdx, fs.maxOffs = 1, fs.pm[1] case fs.pm[0] > 0 && fs.pm[1] > 0: // utterly convex fs.curveDesc = convex fs.dirIdx, fs.maxOffs = 1, fs.pm[1] // wanton choice: grow east } lowerX := 0 if fs.xyx[1] < 0 { lowerX = 1 } if lowerX == 0 && fs.w[0] > 0 { fs.concaveCore = true } if lowerX == 1 && fs.e[0] > 0 { fs.concaveCore = true } return fs, nil }
func similarTextifiedTrees2(src *TextifiedTree, mp map[string][]*TextifiedTree, skipPrefix map[string]bool) { // srcE := word.WrapAsEqualer(string(src.Text), true) // ssrc as Equaler srcE := wordb.WrapAsEqualer(src.Text, true) srcLen := float64(len(src.Text)) for fnKey, tts := range mp { if fnKey == src.SourceID { pf(" to %v SKIP self\n", fnKey) continue } pf(" to %v\n", fnKey) cntr, br := 0, true for _, tt := range tts { // outl, text := tt.Outl, tt.Text if tt.Lvl > src.Lvl+levelsTolerance { break // since we are now sorted by lvl, we can this is safe } if tt.Lvl == src.Lvl || (tt.Lvl > src.Lvl && tt.Lvl <= src.Lvl+levelsTolerance) { // proceed } else { continue } if src.NumTokens < 1 { continue } if src.NumTokens < 5 && tt.NumTokens > 7 { continue } if HistoBasedDistance(src, tt) > 0.51 { breakMapsTooDistinct++ continue } relSize := srcLen / float64(util.Max(1, len(tt.Text))) if relSize < 0.33 || relSize > 3 { continue } absDist, relDist := 0, 0.0 if tt.NumTokens == src.NumTokens && len(tt.Text) == len(src.Text) && bytes.Equal(tt.Text, src.Text) { absDist, relDist = 0, 0.0 appliedCompare++ } else { dstE := wordb.WrapAsEqualer(tt.Text, true) // destinations as Equaler m := levenshtein.New(srcE, dstE, opt) absDist, relDist = m.Distance() appliedLevenshtein++ } // if relDist < 0.26 && absDist < 10 { if br { pf("\t") } sd := "" sd = string(tt.Text[:util.Min(2*excerptLen, len(tt.Text)-1)]) sd = stringspb.ToLen(sd, 2*excerptLen+1) pf("%12v %v %4v %5.2v ", tt.Outline, sd, absDist, relDist) cntr++ br = false sim := Similar{} sim.SourceID = fnKey sim.Lvl = tt.Lvl sim.Outline = tt.Outline sim.AbsLevenshtein = absDist sim.RelLevenshtein = relDist sim.Text = tt.Text src.Similars = append(src.Similars, sim) src.SumAbsLevenshtein += absDist src.SumRelLevenshtein += relDist if cntr%2 == 0 || cntr > 20 { pf("\n") br = true } if cntr > 20 { break } } } if !br { pf("\n") } } }