_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3 values | text stringlengths 52 85.5k | language stringclasses 1 value | meta_information dict |
|---|---|---|---|---|---|
q180100 | getV3Filter | test | func getV3Filter(code []byte) (v3Filter, error) {
// check if filter is a known standard filter
c := crc32.ChecksumIEEE(code)
for _, f := range standardV3Filters {
if f.crc == c && f.len == len(code) {
return f.f, nil
}
}
// create new vm filter
f := new(vmFilter)
r := newRarBitReader(bytes.NewReader(code[1:])) // skip first xor byte check
// read static data
n, err := r.readBits(1)
if err != nil {
return nil, err
}
if n > 0 {
m, err := r.readUint32()
if err != nil {
return nil, err
}
f.static = make([]byte, m+1)
err = r.readFull(f.static)
if err != nil {
return nil, err
}
}
f.code, err = readCommands(r)
if err == io.EOF {
err = nil
}
return f.execute, err
} | go | {
"resource": ""
} |
q180101 | init | test | func (d *decoder29) init(r io.ByteReader, reset bool) error {
if d.br == nil {
d.br = newRarBitReader(r)
} else {
d.br.reset(r)
}
d.eof = false
if reset {
d.initFilters()
d.lz.reset()
d.ppm.reset()
d.decode = nil
}
if d.decode == nil {
return d.readBlockHeader()
}
return nil
} | go | {
"resource": ""
} |
q180102 | readBlockHeader | test | func (d *decoder29) readBlockHeader() error {
d.br.alignByte()
n, err := d.br.readBits(1)
if err == nil {
if n > 0 {
d.decode = d.ppm.decode
err = d.ppm.init(d.br)
} else {
d.decode = d.lz.decode
err = d.lz.init(d.br)
}
}
if err == io.EOF {
err = errDecoderOutOfData
}
return err
} | go | {
"resource": ""
} |
q180103 | readCodeLengthTable | test | func readCodeLengthTable(br bitReader, codeLength []byte, addOld bool) error {
var bitlength [20]byte
for i := 0; i < len(bitlength); i++ {
n, err := br.readBits(4)
if err != nil {
return err
}
if n == 0xf {
cnt, err := br.readBits(4)
if err != nil {
return err
}
if cnt > 0 {
// array already zero'd dont need to explicitly set
i += cnt + 1
continue
}
}
bitlength[i] = byte(n)
}
var bl huffmanDecoder
bl.init(bitlength[:])
for i := 0; i < len(codeLength); i++ {
l, err := bl.readSym(br)
if err != nil {
return err
}
if l < 16 {
if addOld {
codeLength[i] = (codeLength[i] + byte(l)) & 0xf
} else {
codeLength[i] = byte(l)
}
continue
}
var count int
var value byte
switch l {
case 16, 18:
count, err = br.readBits(3)
count += 3
default:
count, err = br.readBits(7)
count += 11
}
if err != nil {
return err
}
if l < 18 {
if i == 0 {
return errInvalidLengthTable
}
value = codeLength[i-1]
}
for ; count > 0 && i < len(codeLength); i++ {
codeLength[i] = value
count--
}
i--
}
return nil
} | go | {
"resource": ""
} |
q180104 | shrinkStates | test | func (c *context) shrinkStates(states []state, size int) []state {
i1 := units2Index[(len(states)+1)>>1]
i2 := units2Index[(size+1)>>1]
if size == 1 {
// store state in context, and free states block
n := c.statesIndex()
c.s[1] = states[0]
states = c.s[1:]
c.a.addFreeBlock(n, i1)
} else if i1 != i2 {
if n := c.a.removeFreeBlock(i2); n > 0 {
// allocate new block and copy
copy(c.a.states[n:], states[:size])
states = c.a.states[n:]
// free old block
c.a.addFreeBlock(c.statesIndex(), i1)
c.setStatesIndex(n)
} else {
// split current block, and free units not needed
n = c.statesIndex() + index2Units[i2]<<1
u := index2Units[i1] - index2Units[i2]
c.a.freeUnits(n, u)
}
}
c.setNumStates(size)
return states[:size]
} | go | {
"resource": ""
} |
q180105 | expandStates | test | func (c *context) expandStates() []state {
states := c.states()
ns := len(states)
if ns == 1 {
s := states[0]
n := c.a.allocUnits(1)
if n == 0 {
return nil
}
c.setStatesIndex(n)
states = c.a.states[n:]
states[0] = s
} else if ns&0x1 == 0 {
u := ns >> 1
i1 := units2Index[u]
i2 := units2Index[u+1]
if i1 != i2 {
n := c.a.allocUnits(i2)
if n == 0 {
return nil
}
copy(c.a.states[n:], states)
c.a.addFreeBlock(c.statesIndex(), i1)
c.setStatesIndex(n)
states = c.a.states[n:]
}
}
c.setNumStates(ns + 1)
return states[:ns+1]
} | go | {
"resource": ""
} |
q180106 | pushByte | test | func (a *subAllocator) pushByte(c byte) int32 {
si := a.heap1Lo / 6 // state index
oi := a.heap1Lo % 6 // byte position in state
switch oi {
case 0:
a.states[si].sym = c
case 1:
a.states[si].freq = c
default:
n := (uint(oi) - 2) * 8
mask := ^(uint32(0xFF) << n)
succ := uint32(a.states[si].succ) & mask
succ |= uint32(c) << n
a.states[si].succ = int32(succ)
}
a.heap1Lo++
if a.heap1Lo >= a.heap1Hi {
return 0
}
return -a.heap1Lo
} | go | {
"resource": ""
} |
q180107 | succByte | test | func (a *subAllocator) succByte(i int32) byte {
i = -i
si := i / 6
oi := i % 6
switch oi {
case 0:
return a.states[si].sym
case 1:
return a.states[si].freq
default:
n := (uint(oi) - 2) * 8
succ := uint32(a.states[si].succ) >> n
return byte(succ & 0xff)
}
} | go | {
"resource": ""
} |
q180108 | succContext | test | func (a *subAllocator) succContext(i int32) *context {
if i <= 0 {
return nil
}
return &context{i: i, s: a.states[i : i+2 : i+2], a: a}
} | go | {
"resource": ""
} |
q180109 | calcAes30Params | test | func calcAes30Params(pass []uint16, salt []byte) (key, iv []byte) {
p := make([]byte, 0, len(pass)*2+len(salt))
for _, v := range pass {
p = append(p, byte(v), byte(v>>8))
}
p = append(p, salt...)
hash := sha1.New()
iv = make([]byte, 16)
s := make([]byte, 0, hash.Size())
for i := 0; i < hashRounds; i++ {
hash.Write(p)
hash.Write([]byte{byte(i), byte(i >> 8), byte(i >> 16)})
if i%(hashRounds/16) == 0 {
s = hash.Sum(s[:0])
iv[i/(hashRounds/16)] = s[4*4+3]
}
}
key = hash.Sum(s[:0])
key = key[:16]
for k := key; len(k) >= 4; k = k[4:] {
k[0], k[1], k[2], k[3] = k[3], k[2], k[1], k[0]
}
return key, iv
} | go | {
"resource": ""
} |
q180110 | parseDosTime | test | func parseDosTime(t uint32) time.Time {
n := int(t)
sec := n & 0x1f << 1
min := n >> 5 & 0x3f
hr := n >> 11 & 0x1f
day := n >> 16 & 0x1f
mon := time.Month(n >> 21 & 0x0f)
yr := n>>25&0x7f + 1980
return time.Date(yr, mon, day, hr, min, sec, 0, time.Local)
} | go | {
"resource": ""
} |
q180111 | decodeName | test | func decodeName(buf []byte) string {
i := bytes.IndexByte(buf, 0)
if i < 0 {
return string(buf) // filename is UTF-8
}
name := buf[:i]
encName := readBuf(buf[i+1:])
if len(encName) < 2 {
return "" // invalid encoding
}
highByte := uint16(encName.byte()) << 8
flags := encName.byte()
flagBits := 8
var wchars []uint16 // decoded characters are UTF-16
for len(wchars) < len(name) && len(encName) > 0 {
if flagBits == 0 {
flags = encName.byte()
flagBits = 8
if len(encName) == 0 {
break
}
}
switch flags >> 6 {
case 0:
wchars = append(wchars, uint16(encName.byte()))
case 1:
wchars = append(wchars, uint16(encName.byte())|highByte)
case 2:
if len(encName) < 2 {
break
}
wchars = append(wchars, encName.uint16())
case 3:
n := encName.byte()
b := name[len(wchars):]
if l := int(n&0x7f) + 2; l < len(b) {
b = b[:l]
}
if n&0x80 > 0 {
if len(encName) < 1 {
break
}
ec := encName.byte()
for _, c := range b {
wchars = append(wchars, uint16(c+ec)|highByte)
}
} else {
for _, c := range b {
wchars = append(wchars, uint16(c))
}
}
}
flags <<= 2
flagBits -= 2
}
return string(utf16.Decode(wchars))
} | go | {
"resource": ""
} |
q180112 | readExtTimes | test | func readExtTimes(f *fileBlockHeader, b *readBuf) {
if len(*b) < 2 {
return // invalid, not enough data
}
flags := b.uint16()
ts := []*time.Time{&f.ModificationTime, &f.CreationTime, &f.AccessTime}
for i, t := range ts {
n := flags >> uint((3-i)*4)
if n&0x8 == 0 {
continue
}
if i != 0 { // ModificationTime already read so skip
if len(*b) < 4 {
return // invalid, not enough data
}
*t = parseDosTime(b.uint32())
}
if n&0x4 > 0 {
*t = t.Add(time.Second)
}
n &= 0x3
if n == 0 {
continue
}
if len(*b) < int(n) {
return // invalid, not enough data
}
// add extra time data in 100's of nanoseconds
d := time.Duration(0)
for j := 3 - n; j < n; j++ {
d |= time.Duration(b.byte()) << (j * 8)
}
d *= 100
*t = t.Add(d)
}
} | go | {
"resource": ""
} |
q180113 | readBlockHeader | test | func (a *archive15) readBlockHeader() (*blockHeader15, error) {
var err error
b := a.buf[:7]
r := io.Reader(a.v)
if a.encrypted {
salt := a.buf[:saltSize]
_, err = io.ReadFull(r, salt)
if err != nil {
return nil, err
}
key, iv := a.getKeys(salt)
r = newAesDecryptReader(r, key, iv)
err = readFull(r, b)
} else {
_, err = io.ReadFull(r, b)
}
if err != nil {
return nil, err
}
crc := b.uint16()
hash := crc32.NewIEEE()
hash.Write(b)
h := new(blockHeader15)
h.htype = b.byte()
h.flags = b.uint16()
size := b.uint16()
if size < 7 {
return nil, errCorruptHeader
}
size -= 7
if int(size) > cap(a.buf) {
a.buf = readBuf(make([]byte, size))
}
h.data = a.buf[:size]
if err := readFull(r, h.data); err != nil {
return nil, err
}
hash.Write(h.data)
if crc != uint16(hash.Sum32()) {
return nil, errBadHeaderCrc
}
if h.flags&blockHasData > 0 {
if len(h.data) < 4 {
return nil, errCorruptHeader
}
h.dataSize = int64(h.data.uint32())
}
if (h.htype == blockService || h.htype == blockFile) && h.flags&fileLargeData > 0 {
if len(h.data) < 25 {
return nil, errCorruptHeader
}
b := h.data[21:25]
h.dataSize |= int64(b.uint32()) << 32
}
return h, nil
} | go | {
"resource": ""
} |
q180114 | newArchive15 | test | func newArchive15(r *bufio.Reader, password string) fileBlockReader {
a := new(archive15)
a.v = r
a.pass = utf16.Encode([]rune(password)) // convert to UTF-16
a.checksum.Hash32 = crc32.NewIEEE()
a.buf = readBuf(make([]byte, 100))
return a
} | go | {
"resource": ""
} |
q180115 | readFilter5Data | test | func readFilter5Data(br bitReader) (int, error) {
// TODO: should data really be uint? (for 32bit ints).
// It will be masked later anyway by decode window mask.
bytes, err := br.readBits(2)
if err != nil {
return 0, err
}
bytes++
var data int
for i := 0; i < bytes; i++ {
n, err := br.readBits(8)
if err != nil {
return 0, err
}
data |= n << (uint(i) * 8)
}
return data, nil
} | go | {
"resource": ""
} |
q180116 | writeByte | test | func (w *window) writeByte(c byte) {
w.buf[w.w] = c
w.w = (w.w + 1) & w.mask
} | go | {
"resource": ""
} |
q180117 | copyBytes | test | func (w *window) copyBytes(len, off int) {
len &= w.mask
n := w.available()
if len > n {
// if there is not enough space availaible we copy
// as much as we can and save the offset and length
// of the remaining data to be copied later.
w.l = len - n
w.o = off
len = n
}
i := (w.w - off) & w.mask
for ; len > 0; len-- {
w.buf[w.w] = w.buf[i]
w.w = (w.w + 1) & w.mask
i = (i + 1) & w.mask
}
} | go | {
"resource": ""
} |
q180118 | read | test | func (w *window) read(p []byte) (n int) {
if w.r > w.w {
n = copy(p, w.buf[w.r:])
w.r = (w.r + n) & w.mask
p = p[n:]
}
if w.r < w.w {
l := copy(p, w.buf[w.r:w.w])
w.r += l
n += l
}
if w.l > 0 && n > 0 {
// if we have successfully read data, copy any
// leftover data from a previous copyBytes.
l := w.l
w.l = 0
w.copyBytes(l, w.o)
}
return n
} | go | {
"resource": ""
} |
q180119 | queueFilter | test | func (d *decodeReader) queueFilter(f *filterBlock) error {
if f.reset {
d.filters = nil
}
if len(d.filters) >= maxQueuedFilters {
return errTooManyFilters
}
// offset & length must be < window size
f.offset &= d.win.mask
f.length &= d.win.mask
// make offset relative to previous filter in list
for _, fb := range d.filters {
if f.offset < fb.offset {
// filter block must not start before previous filter
return errInvalidFilter
}
f.offset -= fb.offset
}
d.filters = append(d.filters, f)
return nil
} | go | {
"resource": ""
} |
q180120 | processFilters | test | func (d *decodeReader) processFilters() (err error) {
f := d.filters[0]
if f.offset > 0 {
return nil
}
d.filters = d.filters[1:]
if d.win.buffered() < f.length {
// fill() didn't return enough bytes
err = d.readErr()
if err == nil || err == io.EOF {
return errInvalidFilter
}
return err
}
if cap(d.buf) < f.length {
d.buf = make([]byte, f.length)
}
d.outbuf = d.buf[:f.length]
n := d.win.read(d.outbuf)
for {
// run filter passing buffer and total bytes read so far
d.outbuf, err = f.filter(d.outbuf, d.tot)
if err != nil {
return err
}
if cap(d.outbuf) > cap(d.buf) {
// Filter returned a bigger buffer, save it for future filters.
d.buf = d.outbuf
}
if len(d.filters) == 0 {
return nil
}
f = d.filters[0]
if f.offset != 0 {
// next filter not at current offset
f.offset -= n
return nil
}
if f.length != len(d.outbuf) {
return errInvalidFilter
}
d.filters = d.filters[1:]
if cap(d.outbuf) < cap(d.buf) {
// Filter returned a smaller buffer. Copy it back to the saved buffer
// so the next filter can make use of the larger buffer if needed.
d.outbuf = append(d.buf[:0], d.outbuf...)
}
}
} | go | {
"resource": ""
} |
q180121 | fill | test | func (d *decodeReader) fill() {
if d.err != nil {
return
}
var fl []*filterBlock
fl, d.err = d.dec.fill(&d.win) // fill window using decoder
for _, f := range fl {
err := d.queueFilter(f)
if err != nil {
d.err = err
return
}
}
} | go | {
"resource": ""
} |
q180122 | Read | test | func (d *decodeReader) Read(p []byte) (n int, err error) {
if len(d.outbuf) == 0 {
// no filter output, see if we need to create more
if d.win.buffered() == 0 {
// fill empty window
d.fill()
if d.win.buffered() == 0 {
return 0, d.readErr()
}
} else if len(d.filters) > 0 {
f := d.filters[0]
if f.offset == 0 && f.length > d.win.buffered() {
d.fill() // filter at current offset needs more data
}
}
if len(d.filters) > 0 {
if err := d.processFilters(); err != nil {
return 0, err
}
}
}
if len(d.outbuf) > 0 {
// copy filter output into p
n = copy(p, d.outbuf)
d.outbuf = d.outbuf[n:]
} else if len(d.filters) > 0 {
f := d.filters[0]
if f.offset < len(p) {
// only read data up to beginning of next filter
p = p[:f.offset]
}
n = d.win.read(p) // read directly from window
f.offset -= n // adjust first filter offset by bytes just read
} else {
n = d.win.read(p) // read directly from window
}
d.tot += int64(n)
return n, nil
} | go | {
"resource": ""
} |
q180123 | readFull | test | func readFull(r io.Reader, buf []byte) error {
_, err := io.ReadFull(r, buf)
if err == io.EOF {
return io.ErrUnexpectedEOF
}
return err
} | go | {
"resource": ""
} |
q180124 | findSig | test | func findSig(br *bufio.Reader) (int, error) {
for n := 0; n <= maxSfxSize; {
b, err := br.ReadSlice(sigPrefix[0])
n += len(b)
if err == bufio.ErrBufferFull {
continue
} else if err != nil {
if err == io.EOF {
err = errNoSig
}
return 0, err
}
b, err = br.Peek(len(sigPrefix[1:]) + 2)
if err != nil {
if err == io.EOF {
err = errNoSig
}
return 0, err
}
if !bytes.HasPrefix(b, []byte(sigPrefix[1:])) {
continue
}
b = b[len(sigPrefix)-1:]
var ver int
switch {
case b[0] == 0:
ver = fileFmt15
case b[0] == 1 && b[1] == 0:
ver = fileFmt50
default:
continue
}
_, _ = br.ReadSlice('\x00')
return ver, nil
}
return 0, errNoSig
} | go | {
"resource": ""
} |
q180125 | execute | test | func (v *vm) execute(cmd []command) {
v.ip = 0 // reset instruction pointer
for n := 0; n < maxCommands; n++ {
ip := v.ip
if ip >= uint32(len(cmd)) {
return
}
ins := cmd[ip]
ins.f(v, ins.bm, ins.op) // run cpu instruction
if v.ipMod {
// command modified ip, don't increment
v.ipMod = false
} else {
v.ip++ // increment ip for next command
}
}
} | go | {
"resource": ""
} |
q180126 | newVM | test | func newVM(mem []byte) *vm {
v := new(vm)
if cap(mem) < vmSize+4 {
v.m = make([]byte, vmSize+4)
copy(v.m, mem)
} else {
v.m = mem[:vmSize+4]
for i := len(mem); i < len(v.m); i++ {
v.m[i] = 0
}
}
v.r[7] = vmSize
return v
} | go | {
"resource": ""
} |
q180127 | limitBitReader | test | func limitBitReader(br bitReader, n int, err error) bitReader {
return &limitedBitReader{br, n, err}
} | go | {
"resource": ""
} |
q180128 | readUint32 | test | func (r *rarBitReader) readUint32() (uint32, error) {
n, err := r.readBits(2)
if err != nil {
return 0, err
}
if n != 1 {
n, err = r.readBits(4 << uint(n))
return uint32(n), err
}
n, err = r.readBits(4)
if err != nil {
return 0, err
}
if n == 0 {
n, err = r.readBits(8)
n |= -1 << 8
return uint32(n), err
}
nlow, err := r.readBits(4)
n = n<<4 | nlow
return uint32(n), err
} | go | {
"resource": ""
} |
q180129 | step3 | test | func step3(word *snowballword.SnowballWord) bool {
// Search for a DERIVATIONAL ending in R2 (i.e. the entire
// ending must lie in R2), and if one is found, remove it.
suffix, _ := word.RemoveFirstSuffixIn(word.R2start, "ост", "ость")
if suffix != "" {
return true
}
return false
} | go | {
"resource": ""
} |
q180130 | Stem | test | func Stem(word string, stemStopwWords bool) string {
word = strings.ToLower(strings.TrimSpace(word))
// Return small words and stop words
if len(word) <= 2 || (stemStopwWords == false && isStopWord(word)) {
return word
}
// Return special words immediately
if specialVersion := stemSpecialWord(word); specialVersion != "" {
word = specialVersion
return word
}
w := snowballword.New(word)
// Stem the word. Note, each of these
// steps will alter `w` in place.
//
preprocess(w)
step0(w)
step1a(w)
step1b(w)
step1c(w)
step2(w)
step3(w)
step4(w)
step5(w)
postprocess(w)
return w.String()
} | go | {
"resource": ""
} |
q180131 | step6 | test | func step6(word *snowballword.SnowballWord) bool {
// If the words ends é or è (unicode code points 233 and 232)
// followed by at least one non-vowel, remove the accent from the e.
// Note, this step is oddly articulated on Porter's Snowball website:
// http://snowball.tartarus.org/algorithms/french/stemmer.html
// More clearly stated, we should replace é or è with e in the
// case where the suffix of the word is é or è followed by
// one-or-more non-vowels.
numNonVowels := 0
for i := len(word.RS) - 1; i >= 0; i-- {
r := word.RS[i]
if isLowerVowel(r) == false {
numNonVowels += 1
} else {
// `r` is a vowel
if (r == 233 || r == 232) && numNonVowels > 0 {
// Replace with "e", or unicode code point 101
word.RS[i] = 101
return true
}
return false
}
}
return false
} | go | {
"resource": ""
} |
q180132 | step5 | test | func step5(word *snowballword.SnowballWord) bool {
suffix, _ := word.FirstSuffix("enn", "onn", "ett", "ell", "eill")
if suffix != "" {
word.RemoveLastNRunes(1)
}
return false
} | go | {
"resource": ""
} |
q180133 | step2a | test | func step2a(word *snowballword.SnowballWord) bool {
suffix, suffixRunes := word.FirstSuffixIn(word.RVstart, len(word.RS), "ya", "ye", "yan", "yen", "yeron", "yendo", "yo", "yó", "yas", "yes", "yais", "yamos")
if suffix != "" {
idx := len(word.RS) - len(suffixRunes) - 1
if idx >= 0 && word.RS[idx] == 117 {
word.RemoveLastNRunes(len(suffixRunes))
return true
}
}
return false
} | go | {
"resource": ""
} |
q180134 | step4 | test | func step4(word *snowballword.SnowballWord) bool {
// (1) Undouble "н", or, 2) if the word ends with a SUPERLATIVE ending,
// (remove it and undouble н n), or 3) if the word ends ь (') (soft sign)
// remove it.
// Undouble "н"
if word.HasSuffixRunes([]rune("нн")) {
word.RemoveLastNRunes(1)
return true
}
// Remove superlative endings
suffix, _ := word.RemoveFirstSuffix("ейше", "ейш")
if suffix != "" {
// Undouble "н"
if word.HasSuffixRunes([]rune("нн")) {
word.RemoveLastNRunes(1)
}
return true
}
// Remove soft sign
if rsLen := len(word.RS); rsLen > 0 && word.RS[rsLen-1] == 'ь' {
word.RemoveLastNRunes(1)
return true
}
return false
} | go | {
"resource": ""
} |
q180135 | Stem | test | func Stem(word, language string, stemStopWords bool) (stemmed string, err error) {
var f func(string, bool) string
switch language {
case "english":
f = english.Stem
case "spanish":
f = spanish.Stem
case "french":
f = french.Stem
case "russian":
f = russian.Stem
case "swedish":
f = swedish.Stem
case "norwegian":
f = norwegian.Stem
default:
err = fmt.Errorf("Unknown language: %s", language)
return
}
stemmed = f(word, stemStopWords)
return
} | go | {
"resource": ""
} |
q180136 | step1c | test | func step1c(w *snowballword.SnowballWord) bool {
rsLen := len(w.RS)
// Replace suffix y or Y by i if preceded by a non-vowel which is not
// the first letter of the word (so cry -> cri, by -> by, say -> say)
//
// Note: the unicode code points for
// y, Y, & i are 121, 89, & 105 respectively.
//
if len(w.RS) > 2 && (w.RS[rsLen-1] == 121 || w.RS[rsLen-1] == 89) && !isLowerVowel(w.RS[rsLen-2]) {
w.RS[rsLen-1] = 105
return true
}
return false
} | go | {
"resource": ""
} |
q180137 | step3 | test | func step3(w *snowballword.SnowballWord) bool {
suffix, suffixRunes := w.FirstSuffix(
"ational", "tional", "alize", "icate", "ative",
"iciti", "ical", "ful", "ness",
)
// If it is not in R1, do nothing
if suffix == "" || len(suffixRunes) > len(w.RS)-w.R1start {
return false
}
// Handle special cases where we're not just going to
// replace the suffix with another suffix: there are
// other things we need to do.
//
if suffix == "ative" {
// If in R2, delete.
//
if len(w.RS)-w.R2start >= 5 {
w.RemoveLastNRunes(len(suffixRunes))
return true
}
return false
}
// Handle a suffix that was found, which is going
// to be replaced with a different suffix.
//
var repl string
switch suffix {
case "ational":
repl = "ate"
case "tional":
repl = "tion"
case "alize":
repl = "al"
case "icate", "iciti", "ical":
repl = "ic"
case "ful", "ness":
repl = ""
}
w.ReplaceSuffixRunes(suffixRunes, []rune(repl), true)
return true
} | go | {
"resource": ""
} |
q180138 | isStopWord | test | func isStopWord(word string) bool {
switch word {
case "au", "aux", "avec", "ce", "ces", "dans", "de", "des", "du",
"elle", "en", "et", "eux", "il", "je", "la", "le", "leur",
"lui", "ma", "mais", "me", "même", "mes", "moi", "mon", "ne",
"nos", "notre", "nous", "on", "ou", "par", "pas", "pour", "qu",
"que", "qui", "sa", "se", "ses", "son", "sur", "ta", "te",
"tes", "toi", "ton", "tu", "un", "une", "vos", "votre", "vous",
"c", "d", "j", "l", "à", "m", "n", "s", "t", "y", "été",
"étée", "étées", "étés", "étant", "étante", "étants", "étantes",
"suis", "es", "est", "sommes", "êtes", "sont", "serai",
"seras", "sera", "serons", "serez", "seront", "serais",
"serait", "serions", "seriez", "seraient", "étais", "était",
"étions", "étiez", "étaient", "fus", "fut", "fûmes", "fûtes",
"furent", "sois", "soit", "soyons", "soyez", "soient", "fusse",
"fusses", "fût", "fussions", "fussiez", "fussent", "ayant",
"ayante", "ayantes", "ayants", "eu", "eue", "eues", "eus",
"ai", "as", "avons", "avez", "ont", "aurai", "auras", "aura",
"aurons", "aurez", "auront", "aurais", "aurait", "aurions",
"auriez", "auraient", "avais", "avait", "avions", "aviez",
"avaient", "eut", "eûmes", "eûtes", "eurent", "aie", "aies",
"ait", "ayons", "ayez", "aient", "eusse", "eusses", "eût",
"eussions", "eussiez", "eussent":
return true
}
return false
} | go | {
"resource": ""
} |
q180139 | capitalizeYUI | test | func capitalizeYUI(word *snowballword.SnowballWord) {
// Keep track of vowels that we see
vowelPreviously := false
// Peak ahead to see if the next rune is a vowel
vowelNext := func(j int) bool {
return (j+1 < len(word.RS) && isLowerVowel(word.RS[j+1]))
}
// Look at all runes
for i := 0; i < len(word.RS); i++ {
// Nothing to do for non-vowels
if isLowerVowel(word.RS[i]) == false {
vowelPreviously = false
continue
}
vowelHere := true
switch word.RS[i] {
case 121: // y
// Is this "y" preceded OR followed by a vowel?
if vowelPreviously || vowelNext(i) {
word.RS[i] = 89 // Y
vowelHere = false
}
case 117: // u
// Is this "u" is flanked by vowels OR preceded by a "q"?
if (vowelPreviously && vowelNext(i)) || (i >= 1 && word.RS[i-1] == 113) {
word.RS[i] = 85 // U
vowelHere = false
}
case 105: // i
// Is this "i" is flanked by vowels?
if vowelPreviously && vowelNext(i) {
word.RS[i] = 73 // I
vowelHere = false
}
}
vowelPreviously = vowelHere
}
} | go | {
"resource": ""
} |
q180140 | step2 | test | func step2(w *snowballword.SnowballWord) bool {
// Possible sufficies for this step, longest first.
suffix, suffixRunes := w.FirstSuffix(
"ational", "fulness", "iveness", "ization", "ousness",
"biliti", "lessli", "tional", "alism", "aliti", "ation",
"entli", "fulli", "iviti", "ousli", "anci", "abli",
"alli", "ator", "enci", "izer", "bli", "ogi", "li",
)
// If it is not in R1, do nothing
if suffix == "" || len(suffixRunes) > len(w.RS)-w.R1start {
return false
}
// Handle special cases where we're not just going to
// replace the suffix with another suffix: there are
// other things we need to do.
//
switch suffix {
case "li":
// Delete if preceded by a valid li-ending. Valid li-endings inlude the
// following charaters: cdeghkmnrt. (Note, the unicode code points for
// these characters are, respectively, as follows:
// 99 100 101 103 104 107 109 110 114 116)
//
rsLen := len(w.RS)
if rsLen >= 3 {
switch w.RS[rsLen-3] {
case 99, 100, 101, 103, 104, 107, 109, 110, 114, 116:
w.RemoveLastNRunes(len(suffixRunes))
return true
}
}
return false
case "ogi":
// Replace by og if preceded by l.
// (Note, the unicode code point for l is 108)
//
rsLen := len(w.RS)
if rsLen >= 4 && w.RS[rsLen-4] == 108 {
w.ReplaceSuffixRunes(suffixRunes, []rune("og"), true)
}
return true
}
// Handle a suffix that was found, which is going
// to be replaced with a different suffix.
//
var repl string
switch suffix {
case "tional":
repl = "tion"
case "enci":
repl = "ence"
case "anci":
repl = "ance"
case "abli":
repl = "able"
case "entli":
repl = "ent"
case "izer", "ization":
repl = "ize"
case "ational", "ation", "ator":
repl = "ate"
case "alism", "aliti", "alli":
repl = "al"
case "fulness":
repl = "ful"
case "ousli", "ousness":
repl = "ous"
case "iveness", "iviti":
repl = "ive"
case "biliti", "bli":
repl = "ble"
case "fulli":
repl = "ful"
case "lessli":
repl = "less"
}
w.ReplaceSuffixRunes(suffixRunes, []rune(repl), true)
return true
} | go | {
"resource": ""
} |
q180141 | step3 | test | func step3(word *snowballword.SnowballWord) bool {
suffix, suffixRunes := word.FirstSuffixIfIn(word.RVstart, len(word.RS),
"os", "a", "o", "á", "í", "ó", "e", "é",
)
// No suffix found, nothing to do.
//
if suffix == "" {
return false
}
// Remove all these suffixes
word.RemoveLastNRunes(len(suffixRunes))
if suffix == "e" || suffix == "é" {
// If preceded by gu with the u in RV delete the u
//
guSuffix, _ := word.FirstSuffix("gu")
if guSuffix != "" {
word.RemoveLastNRunes(1)
}
}
return true
} | go | {
"resource": ""
} |
q180142 | step0 | test | func step0(w *snowballword.SnowballWord) bool {
suffix, suffixRunes := w.FirstSuffix("'s'", "'s", "'")
if suffix == "" {
return false
}
w.RemoveLastNRunes(len(suffixRunes))
return true
} | go | {
"resource": ""
} |
q180143 | VnvSuffix | test | func VnvSuffix(word *snowballword.SnowballWord, f isVowelFunc, start int) int {
for i := 1; i < len(word.RS[start:]); i++ {
j := start + i
if f(word.RS[j-1]) && !f(word.RS[j]) {
return j + 1
}
}
return len(word.RS)
} | go | {
"resource": ""
} |
q180144 | step1 | test | func step1(w *snowballword.SnowballWord) bool {
// Possible sufficies for this step, longest first.
suffixes := []string{
"heterna", "hetens", "anden", "heten", "heter", "arnas",
"ernas", "ornas", "andes", "arens", "andet", "arna", "erna",
"orna", "ande", "arne", "aste", "aren", "ades", "erns", "ade",
"are", "ern", "ens", "het", "ast", "ad", "en", "ar", "er",
"or", "as", "es", "at", "a", "e", "s",
}
// Using FirstSuffixIn since there are overlapping suffixes, where some might not be in the R1,
// while another might. For example: "ärade"
suffix, suffixRunes := w.FirstSuffixIn(w.R1start, len(w.RS), suffixes...)
// If it is not in R1, do nothing
if suffix == "" || len(suffixRunes) > len(w.RS)-w.R1start {
return false
}
if suffix == "s" {
// Delete if preceded by a valid s-ending. Valid s-endings inlude the
// following charaters: bcdfghjklmnoprtvy.
//
rsLen := len(w.RS)
if rsLen >= 2 {
switch w.RS[rsLen-2] {
case 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k',
'l', 'm', 'n', 'o', 'p', 'r', 't', 'v', 'y':
w.RemoveLastNRunes(len(suffixRunes))
return true
}
}
return false
}
// Remove the suffix
w.RemoveLastNRunes(len(suffixRunes))
return true
} | go | {
"resource": ""
} |
q180145 | step2a | test | func step2a(word *snowballword.SnowballWord) bool {
// Search for the longest among the following suffixes
// in RV and if found, delete if preceded by a non-vowel.
suffix, suffixRunes := word.FirstSuffixIn(word.RVstart, len(word.RS),
"issantes", "issaIent", "issions", "issants", "issante",
"iraIent", "issons", "issiez", "issent", "issant", "issait",
"issais", "irions", "issez", "isses", "iront", "irons", "iriez",
"irent", "irait", "irais", "îtes", "îmes", "isse", "irez",
"iras", "irai", "ira", "ies", "ît", "it", "is", "ir", "ie", "i",
)
if suffix != "" {
sLen := len(suffixRunes)
idx := len(word.RS) - sLen - 1
if idx >= 0 && word.FitsInRV(sLen+1) && isLowerVowel(word.RS[idx]) == false {
word.RemoveLastNRunes(len(suffixRunes))
return true
}
}
return false
} | go | {
"resource": ""
} |
q180146 | removePerfectiveGerundEnding | test | func removePerfectiveGerundEnding(word *snowballword.SnowballWord) bool {
suffix, suffixRunes := word.FirstSuffixIn(word.RVstart, len(word.RS),
"ившись", "ывшись", "вшись", "ивши", "ывши", "вши", "ив", "ыв", "в",
)
switch suffix {
case "в", "вши", "вшись":
// These are "Group 1" perfective gerund endings.
// Group 1 endings must follow а (a) or я (ia) in RV.
if precededByARinRV(word, len(suffixRunes)) == false {
suffix = ""
}
}
if suffix != "" {
word.RemoveLastNRunes(len(suffixRunes))
return true
}
return false
} | go | {
"resource": ""
} |
q180147 | removeAdjectivalEnding | test | func removeAdjectivalEnding(word *snowballword.SnowballWord) bool {
// Remove adjectival endings. Start by looking for
// an adjective ending.
//
suffix, _ := word.RemoveFirstSuffixIn(word.RVstart,
"ими", "ыми", "его", "ого", "ему", "ому", "ее", "ие",
"ые", "ое", "ей", "ий", "ый", "ой", "ем", "им", "ым",
"ом", "их", "ых", "ую", "юю", "ая", "яя", "ою", "ею",
)
if suffix != "" {
// We found an adjective ending. Remove optional participle endings.
//
newSuffix, newSuffixRunes := word.FirstSuffixIn(word.RVstart, len(word.RS),
"ивш", "ывш", "ующ",
"ем", "нн", "вш", "ющ", "щ",
)
switch newSuffix {
case "ем", "нн", "вш", "ющ", "щ":
// These are "Group 1" participle endings.
// Group 1 endings must follow а (a) or я (ia) in RV.
if precededByARinRV(word, len(newSuffixRunes)) == false {
newSuffix = ""
}
}
if newSuffix != "" {
word.RemoveLastNRunes(len(newSuffixRunes))
}
return true
}
return false
} | go | {
"resource": ""
} |
q180148 | step2b | test | func step2b(word *snowballword.SnowballWord) bool {
suffix, suffixRunes := word.FirstSuffixIn(word.RVstart, len(word.RS),
"iésemos", "iéramos", "iríamos", "eríamos", "aríamos", "ásemos",
"áramos", "ábamos", "isteis", "iríais", "iremos", "ieseis",
"ierais", "eríais", "eremos", "asteis", "aríais", "aremos",
"íamos", "irías", "irían", "iréis", "ieses", "iesen", "ieron",
"ieras", "ieran", "iendo", "erías", "erían", "eréis", "aseis",
"arías", "arían", "aréis", "arais", "abais", "íais", "iste",
"iría", "irás", "irán", "imos", "iese", "iera", "idos", "idas",
"ería", "erás", "erán", "aste", "ases", "asen", "aría", "arás",
"arán", "aron", "aras", "aran", "ando", "amos", "ados", "adas",
"abas", "aban", "ías", "ían", "éis", "áis", "iré", "irá", "ido",
"ida", "eré", "erá", "emos", "ase", "aré", "ará", "ara", "ado",
"ada", "aba", "ís", "ía", "ió", "ir", "id", "es", "er", "en",
"ed", "as", "ar", "an", "ad",
)
switch suffix {
case "":
return false
case "en", "es", "éis", "emos":
// Delete, and if preceded by gu delete the u (the gu need not be in RV)
word.RemoveLastNRunes(len(suffixRunes))
guSuffix, _ := word.FirstSuffix("gu")
if guSuffix != "" {
word.RemoveLastNRunes(1)
}
default:
// Delete
word.RemoveLastNRunes(len(suffixRunes))
}
return true
} | go | {
"resource": ""
} |
q180149 | step4 | test | func step4(word *snowballword.SnowballWord) bool {
hadChange := false
if word.String() == "voudrion" {
log.Println("...", word)
}
// If the word ends s (unicode code point 115),
// not preceded by a, i, o, u, è or s, delete it.
//
if idx := len(word.RS) - 1; idx >= 1 && word.RS[idx] == 115 {
switch word.RS[idx-1] {
case 97, 105, 111, 117, 232, 115:
// Do nothing, preceded by a, i, o, u, è or s
return false
default:
word.RemoveLastNRunes(1)
hadChange = true
}
}
// Note: all the following are restricted to the RV region.
// Search for the longest among the following suffixes in RV.
//
suffix, suffixRunes := word.FirstSuffixIn(word.RVstart, len(word.RS),
"Ière", "ière", "Ier", "ier", "ion", "e", "ë",
)
switch suffix {
case "":
return hadChange
case "ion":
// Delete if in R2 and preceded by s or t in RV
const sLen int = 3 // equivalently, len(suffixRunes)
idx := len(word.RS) - sLen - 1
if word.FitsInR2(sLen) && idx >= 0 && word.FitsInRV(sLen+1) {
if word.RS[idx] == 115 || word.RS[idx] == 116 {
word.RemoveLastNRunes(sLen)
return true
}
}
return hadChange
case "ier", "ière", "Ier", "Ière":
// Replace with i
word.ReplaceSuffixRunes(suffixRunes, []rune("i"), true)
return true
case "e":
word.RemoveLastNRunes(1)
return true
case "ë":
// If preceded by gu (unicode code point 103 & 117), delete
idx := len(word.RS) - 1
if idx >= 2 && word.RS[idx-2] == 103 && word.RS[idx-1] == 117 {
word.RemoveLastNRunes(1)
return true
}
return hadChange
}
return true
} | go | {
"resource": ""
} |
q180150 | step5 | test | func step5(w *snowballword.SnowballWord) bool {
// Last rune index = `lri`
lri := len(w.RS) - 1
// If R1 is emtpy, R2 is also empty, and we
// need not do anything in step 5.
//
if w.R1start > lri {
return false
}
if w.RS[lri] == 101 {
// The word ends with "e", which is unicode code point 101.
// Delete "e" suffix if in R2, or in R1 and not preceded
// by a short syllable.
if w.R2start <= lri || !endsShortSyllable(w, lri) {
w.ReplaceSuffix("e", "", true)
return true
}
return false
} else if w.R2start <= lri && w.RS[lri] == 108 && lri-1 >= 0 && w.RS[lri-1] == 108 {
// The word ends in double "l", and the final "l" is
// in R2. (Note, the unicode code point for "l" is 108.)
// Delete the second "l".
w.ReplaceSuffix("l", "", true)
return true
}
return false
} | go | {
"resource": ""
} |
q180151 | Stem | test | func Stem(word string, stemStopwWords bool) string {
word = strings.ToLower(strings.TrimSpace(word))
// Return small words and stop words
if len(word) <= 2 || (stemStopwWords == false && isStopWord(word)) {
return word
}
w := snowballword.New(word)
// Stem the word. Note, each of these
// steps will alter `w` in place.
//
preprocess(w)
step0(w)
changeInStep1 := step1(w)
if changeInStep1 == false {
changeInStep2a := step2a(w)
if changeInStep2a == false {
step2b(w)
}
}
step3(w)
postprocess(w)
return w.String()
} | go | {
"resource": ""
} |
q180152 | Stem | test | func Stem(word string, stemStopwWords bool) string {
word = strings.ToLower(strings.TrimSpace(word))
w := snowballword.New(word)
// Return small words and stop words
if len(w.RS) <= 2 || (stemStopwWords == false && isStopWord(word)) {
return word
}
preprocess(w)
step1(w)
step2(w)
step3(w)
step4(w)
return w.String()
} | go | {
"resource": ""
} |
q180153 | isStopWord | test | func isStopWord(word string) bool {
switch word {
case "ut", "få", "hadde", "hva", "tilbake", "vil", "han", "meget", "men", "vi", "en", "før",
"samme", "stille", "inn", "er", "kan", "makt", "ved", "forsøke", "hvis", "part", "rett",
"måte", "denne", "mer", "i", "lang", "ny", "hans", "hvilken", "tid", "vite", "her", "opp",
"var", "navn", "mye", "om", "sant", "tilstand", "der", "ikke", "mest", "punkt", "hvem",
"skulle", "mange", "over", "vårt", "alle", "arbeid", "lik", "like", "gå", "når", "siden",
"å", "begge", "bruke", "eller", "og", "til", "da", "et", "hvorfor", "nå", "sist", "slutt",
"deres", "det", "hennes", "så", "mens", "bra", "din", "fordi", "gjøre", "god", "ha", "start",
"andre", "må", "med", "under", "meg", "oss", "innen", "på", "verdi", "ville", "kunne", "uten",
"vår", "slik", "ene", "folk", "min", "riktig", "enhver", "bort", "enn", "nei", "som", "våre", "disse",
"gjorde", "lage", "si", "du", "fra", "også", "hvordan", "av", "eneste", "for", "hvor", "først", "hver":
return true
}
return false
} | go | {
"resource": ""
} |
q180154 | isStopWord | test | func isStopWord(word string) bool {
switch word {
case "och", "det", "att", "i", "en", "jag", "hon", "som", "han",
"på", "den", "med", "var", "sig", "för", "så", "till", "är", "men",
"ett", "om", "hade", "de", "av", "icke", "mig", "du", "henne", "då",
"sin", "nu", "har", "inte", "hans", "honom", "skulle", "hennes",
"där", "min", "man", "ej", "vid", "kunde", "något", "från", "ut",
"när", "efter", "upp", "vi", "dem", "vara", "vad", "över", "än",
"dig", "kan", "sina", "här", "ha", "mot", "alla", "under", "någon",
"eller", "allt", "mycket", "sedan", "ju", "denna", "själv", "detta",
"åt", "utan", "varit", "hur", "ingen", "mitt", "ni", "bli", "blev",
"oss", "din", "dessa", "några", "deras", "blir", "mina", "samma",
"vilken", "er", "sådan", "vår", "blivit", "dess", "inom", "mellan",
"sådant", "varför", "varje", "vilka", "ditt", "vem", "vilket",
"sitta", "sådana", "vart", "dina", "vars", "vårt", "våra",
"ert", "era", "vilkas":
return true
}
return false
} | go | {
"resource": ""
} |
q180155 | New | test | func New(in string) (word *SnowballWord) {
word = &SnowballWord{RS: []rune(in)}
word.R1start = len(word.RS)
word.R2start = len(word.RS)
word.RVstart = len(word.RS)
return
} | go | {
"resource": ""
} |
q180156 | RemoveLastNRunes | test | func (w *SnowballWord) RemoveLastNRunes(n int) {
w.RS = w.RS[:len(w.RS)-n]
w.resetR1R2()
} | go | {
"resource": ""
} |
q180157 | resetR1R2 | test | func (w *SnowballWord) resetR1R2() {
rsLen := len(w.RS)
if w.R1start > rsLen {
w.R1start = rsLen
}
if w.R2start > rsLen {
w.R2start = rsLen
}
if w.RVstart > rsLen {
w.RVstart = rsLen
}
} | go | {
"resource": ""
} |
q180158 | slice | test | func (w *SnowballWord) slice(start, stop int) []rune {
startMin := 0
if start < startMin {
start = startMin
}
max := len(w.RS) - 1
if start > max {
start = max
}
if stop > max {
stop = max
}
return w.RS[start:stop]
} | go | {
"resource": ""
} |
q180159 | FitsInR1 | test | func (w *SnowballWord) FitsInR1(x int) bool {
return w.R1start <= len(w.RS)-x
} | go | {
"resource": ""
} |
q180160 | FitsInR2 | test | func (w *SnowballWord) FitsInR2(x int) bool {
return w.R2start <= len(w.RS)-x
} | go | {
"resource": ""
} |
q180161 | FitsInRV | test | func (w *SnowballWord) FitsInRV(x int) bool {
return w.RVstart <= len(w.RS)-x
} | go | {
"resource": ""
} |
q180162 | FirstPrefix | test | func (w *SnowballWord) FirstPrefix(prefixes ...string) (foundPrefix string, foundPrefixRunes []rune) {
found := false
rsLen := len(w.RS)
for _, prefix := range prefixes {
prefixRunes := []rune(prefix)
if len(prefixRunes) > rsLen {
continue
}
found = true
for i, r := range prefixRunes {
if i > rsLen-1 || (w.RS)[i] != r {
found = false
break
}
}
if found {
foundPrefix = prefix
foundPrefixRunes = prefixRunes
break
}
}
return
} | go | {
"resource": ""
} |
q180163 | HasSuffixRunes | test | func (w *SnowballWord) HasSuffixRunes(suffixRunes []rune) bool {
return w.HasSuffixRunesIn(0, len(w.RS), suffixRunes)
} | go | {
"resource": ""
} |
q180164 | FirstSuffixIfIn | test | func (w *SnowballWord) FirstSuffixIfIn(startPos, endPos int, suffixes ...string) (suffix string, suffixRunes []rune) {
for _, suffix := range suffixes {
suffixRunes := []rune(suffix)
if w.HasSuffixRunesIn(0, endPos, suffixRunes) {
if endPos-len(suffixRunes) >= startPos {
return suffix, suffixRunes
} else {
// Empty out suffixRunes
suffixRunes = suffixRunes[:0]
return "", suffixRunes
}
}
}
// Empty out suffixRunes
suffixRunes = suffixRunes[:0]
return "", suffixRunes
} | go | {
"resource": ""
} |
q180165 | RemoveFirstSuffixIfIn | test | func (w *SnowballWord) RemoveFirstSuffixIfIn(startPos int, suffixes ...string) (suffix string, suffixRunes []rune) {
suffix, suffixRunes = w.FirstSuffixIfIn(startPos, len(w.RS), suffixes...)
if suffix != "" {
w.RemoveLastNRunes(len(suffixRunes))
}
return
} | go | {
"resource": ""
} |
q180166 | RemoveFirstSuffix | test | func (w *SnowballWord) RemoveFirstSuffix(suffixes ...string) (suffix string, suffixRunes []rune) {
return w.RemoveFirstSuffixIn(0, suffixes...)
} | go | {
"resource": ""
} |
q180167 | FirstSuffix | test | func (w *SnowballWord) FirstSuffix(suffixes ...string) (suffix string, suffixRunes []rune) {
return w.FirstSuffixIfIn(0, len(w.RS), suffixes...)
} | go | {
"resource": ""
} |
q180168 | preprocess | test | func preprocess(word *snowballword.SnowballWord) {
// Clean up apostrophes
normalizeApostrophes(word)
trimLeftApostrophes(word)
// Capitalize Y's that are not behaving
// as vowels.
capitalizeYs(word)
// Find the two regions, R1 & R2
r1start, r2start := r1r2(word)
word.R1start = r1start
word.R2start = r2start
} | go | {
"resource": ""
} |
q180169 | step0 | test | func step0(word *snowballword.SnowballWord) bool {
// Search for the longest among the following suffixes
suffix1, suffix1Runes := word.FirstSuffixIn(word.RVstart, len(word.RS),
"selas", "selos", "sela", "selo", "las", "les",
"los", "nos", "me", "se", "la", "le", "lo",
)
// If the suffix empty or not in RV, we have nothing to do.
if suffix1 == "" {
return false
}
// We'll remove suffix1, if comes after one of the following
suffix2, suffix2Runes := word.FirstSuffixIn(word.RVstart, len(word.RS)-len(suffix1),
"iéndo", "iendo", "yendo", "ando", "ándo",
"ár", "ér", "ír", "ar", "er", "ir",
)
switch suffix2 {
case "":
// Nothing to do
return false
case "iéndo", "ándo", "ár", "ér", "ír":
// In these cases, deletion is followed by removing
// the acute accent (e.g., haciéndola -> haciendo).
var suffix2repl string
switch suffix2 {
case "":
return false
case "iéndo":
suffix2repl = "iendo"
case "ándo":
suffix2repl = "ando"
case "ár":
suffix2repl = "ar"
case "ír":
suffix2repl = "ir"
}
word.RemoveLastNRunes(len(suffix1Runes))
word.ReplaceSuffixRunes(suffix2Runes, []rune(suffix2repl), true)
return true
case "ando", "iendo", "ar", "er", "ir":
word.RemoveLastNRunes(len(suffix1Runes))
return true
case "yendo":
// In the case of "yendo", the "yendo" must lie in RV,
// and be preceded by a "u" somewhere in the word.
for i := 0; i < len(word.RS)-(len(suffix1)+len(suffix2)); i++ {
// Note, the unicode code point for "u" is 117.
if word.RS[i] == 117 {
word.RemoveLastNRunes(len(suffix1Runes))
return true
}
}
}
return false
} | go | {
"resource": ""
} |
q180170 | step1b | test | func step1b(w *snowballword.SnowballWord) bool {
suffix, suffixRunes := w.FirstSuffix("eedly", "ingly", "edly", "ing", "eed", "ed")
switch suffix {
case "":
// No suffix found
return false
case "eed", "eedly":
// Replace by ee if in R1
if len(suffixRunes) <= len(w.RS)-w.R1start {
w.ReplaceSuffixRunes(suffixRunes, []rune("ee"), true)
}
return true
case "ed", "edly", "ing", "ingly":
hasLowerVowel := false
for i := 0; i < len(w.RS)-len(suffixRunes); i++ {
if isLowerVowel(w.RS[i]) {
hasLowerVowel = true
break
}
}
if hasLowerVowel {
// This case requires a two-step transformation and, due
// to the way we've implemented the `ReplaceSuffix` method
// here, information about R1 and R2 would be lost between
// the two. Therefore, we need to keep track of the
// original R1 & R2, so that we may set them below, at the
// end of this case.
//
originalR1start := w.R1start
originalR2start := w.R2start
// Delete if the preceding word part contains a vowel
w.RemoveLastNRunes(len(suffixRunes))
// ...and after the deletion...
newSuffix, newSuffixRunes := w.FirstSuffix("at", "bl", "iz", "bb", "dd", "ff", "gg", "mm", "nn", "pp", "rr", "tt")
switch newSuffix {
case "":
// If the word is short, add "e"
if isShortWord(w) {
// By definition, r1 and r2 are the empty string for
// short words.
w.RS = append(w.RS, []rune("e")...)
w.R1start = len(w.RS)
w.R2start = len(w.RS)
return true
}
case "at", "bl", "iz":
// If the word ends "at", "bl" or "iz" add "e"
w.ReplaceSuffixRunes(newSuffixRunes, []rune(newSuffix+"e"), true)
case "bb", "dd", "ff", "gg", "mm", "nn", "pp", "rr", "tt":
// If the word ends with a double remove the last letter.
// Note that, "double" does not include all possible doubles,
// just those shown above.
//
w.RemoveLastNRunes(1)
}
// Because we did a double replacement, we need to fix
// R1 and R2 manually. This is just becase of how we've
// implemented the `ReplaceSuffix` method.
//
rsLen := len(w.RS)
if originalR1start < rsLen {
w.R1start = originalR1start
} else {
w.R1start = rsLen
}
if originalR2start < rsLen {
w.R2start = originalR2start
} else {
w.R2start = rsLen
}
return true
}
}
return false
} | go | {
"resource": ""
} |
q180171 | step2b | test | func step2b(word *snowballword.SnowballWord) bool {
// Search for the longest among the following suffixes in RV.
//
suffix, suffixRunes := word.FirstSuffixIn(word.RVstart, len(word.RS),
"eraIent", "assions", "erions", "assiez", "assent",
"èrent", "eront", "erons", "eriez", "erait", "erais",
"asses", "antes", "aIent", "âtes", "âmes", "ions",
"erez", "eras", "erai", "asse", "ants", "ante", "ées",
"iez", "era", "ant", "ait", "ais", "és", "ée", "ât",
"ez", "er", "as", "ai", "é", "a",
)
switch suffix {
case "ions":
// Delete if in R2
suffixLen := len(suffixRunes)
if word.FitsInR2(suffixLen) {
word.RemoveLastNRunes(suffixLen)
return true
}
return false
case "é", "ée", "ées", "és", "èrent", "er", "era",
"erai", "eraIent", "erais", "erait", "eras", "erez",
"eriez", "erions", "erons", "eront", "ez", "iez":
// Delete
word.RemoveLastNRunes(len(suffixRunes))
return true
case "âmes", "ât", "âtes", "a", "ai", "aIent",
"ais", "ait", "ant", "ante", "antes", "ants", "as",
"asse", "assent", "asses", "assiez", "assions":
// Delete
word.RemoveLastNRunes(len(suffixRunes))
// If preceded by e (unicode code point 101), delete
//
idx := len(word.RS) - 1
if idx >= 0 && word.RS[idx] == 101 && word.FitsInRV(1) {
word.RemoveLastNRunes(1)
}
return true
}
return false
} | go | {
"resource": ""
} |
q180172 | capitalizeYs | test | func capitalizeYs(word *snowballword.SnowballWord) (numCapitalizations int) {
for i, r := range word.RS {
// (Note: Y & y unicode code points = 89 & 121)
if r == 121 && (i == 0 || isLowerVowel(word.RS[i-1])) {
word.RS[i] = 89
numCapitalizations += 1
}
}
return
} | go | {
"resource": ""
} |
q180173 | uncapitalizeYs | test | func uncapitalizeYs(word *snowballword.SnowballWord) {
for i, r := range word.RS {
// (Note: Y & y unicode code points = 89 & 121)
if r == 89 {
word.RS[i] = 121
}
}
return
} | go | {
"resource": ""
} |
q180174 | stemSpecialWord | test | func stemSpecialWord(word string) (stemmed string) {
switch word {
case "skis":
stemmed = "ski"
case "skies":
stemmed = "sky"
case "dying":
stemmed = "die"
case "lying":
stemmed = "lie"
case "tying":
stemmed = "tie"
case "idly":
stemmed = "idl"
case "gently":
stemmed = "gentl"
case "ugly":
stemmed = "ugli"
case "early":
stemmed = "earli"
case "only":
stemmed = "onli"
case "singly":
stemmed = "singl"
case "sky":
stemmed = "sky"
case "news":
stemmed = "news"
case "howe":
stemmed = "howe"
case "atlas":
stemmed = "atlas"
case "cosmos":
stemmed = "cosmos"
case "bias":
stemmed = "bias"
case "andes":
stemmed = "andes"
case "inning":
stemmed = "inning"
case "innings":
stemmed = "inning"
case "outing":
stemmed = "outing"
case "outings":
stemmed = "outing"
case "canning":
stemmed = "canning"
case "cannings":
stemmed = "canning"
case "herring":
stemmed = "herring"
case "herrings":
stemmed = "herring"
case "earring":
stemmed = "earring"
case "earrings":
stemmed = "earring"
case "proceed":
stemmed = "proceed"
case "proceeds":
stemmed = "proceed"
case "proceeded":
stemmed = "proceed"
case "proceeding":
stemmed = "proceed"
case "exceed":
stemmed = "exceed"
case "exceeds":
stemmed = "exceed"
case "exceeded":
stemmed = "exceed"
case "exceeding":
stemmed = "exceed"
case "succeed":
stemmed = "succeed"
case "succeeds":
stemmed = "succeed"
case "succeeded":
stemmed = "succeed"
case "succeeding":
stemmed = "succeed"
}
return
} | go | {
"resource": ""
} |
q180175 | isShortWord | test | func isShortWord(w *snowballword.SnowballWord) (isShort bool) {
// If r1 is not empty, the word is not short
if w.R1start < len(w.RS) {
return
}
// Otherwise it must end in a short syllable
return endsShortSyllable(w, len(w.RS))
} | go | {
"resource": ""
} |
q180176 | step1a | test | func step1a(w *snowballword.SnowballWord) bool {
suffix, suffixRunes := w.FirstSuffix("sses", "ied", "ies", "us", "ss", "s")
switch suffix {
case "sses":
// Replace by ss
w.ReplaceSuffixRunes(suffixRunes, []rune("ss"), true)
return true
case "ies", "ied":
// Replace by i if preceded by more than one letter,
// otherwise by ie (so ties -> tie, cries -> cri).
var repl string
if len(w.RS) > 4 {
repl = "i"
} else {
repl = "ie"
}
w.ReplaceSuffixRunes(suffixRunes, []rune(repl), true)
return true
case "us", "ss":
// Do nothing
return false
case "s":
// Delete if the preceding word part contains a vowel
// not immediately before the s (so gas and this retain
// the s, gaps and kiwis lose it)
//
for i := 0; i < len(w.RS)-2; i++ {
if isLowerVowel(w.RS[i]) {
w.RemoveLastNRunes(len(suffixRunes))
return true
}
}
}
return false
} | go | {
"resource": ""
} |
q180177 | Set | test | func Set(key string, value interface{}) {
gid := curGoroutineID()
dataLock.Lock()
if data[gid] == nil {
data[gid] = Values{}
}
data[gid][key] = value
dataLock.Unlock()
} | go | {
"resource": ""
} |
q180178 | Get | test | func Get(key string) interface{} {
gid := curGoroutineID()
dataLock.RLock()
if data[gid] == nil {
dataLock.RUnlock()
return nil
}
value := data[gid][key]
dataLock.RUnlock()
return value
} | go | {
"resource": ""
} |
q180179 | Cleanup | test | func Cleanup() {
gid := curGoroutineID()
dataLock.Lock()
delete(data, gid)
dataLock.Unlock()
} | go | {
"resource": ""
} |
q180180 | getValues | test | func getValues() Values {
gid := curGoroutineID()
dataLock.Lock()
values := data[gid]
dataLock.Unlock()
return values
} | go | {
"resource": ""
} |
q180181 | linkGRs | test | func linkGRs(parentData Values) {
childID := curGoroutineID()
dataLock.Lock()
data[childID] = parentData
dataLock.Unlock()
} | go | {
"resource": ""
} |
q180182 | unlinkGRs | test | func unlinkGRs() {
childID := curGoroutineID()
dataLock.Lock()
delete(data, childID)
dataLock.Unlock()
} | go | {
"resource": ""
} |
q180183 | AppUri | test | func AppUri(appName, path string, config helpersinternal.CurlConfig) string {
uriCreator := &helpersinternal.AppUriCreator{CurlConfig: config}
return uriCreator.AppUri(appName, path)
} | go | {
"resource": ""
} |
q180184 | CurlAppWithTimeout | test | func CurlAppWithTimeout(cfg helpersinternal.CurlConfig, appName, path string, timeout time.Duration, args ...string) string {
appCurler := helpersinternal.NewAppCurler(Curl, cfg)
return appCurler.CurlAndWait(cfg, appName, path, timeout, args...)
} | go | {
"resource": ""
} |
q180185 | CurlApp | test | func CurlApp(cfg helpersinternal.CurlConfig, appName, path string, args ...string) string {
appCurler := helpersinternal.NewAppCurler(Curl, cfg)
return appCurler.CurlAndWait(cfg, appName, path, CURL_TIMEOUT, args...)
} | go | {
"resource": ""
} |
q180186 | CurlAppRoot | test | func CurlAppRoot(cfg helpersinternal.CurlConfig, appName string) string {
appCurler := helpersinternal.NewAppCurler(Curl, cfg)
return appCurler.CurlAndWait(cfg, appName, "/", CURL_TIMEOUT)
} | go | {
"resource": ""
} |
q180187 | GetTags | test | func GetTags(prefix rune, str string, terminator ...rune) (tags []Tag) {
// If we have no terminators given, default to only whitespace
if len(terminator) == 0 {
terminator = []rune(" ")
}
// get list of indexes in our str that is a terminator
// Always include the beginning of our str a terminator. This is so we can
// detect the first character as a prefix
termIndexes := []int{-1}
for i, char := range str {
if isTerminator(char, terminator...) {
termIndexes = append(termIndexes, i)
}
}
// Always include last character as a terminator
termIndexes = append(termIndexes, len(str))
// check if the character AFTER our term index is our prefix
for i, t := range termIndexes {
// ensure term index is not the last character in str
if t >= (len(str) - 1) {
break
}
if str[t+1] == byte(prefix) {
tagText := strings.TrimLeft(str[t+2:termIndexes[i+1]], string(prefix))
if tagText == "" {
continue
}
index := t + 1
tags = append(tags, Tag{prefix, tagText, index})
}
}
return
} | go | {
"resource": ""
} |
q180188 | GetTagsAsUniqueStrings | test | func GetTagsAsUniqueStrings(prefix rune, str string, terminator ...rune) (strs []string) {
tags := GetTags(prefix, str, terminator...)
for _, tag := range tags {
strs = append(strs, tag.Tag)
}
return uniquify(strs)
} | go | {
"resource": ""
} |
q180189 | isTerminator | test | func isTerminator(r rune, terminator ...rune) bool {
for _, t := range terminator {
if r == t {
return true
}
}
return unicode.IsSpace(r) || !unicode.IsPrint(r)
} | go | {
"resource": ""
} |
q180190 | uniquify | test | func uniquify(in []string) (out []string) {
for _, i := range in {
if i == "" {
continue
}
for _, o := range out {
if i == o {
continue
}
}
out = append(out, i)
}
return
} | go | {
"resource": ""
} |
q180191 | New | test | func New(config Config) gin.HandlerFunc {
location := newLocation(config)
return func(c *gin.Context) {
location.applyToContext(c)
}
} | go | {
"resource": ""
} |
q180192 | Get | test | func Get(c *gin.Context) *url.URL {
v, ok := c.Get(key)
if !ok {
return nil
}
vv, ok := v.(*url.URL)
if !ok {
return nil
}
return vv
} | go | {
"resource": ""
} |
q180193 | GenerateRSAKeyPair | test | func GenerateRSAKeyPair(bits int, src io.Reader) (PrivKey, PubKey, error) {
if bits < 512 {
return nil, nil, ErrRsaKeyTooSmall
}
priv, err := rsa.GenerateKey(src, bits)
if err != nil {
return nil, nil, err
}
pk := &priv.PublicKey
return &RsaPrivateKey{sk: priv}, &RsaPublicKey{pk}, nil
} | go | {
"resource": ""
} |
q180194 | Verify | test | func (pk *RsaPublicKey) Verify(data, sig []byte) (bool, error) {
hashed := sha256.Sum256(data)
err := rsa.VerifyPKCS1v15(pk.k, crypto.SHA256, hashed[:], sig)
if err != nil {
return false, err
}
return true, nil
} | go | {
"resource": ""
} |
q180195 | Encrypt | test | func (pk *RsaPublicKey) Encrypt(b []byte) ([]byte, error) {
return rsa.EncryptPKCS1v15(rand.Reader, pk.k, b)
} | go | {
"resource": ""
} |
q180196 | Sign | test | func (sk *RsaPrivateKey) Sign(message []byte) ([]byte, error) {
hashed := sha256.Sum256(message)
return rsa.SignPKCS1v15(rand.Reader, sk.sk, crypto.SHA256, hashed[:])
} | go | {
"resource": ""
} |
q180197 | GetPublic | test | func (sk *RsaPrivateKey) GetPublic() PubKey {
if sk.pk == nil {
sk.pk = &sk.sk.PublicKey
}
return &RsaPublicKey{sk.pk}
} | go | {
"resource": ""
} |
q180198 | Decrypt | test | func (sk *RsaPrivateKey) Decrypt(b []byte) ([]byte, error) {
return rsa.DecryptPKCS1v15(rand.Reader, sk.sk, b)
} | go | {
"resource": ""
} |
q180199 | UnmarshalRsaPrivateKey | test | func UnmarshalRsaPrivateKey(b []byte) (PrivKey, error) {
sk, err := x509.ParsePKCS1PrivateKey(b)
if err != nil {
return nil, err
}
if sk.N.BitLen() < 512 {
return nil, ErrRsaKeyTooSmall
}
return &RsaPrivateKey{sk: sk}, nil
} | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.