repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
nwaples/rardecode
archive15.go
readBlockHeader
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
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 }
[ "func", "(", "a", "*", "archive15", ")", "readBlockHeader", "(", ")", "(", "*", "blockHeader15", ",", "error", ")", "{", "var", "err", "error", "\n", "b", ":=", "a", ".", "buf", "[", ":", "7", "]", "\n", "r", ":=", "io", ".", "Reader", "(", "a", ".", "v", ")", "\n", "if", "a", ".", "encrypted", "{", "salt", ":=", "a", ".", "buf", "[", ":", "saltSize", "]", "\n", "_", ",", "err", "=", "io", ".", "ReadFull", "(", "r", ",", "salt", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "key", ",", "iv", ":=", "a", ".", "getKeys", "(", "salt", ")", "\n", "r", "=", "newAesDecryptReader", "(", "r", ",", "key", ",", "iv", ")", "\n", "err", "=", "readFull", "(", "r", ",", "b", ")", "\n", "}", "else", "{", "_", ",", "err", "=", "io", ".", "ReadFull", "(", "r", ",", "b", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "crc", ":=", "b", ".", "uint16", "(", ")", "\n", "hash", ":=", "crc32", ".", "NewIEEE", "(", ")", "\n", "hash", ".", "Write", "(", "b", ")", "\n", "h", ":=", "new", "(", "blockHeader15", ")", "\n", "h", ".", "htype", "=", "b", ".", "byte", "(", ")", "\n", "h", ".", "flags", "=", "b", ".", "uint16", "(", ")", "\n", "size", ":=", "b", ".", "uint16", "(", ")", "\n", "if", "size", "<", "7", "{", "return", "nil", ",", "errCorruptHeader", "\n", "}", "\n", "size", "-=", "7", "\n", "if", "int", "(", "size", ")", ">", "cap", "(", "a", ".", "buf", ")", "{", "a", ".", "buf", "=", "readBuf", "(", "make", "(", "[", "]", "byte", ",", "size", ")", ")", "\n", "}", "\n", "h", ".", "data", "=", "a", ".", "buf", "[", ":", "size", "]", "\n", "if", "err", ":=", "readFull", "(", "r", ",", "h", ".", "data", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "hash", ".", "Write", "(", "h", ".", "data", ")", "\n", "if", "crc", "!=", "uint16", "(", "hash", ".", "Sum32", "(", ")", ")", "{", "return", "nil", ",", "errBadHeaderCrc", "\n", "}", "\n", "if", "h", ".", "flags", "&", "blockHasData", ">", "0", "{", "if", "len", "(", "h", ".", "data", ")", "<", "4", "{", "return", "nil", ",", "errCorruptHeader", "\n", "}", "\n", "h", ".", "dataSize", "=", "int64", "(", "h", ".", "data", ".", "uint32", "(", ")", ")", "\n", "}", "\n", "if", "(", "h", ".", "htype", "==", "blockService", "||", "h", ".", "htype", "==", "blockFile", ")", "&&", "h", ".", "flags", "&", "fileLargeData", ">", "0", "{", "if", "len", "(", "h", ".", "data", ")", "<", "25", "{", "return", "nil", ",", "errCorruptHeader", "\n", "}", "\n", "b", ":=", "h", ".", "data", "[", "21", ":", "25", "]", "\n", "h", ".", "dataSize", "|=", "int64", "(", "b", ".", "uint32", "(", ")", ")", "<<", "32", "\n", "}", "\n", "return", "h", ",", "nil", "\n", "}" ]
// readBlockHeader returns the next block header in the archive. // It will return io.EOF if there were no bytes read.
[ "readBlockHeader", "returns", "the", "next", "block", "header", "in", "the", "archive", ".", "It", "will", "return", "io", ".", "EOF", "if", "there", "were", "no", "bytes", "read", "." ]
197ef08ef68c4454ae5970a9c2692d6056ceb8d7
https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/archive15.go#L360-L416
test
nwaples/rardecode
archive15.go
newArchive15
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
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 }
[ "func", "newArchive15", "(", "r", "*", "bufio", ".", "Reader", ",", "password", "string", ")", "fileBlockReader", "{", "a", ":=", "new", "(", "archive15", ")", "\n", "a", ".", "v", "=", "r", "\n", "a", ".", "pass", "=", "utf16", ".", "Encode", "(", "[", "]", "rune", "(", "password", ")", ")", "\n", "a", ".", "checksum", ".", "Hash32", "=", "crc32", ".", "NewIEEE", "(", ")", "\n", "a", ".", "buf", "=", "readBuf", "(", "make", "(", "[", "]", "byte", ",", "100", ")", ")", "\n", "return", "a", "\n", "}" ]
// newArchive15 creates a new fileBlockReader for a Version 1.5 archive
[ "newArchive15", "creates", "a", "new", "fileBlockReader", "for", "a", "Version", "1", ".", "5", "archive" ]
197ef08ef68c4454ae5970a9c2692d6056ceb8d7
https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/archive15.go#L461-L468
test
nwaples/rardecode
decode50.go
readFilter5Data
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
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 }
[ "func", "readFilter5Data", "(", "br", "bitReader", ")", "(", "int", ",", "error", ")", "{", "bytes", ",", "err", ":=", "br", ".", "readBits", "(", "2", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "bytes", "++", "\n", "var", "data", "int", "\n", "for", "i", ":=", "0", ";", "i", "<", "bytes", ";", "i", "++", "{", "n", ",", "err", ":=", "br", ".", "readBits", "(", "8", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "data", "|=", "n", "<<", "(", "uint", "(", "i", ")", "*", "8", ")", "\n", "}", "\n", "return", "data", ",", "nil", "\n", "}" ]
// readFilter5Data reads an encoded integer used in V5 filters.
[ "readFilter5Data", "reads", "an", "encoded", "integer", "used", "in", "V5", "filters", "." ]
197ef08ef68c4454ae5970a9c2692d6056ceb8d7
https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/decode50.go#L132-L150
test
nwaples/rardecode
decode_reader.go
writeByte
func (w *window) writeByte(c byte) { w.buf[w.w] = c w.w = (w.w + 1) & w.mask }
go
func (w *window) writeByte(c byte) { w.buf[w.w] = c w.w = (w.w + 1) & w.mask }
[ "func", "(", "w", "*", "window", ")", "writeByte", "(", "c", "byte", ")", "{", "w", ".", "buf", "[", "w", ".", "w", "]", "=", "c", "\n", "w", ".", "w", "=", "(", "w", ".", "w", "+", "1", ")", "&", "w", ".", "mask", "\n", "}" ]
// writeByte writes c to the end of the window
[ "writeByte", "writes", "c", "to", "the", "end", "of", "the", "window" ]
197ef08ef68c4454ae5970a9c2692d6056ceb8d7
https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/decode_reader.go#L78-L81
test
nwaples/rardecode
decode_reader.go
copyBytes
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
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 } }
[ "func", "(", "w", "*", "window", ")", "copyBytes", "(", "len", ",", "off", "int", ")", "{", "len", "&=", "w", ".", "mask", "\n", "n", ":=", "w", ".", "available", "(", ")", "\n", "if", "len", ">", "n", "{", "w", ".", "l", "=", "len", "-", "n", "\n", "w", ".", "o", "=", "off", "\n", "len", "=", "n", "\n", "}", "\n", "i", ":=", "(", "w", ".", "w", "-", "off", ")", "&", "w", ".", "mask", "\n", "for", ";", "len", ">", "0", ";", "len", "--", "{", "w", ".", "buf", "[", "w", ".", "w", "]", "=", "w", ".", "buf", "[", "i", "]", "\n", "w", ".", "w", "=", "(", "w", ".", "w", "+", "1", ")", "&", "w", ".", "mask", "\n", "i", "=", "(", "i", "+", "1", ")", "&", "w", ".", "mask", "\n", "}", "\n", "}" ]
// copyBytes copies len bytes at off distance from the end // to the end of the window.
[ "copyBytes", "copies", "len", "bytes", "at", "off", "distance", "from", "the", "end", "to", "the", "end", "of", "the", "window", "." ]
197ef08ef68c4454ae5970a9c2692d6056ceb8d7
https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/decode_reader.go#L85-L104
test
nwaples/rardecode
decode_reader.go
read
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
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 }
[ "func", "(", "w", "*", "window", ")", "read", "(", "p", "[", "]", "byte", ")", "(", "n", "int", ")", "{", "if", "w", ".", "r", ">", "w", ".", "w", "{", "n", "=", "copy", "(", "p", ",", "w", ".", "buf", "[", "w", ".", "r", ":", "]", ")", "\n", "w", ".", "r", "=", "(", "w", ".", "r", "+", "n", ")", "&", "w", ".", "mask", "\n", "p", "=", "p", "[", "n", ":", "]", "\n", "}", "\n", "if", "w", ".", "r", "<", "w", ".", "w", "{", "l", ":=", "copy", "(", "p", ",", "w", ".", "buf", "[", "w", ".", "r", ":", "w", ".", "w", "]", ")", "\n", "w", ".", "r", "+=", "l", "\n", "n", "+=", "l", "\n", "}", "\n", "if", "w", ".", "l", ">", "0", "&&", "n", ">", "0", "{", "l", ":=", "w", ".", "l", "\n", "w", ".", "l", "=", "0", "\n", "w", ".", "copyBytes", "(", "l", ",", "w", ".", "o", ")", "\n", "}", "\n", "return", "n", "\n", "}" ]
// read reads bytes from the beginning of the window into p
[ "read", "reads", "bytes", "from", "the", "beginning", "of", "the", "window", "into", "p" ]
197ef08ef68c4454ae5970a9c2692d6056ceb8d7
https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/decode_reader.go#L107-L126
test
nwaples/rardecode
decode_reader.go
queueFilter
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
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 }
[ "func", "(", "d", "*", "decodeReader", ")", "queueFilter", "(", "f", "*", "filterBlock", ")", "error", "{", "if", "f", ".", "reset", "{", "d", ".", "filters", "=", "nil", "\n", "}", "\n", "if", "len", "(", "d", ".", "filters", ")", ">=", "maxQueuedFilters", "{", "return", "errTooManyFilters", "\n", "}", "\n", "f", ".", "offset", "&=", "d", ".", "win", ".", "mask", "\n", "f", ".", "length", "&=", "d", ".", "win", ".", "mask", "\n", "for", "_", ",", "fb", ":=", "range", "d", ".", "filters", "{", "if", "f", ".", "offset", "<", "fb", ".", "offset", "{", "return", "errInvalidFilter", "\n", "}", "\n", "f", ".", "offset", "-=", "fb", ".", "offset", "\n", "}", "\n", "d", ".", "filters", "=", "append", "(", "d", ".", "filters", ",", "f", ")", "\n", "return", "nil", "\n", "}" ]
// queueFilter adds a filterBlock to the end decodeReader's filters.
[ "queueFilter", "adds", "a", "filterBlock", "to", "the", "end", "decodeReader", "s", "filters", "." ]
197ef08ef68c4454ae5970a9c2692d6056ceb8d7
https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/decode_reader.go#L158-L178
test
nwaples/rardecode
decode_reader.go
processFilters
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
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...) } } }
[ "func", "(", "d", "*", "decodeReader", ")", "processFilters", "(", ")", "(", "err", "error", ")", "{", "f", ":=", "d", ".", "filters", "[", "0", "]", "\n", "if", "f", ".", "offset", ">", "0", "{", "return", "nil", "\n", "}", "\n", "d", ".", "filters", "=", "d", ".", "filters", "[", "1", ":", "]", "\n", "if", "d", ".", "win", ".", "buffered", "(", ")", "<", "f", ".", "length", "{", "err", "=", "d", ".", "readErr", "(", ")", "\n", "if", "err", "==", "nil", "||", "err", "==", "io", ".", "EOF", "{", "return", "errInvalidFilter", "\n", "}", "\n", "return", "err", "\n", "}", "\n", "if", "cap", "(", "d", ".", "buf", ")", "<", "f", ".", "length", "{", "d", ".", "buf", "=", "make", "(", "[", "]", "byte", ",", "f", ".", "length", ")", "\n", "}", "\n", "d", ".", "outbuf", "=", "d", ".", "buf", "[", ":", "f", ".", "length", "]", "\n", "n", ":=", "d", ".", "win", ".", "read", "(", "d", ".", "outbuf", ")", "\n", "for", "{", "d", ".", "outbuf", ",", "err", "=", "f", ".", "filter", "(", "d", ".", "outbuf", ",", "d", ".", "tot", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "cap", "(", "d", ".", "outbuf", ")", ">", "cap", "(", "d", ".", "buf", ")", "{", "d", ".", "buf", "=", "d", ".", "outbuf", "\n", "}", "\n", "if", "len", "(", "d", ".", "filters", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "f", "=", "d", ".", "filters", "[", "0", "]", "\n", "if", "f", ".", "offset", "!=", "0", "{", "f", ".", "offset", "-=", "n", "\n", "return", "nil", "\n", "}", "\n", "if", "f", ".", "length", "!=", "len", "(", "d", ".", "outbuf", ")", "{", "return", "errInvalidFilter", "\n", "}", "\n", "d", ".", "filters", "=", "d", ".", "filters", "[", "1", ":", "]", "\n", "if", "cap", "(", "d", ".", "outbuf", ")", "<", "cap", "(", "d", ".", "buf", ")", "{", "d", ".", "outbuf", "=", "append", "(", "d", ".", "buf", "[", ":", "0", "]", ",", "d", ".", "outbuf", "...", ")", "\n", "}", "\n", "}", "\n", "}" ]
// processFilters processes any filters valid at the current read index // and stores the output in outbuf.
[ "processFilters", "processes", "any", "filters", "valid", "at", "the", "current", "read", "index", "and", "stores", "the", "output", "in", "outbuf", "." ]
197ef08ef68c4454ae5970a9c2692d6056ceb8d7
https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/decode_reader.go#L182-L233
test
nwaples/rardecode
decode_reader.go
fill
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
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 } } }
[ "func", "(", "d", "*", "decodeReader", ")", "fill", "(", ")", "{", "if", "d", ".", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "var", "fl", "[", "]", "*", "filterBlock", "\n", "fl", ",", "d", ".", "err", "=", "d", ".", "dec", ".", "fill", "(", "&", "d", ".", "win", ")", "\n", "for", "_", ",", "f", ":=", "range", "fl", "{", "err", ":=", "d", ".", "queueFilter", "(", "f", ")", "\n", "if", "err", "!=", "nil", "{", "d", ".", "err", "=", "err", "\n", "return", "\n", "}", "\n", "}", "\n", "}" ]
// fill fills the decodeReader's window
[ "fill", "fills", "the", "decodeReader", "s", "window" ]
197ef08ef68c4454ae5970a9c2692d6056ceb8d7
https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/decode_reader.go#L236-L249
test
nwaples/rardecode
decode_reader.go
Read
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
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 }
[ "func", "(", "d", "*", "decodeReader", ")", "Read", "(", "p", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "if", "len", "(", "d", ".", "outbuf", ")", "==", "0", "{", "if", "d", ".", "win", ".", "buffered", "(", ")", "==", "0", "{", "d", ".", "fill", "(", ")", "\n", "if", "d", ".", "win", ".", "buffered", "(", ")", "==", "0", "{", "return", "0", ",", "d", ".", "readErr", "(", ")", "\n", "}", "\n", "}", "else", "if", "len", "(", "d", ".", "filters", ")", ">", "0", "{", "f", ":=", "d", ".", "filters", "[", "0", "]", "\n", "if", "f", ".", "offset", "==", "0", "&&", "f", ".", "length", ">", "d", ".", "win", ".", "buffered", "(", ")", "{", "d", ".", "fill", "(", ")", "\n", "}", "\n", "}", "\n", "if", "len", "(", "d", ".", "filters", ")", ">", "0", "{", "if", "err", ":=", "d", ".", "processFilters", "(", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "len", "(", "d", ".", "outbuf", ")", ">", "0", "{", "n", "=", "copy", "(", "p", ",", "d", ".", "outbuf", ")", "\n", "d", ".", "outbuf", "=", "d", ".", "outbuf", "[", "n", ":", "]", "\n", "}", "else", "if", "len", "(", "d", ".", "filters", ")", ">", "0", "{", "f", ":=", "d", ".", "filters", "[", "0", "]", "\n", "if", "f", ".", "offset", "<", "len", "(", "p", ")", "{", "p", "=", "p", "[", ":", "f", ".", "offset", "]", "\n", "}", "\n", "n", "=", "d", ".", "win", ".", "read", "(", "p", ")", "\n", "f", ".", "offset", "-=", "n", "\n", "}", "else", "{", "n", "=", "d", ".", "win", ".", "read", "(", "p", ")", "\n", "}", "\n", "d", ".", "tot", "+=", "int64", "(", "n", ")", "\n", "return", "n", ",", "nil", "\n", "}" ]
// Read decodes data and stores it in p.
[ "Read", "decodes", "data", "and", "stores", "it", "in", "p", "." ]
197ef08ef68c4454ae5970a9c2692d6056ceb8d7
https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/decode_reader.go#L252-L290
test
nwaples/rardecode
archive.go
readFull
func readFull(r io.Reader, buf []byte) error { _, err := io.ReadFull(r, buf) if err == io.EOF { return io.ErrUnexpectedEOF } return err }
go
func readFull(r io.Reader, buf []byte) error { _, err := io.ReadFull(r, buf) if err == io.EOF { return io.ErrUnexpectedEOF } return err }
[ "func", "readFull", "(", "r", "io", ".", "Reader", ",", "buf", "[", "]", "byte", ")", "error", "{", "_", ",", "err", ":=", "io", ".", "ReadFull", "(", "r", ",", "buf", ")", "\n", "if", "err", "==", "io", ".", "EOF", "{", "return", "io", ".", "ErrUnexpectedEOF", "\n", "}", "\n", "return", "err", "\n", "}" ]
// readFull wraps io.ReadFull to return io.ErrUnexpectedEOF instead // of io.EOF when 0 bytes are read.
[ "readFull", "wraps", "io", ".", "ReadFull", "to", "return", "io", ".", "ErrUnexpectedEOF", "instead", "of", "io", ".", "EOF", "when", "0", "bytes", "are", "read", "." ]
197ef08ef68c4454ae5970a9c2692d6056ceb8d7
https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/archive.go#L85-L91
test
nwaples/rardecode
archive.go
findSig
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
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 }
[ "func", "findSig", "(", "br", "*", "bufio", ".", "Reader", ")", "(", "int", ",", "error", ")", "{", "for", "n", ":=", "0", ";", "n", "<=", "maxSfxSize", ";", "{", "b", ",", "err", ":=", "br", ".", "ReadSlice", "(", "sigPrefix", "[", "0", "]", ")", "\n", "n", "+=", "len", "(", "b", ")", "\n", "if", "err", "==", "bufio", ".", "ErrBufferFull", "{", "continue", "\n", "}", "else", "if", "err", "!=", "nil", "{", "if", "err", "==", "io", ".", "EOF", "{", "err", "=", "errNoSig", "\n", "}", "\n", "return", "0", ",", "err", "\n", "}", "\n", "b", ",", "err", "=", "br", ".", "Peek", "(", "len", "(", "sigPrefix", "[", "1", ":", "]", ")", "+", "2", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "io", ".", "EOF", "{", "err", "=", "errNoSig", "\n", "}", "\n", "return", "0", ",", "err", "\n", "}", "\n", "if", "!", "bytes", ".", "HasPrefix", "(", "b", ",", "[", "]", "byte", "(", "sigPrefix", "[", "1", ":", "]", ")", ")", "{", "continue", "\n", "}", "\n", "b", "=", "b", "[", "len", "(", "sigPrefix", ")", "-", "1", ":", "]", "\n", "var", "ver", "int", "\n", "switch", "{", "case", "b", "[", "0", "]", "==", "0", ":", "ver", "=", "fileFmt15", "\n", "case", "b", "[", "0", "]", "==", "1", "&&", "b", "[", "1", "]", "==", "0", ":", "ver", "=", "fileFmt50", "\n", "default", ":", "continue", "\n", "}", "\n", "_", ",", "_", "=", "br", ".", "ReadSlice", "(", "'\\x00'", ")", "\n", "return", "ver", ",", "nil", "\n", "}", "\n", "return", "0", ",", "errNoSig", "\n", "}" ]
// findSig searches for the RAR signature and version at the beginning of a file. // It searches no more than maxSfxSize bytes.
[ "findSig", "searches", "for", "the", "RAR", "signature", "and", "version", "at", "the", "beginning", "of", "a", "file", ".", "It", "searches", "no", "more", "than", "maxSfxSize", "bytes", "." ]
197ef08ef68c4454ae5970a9c2692d6056ceb8d7
https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/archive.go#L95-L134
test
nwaples/rardecode
vm.go
execute
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
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 } } }
[ "func", "(", "v", "*", "vm", ")", "execute", "(", "cmd", "[", "]", "command", ")", "{", "v", ".", "ip", "=", "0", "\n", "for", "n", ":=", "0", ";", "n", "<", "maxCommands", ";", "n", "++", "{", "ip", ":=", "v", ".", "ip", "\n", "if", "ip", ">=", "uint32", "(", "len", "(", "cmd", ")", ")", "{", "return", "\n", "}", "\n", "ins", ":=", "cmd", "[", "ip", "]", "\n", "ins", ".", "f", "(", "v", ",", "ins", ".", "bm", ",", "ins", ".", "op", ")", "\n", "if", "v", ".", "ipMod", "{", "v", ".", "ipMod", "=", "false", "\n", "}", "else", "{", "v", ".", "ip", "++", "\n", "}", "\n", "}", "\n", "}" ]
// execute runs a list of commands on the vm.
[ "execute", "runs", "a", "list", "of", "commands", "on", "the", "vm", "." ]
197ef08ef68c4454ae5970a9c2692d6056ceb8d7
https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/vm.go#L39-L55
test
nwaples/rardecode
vm.go
newVM
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
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 }
[ "func", "newVM", "(", "mem", "[", "]", "byte", ")", "*", "vm", "{", "v", ":=", "new", "(", "vm", ")", "\n", "if", "cap", "(", "mem", ")", "<", "vmSize", "+", "4", "{", "v", ".", "m", "=", "make", "(", "[", "]", "byte", ",", "vmSize", "+", "4", ")", "\n", "copy", "(", "v", ".", "m", ",", "mem", ")", "\n", "}", "else", "{", "v", ".", "m", "=", "mem", "[", ":", "vmSize", "+", "4", "]", "\n", "for", "i", ":=", "len", "(", "mem", ")", ";", "i", "<", "len", "(", "v", ".", "m", ")", ";", "i", "++", "{", "v", ".", "m", "[", "i", "]", "=", "0", "\n", "}", "\n", "}", "\n", "v", ".", "r", "[", "7", "]", "=", "vmSize", "\n", "return", "v", "\n", "}" ]
// newVM creates a new RAR virtual machine using the byte slice as memory.
[ "newVM", "creates", "a", "new", "RAR", "virtual", "machine", "using", "the", "byte", "slice", "as", "memory", "." ]
197ef08ef68c4454ae5970a9c2692d6056ceb8d7
https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/vm.go#L58-L72
test
nwaples/rardecode
bit_reader.go
limitBitReader
func limitBitReader(br bitReader, n int, err error) bitReader { return &limitedBitReader{br, n, err} }
go
func limitBitReader(br bitReader, n int, err error) bitReader { return &limitedBitReader{br, n, err} }
[ "func", "limitBitReader", "(", "br", "bitReader", ",", "n", "int", ",", "err", "error", ")", "bitReader", "{", "return", "&", "limitedBitReader", "{", "br", ",", "n", ",", "err", "}", "\n", "}" ]
// limitBitReader returns a bitReader that reads from br and stops with io.EOF after n bits. // If br returns an io.EOF before reading n bits, err is returned.
[ "limitBitReader", "returns", "a", "bitReader", "that", "reads", "from", "br", "and", "stops", "with", "io", ".", "EOF", "after", "n", "bits", ".", "If", "br", "returns", "an", "io", ".", "EOF", "before", "reading", "n", "bits", "err", "is", "returned", "." ]
197ef08ef68c4454ae5970a9c2692d6056ceb8d7
https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/bit_reader.go#L18-L20
test
nwaples/rardecode
bit_reader.go
readUint32
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
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 }
[ "func", "(", "r", "*", "rarBitReader", ")", "readUint32", "(", ")", "(", "uint32", ",", "error", ")", "{", "n", ",", "err", ":=", "r", ".", "readBits", "(", "2", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "if", "n", "!=", "1", "{", "n", ",", "err", "=", "r", ".", "readBits", "(", "4", "<<", "uint", "(", "n", ")", ")", "\n", "return", "uint32", "(", "n", ")", ",", "err", "\n", "}", "\n", "n", ",", "err", "=", "r", ".", "readBits", "(", "4", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "if", "n", "==", "0", "{", "n", ",", "err", "=", "r", ".", "readBits", "(", "8", ")", "\n", "n", "|=", "-", "1", "<<", "8", "\n", "return", "uint32", "(", "n", ")", ",", "err", "\n", "}", "\n", "nlow", ",", "err", ":=", "r", ".", "readBits", "(", "4", ")", "\n", "n", "=", "n", "<<", "4", "|", "nlow", "\n", "return", "uint32", "(", "n", ")", ",", "err", "\n", "}" ]
// readUint32 reads a RAR V3 encoded uint32
[ "readUint32", "reads", "a", "RAR", "V3", "encoded", "uint32" ]
197ef08ef68c4454ae5970a9c2692d6056ceb8d7
https://github.com/nwaples/rardecode/blob/197ef08ef68c4454ae5970a9c2692d6056ceb8d7/bit_reader.go#L77-L98
test
kljensen/snowball
russian/step3.go
step3
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
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 }
[ "func", "step3", "(", "word", "*", "snowballword", ".", "SnowballWord", ")", "bool", "{", "suffix", ",", "_", ":=", "word", ".", "RemoveFirstSuffixIn", "(", "word", ".", "R2start", ",", "\"ост\", \"", "о", "ть\")", ")", "\n", "т", "\n", "if", "suffix", "!=", "\"\"", "{", "return", "true", "\n", "}", "\n", "}" ]
// Step 3 is the removal of the derivational suffix. //
[ "Step", "3", "is", "the", "removal", "of", "the", "derivational", "suffix", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/russian/step3.go#L9-L19
test
kljensen/snowball
english/stem.go
Stem
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
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() }
[ "func", "Stem", "(", "word", "string", ",", "stemStopwWords", "bool", ")", "string", "{", "word", "=", "strings", ".", "ToLower", "(", "strings", ".", "TrimSpace", "(", "word", ")", ")", "\n", "if", "len", "(", "word", ")", "<=", "2", "||", "(", "stemStopwWords", "==", "false", "&&", "isStopWord", "(", "word", ")", ")", "{", "return", "word", "\n", "}", "\n", "if", "specialVersion", ":=", "stemSpecialWord", "(", "word", ")", ";", "specialVersion", "!=", "\"\"", "{", "word", "=", "specialVersion", "\n", "return", "word", "\n", "}", "\n", "w", ":=", "snowballword", ".", "New", "(", "word", ")", "\n", "preprocess", "(", "w", ")", "\n", "step0", "(", "w", ")", "\n", "step1a", "(", "w", ")", "\n", "step1b", "(", "w", ")", "\n", "step1c", "(", "w", ")", "\n", "step2", "(", "w", ")", "\n", "step3", "(", "w", ")", "\n", "step4", "(", "w", ")", "\n", "step5", "(", "w", ")", "\n", "postprocess", "(", "w", ")", "\n", "return", "w", ".", "String", "(", ")", "\n", "}" ]
// Stem an English word. This is the only exported // function in this package. //
[ "Stem", "an", "English", "word", ".", "This", "is", "the", "only", "exported", "function", "in", "this", "package", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/english/stem.go#L11-L44
test
kljensen/snowball
french/step6.go
step6
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
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 }
[ "func", "step6", "(", "word", "*", "snowballword", ".", "SnowballWord", ")", "bool", "{", "numNonVowels", ":=", "0", "\n", "for", "i", ":=", "len", "(", "word", ".", "RS", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", "{", "r", ":=", "word", ".", "RS", "[", "i", "]", "\n", "if", "isLowerVowel", "(", "r", ")", "==", "false", "{", "numNonVowels", "+=", "1", "\n", "}", "else", "{", "if", "(", "r", "==", "233", "||", "r", "==", "232", ")", "&&", "numNonVowels", ">", "0", "{", "word", ".", "RS", "[", "i", "]", "=", "101", "\n", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// Step 6 Un-accent //
[ "Step", "6", "Un", "-", "accent" ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/french/step6.go#L9-L42
test
kljensen/snowball
french/step5.go
step5
func step5(word *snowballword.SnowballWord) bool { suffix, _ := word.FirstSuffix("enn", "onn", "ett", "ell", "eill") if suffix != "" { word.RemoveLastNRunes(1) } return false }
go
func step5(word *snowballword.SnowballWord) bool { suffix, _ := word.FirstSuffix("enn", "onn", "ett", "ell", "eill") if suffix != "" { word.RemoveLastNRunes(1) } return false }
[ "func", "step5", "(", "word", "*", "snowballword", ".", "SnowballWord", ")", "bool", "{", "suffix", ",", "_", ":=", "word", ".", "FirstSuffix", "(", "\"enn\"", ",", "\"onn\"", ",", "\"ett\"", ",", "\"ell\"", ",", "\"eill\"", ")", "\n", "if", "suffix", "!=", "\"\"", "{", "word", ".", "RemoveLastNRunes", "(", "1", ")", "\n", "}", "\n", "return", "false", "\n", "}" ]
// Step 5 Undouble non-vowel endings //
[ "Step", "5", "Undouble", "non", "-", "vowel", "endings" ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/french/step5.go#L9-L16
test
kljensen/snowball
spanish/step2a.go
step2a
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
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 }
[ "func", "step2a", "(", "word", "*", "snowballword", ".", "SnowballWord", ")", "bool", "{", "suffix", ",", "suffixRunes", ":=", "word", ".", "FirstSuffixIn", "(", "word", ".", "RVstart", ",", "len", "(", "word", ".", "RS", ")", ",", "\"ya\"", ",", "\"ye\"", ",", "\"yan\"", ",", "\"yen\"", ",", "\"yeron\"", ",", "\"yendo\"", ",", "\"yo\"", ",", "\"yó\",", ",", " ", "yas\",", "y", ",", " ", "yes\",", "y", ")", "\n", ",", "\n", " ", "\n", "}" ]
// Step 2a is the removal of verb suffixes beginning y, // Search for the longest among the following suffixes // in RV, and if found, delete if preceded by u. //
[ "Step", "2a", "is", "the", "removal", "of", "verb", "suffixes", "beginning", "y", "Search", "for", "the", "longest", "among", "the", "following", "suffixes", "in", "RV", "and", "if", "found", "delete", "if", "preceded", "by", "u", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/spanish/step2a.go#L11-L21
test
kljensen/snowball
russian/step4.go
step4
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
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 }
[ "func", "step4", "(", "word", "*", "snowballword", ".", "SnowballWord", ")", "bool", "{", "if", "word", ".", "HasSuffixRunes", "(", "[", "]", "rune", "(", "\"нн\"))", ")", " ", "{", "\n", "{", "word", ".", "RemoveLastNRunes", "(", "1", ")", "\n", "return", "true", "\n", "}", "\n", "suffix", ",", "_", ":=", "word", ".", "RemoveFirstSuffix", "(", "\"ейше\", \"е", "е", "й", ")", "\n", "\")", "\n", "if", "suffix", "!=", "\"\"", "{", "if", "word", ".", "HasSuffixRunes", "(", "[", "]", "rune", "(", "\"нн\"))", ")", " ", "{", "\n", "{", "word", ".", "RemoveLastNRunes", "(", "1", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Step 4 is the undoubling of double non-vowel endings // and removal of superlative endings. //
[ "Step", "4", "is", "the", "undoubling", "of", "double", "non", "-", "vowel", "endings", "and", "removal", "of", "superlative", "endings", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/russian/step4.go#L10-L38
test
kljensen/snowball
snowball.go
Stem
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
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 }
[ "func", "Stem", "(", "word", ",", "language", "string", ",", "stemStopWords", "bool", ")", "(", "stemmed", "string", ",", "err", "error", ")", "{", "var", "f", "func", "(", "string", ",", "bool", ")", "string", "\n", "switch", "language", "{", "case", "\"english\"", ":", "f", "=", "english", ".", "Stem", "\n", "case", "\"spanish\"", ":", "f", "=", "spanish", ".", "Stem", "\n", "case", "\"french\"", ":", "f", "=", "french", ".", "Stem", "\n", "case", "\"russian\"", ":", "f", "=", "russian", ".", "Stem", "\n", "case", "\"swedish\"", ":", "f", "=", "swedish", ".", "Stem", "\n", "case", "\"norwegian\"", ":", "f", "=", "norwegian", ".", "Stem", "\n", "default", ":", "err", "=", "fmt", ".", "Errorf", "(", "\"Unknown language: %s\"", ",", "language", ")", "\n", "return", "\n", "}", "\n", "stemmed", "=", "f", "(", "word", ",", "stemStopWords", ")", "\n", "return", "\n", "}" ]
// Stem a word in the specified language. //
[ "Stem", "a", "word", "in", "the", "specified", "language", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/snowball.go#L20-L43
test
kljensen/snowball
english/step1c.go
step1c
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
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 }
[ "func", "step1c", "(", "w", "*", "snowballword", ".", "SnowballWord", ")", "bool", "{", "rsLen", ":=", "len", "(", "w", ".", "RS", ")", "\n", "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", "\n", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// Step 1c is the normalization of various "y" endings. //
[ "Step", "1c", "is", "the", "normalization", "of", "various", "y", "endings", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/english/step1c.go#L9-L24
test
kljensen/snowball
english/step3.go
step3
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
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 }
[ "func", "step3", "(", "w", "*", "snowballword", ".", "SnowballWord", ")", "bool", "{", "suffix", ",", "suffixRunes", ":=", "w", ".", "FirstSuffix", "(", "\"ational\"", ",", "\"tional\"", ",", "\"alize\"", ",", "\"icate\"", ",", "\"ative\"", ",", "\"iciti\"", ",", "\"ical\"", ",", "\"ful\"", ",", "\"ness\"", ",", ")", "\n", "if", "suffix", "==", "\"\"", "||", "len", "(", "suffixRunes", ")", ">", "len", "(", "w", ".", "RS", ")", "-", "w", ".", "R1start", "{", "return", "false", "\n", "}", "\n", "if", "suffix", "==", "\"ative\"", "{", "if", "len", "(", "w", ".", "RS", ")", "-", "w", ".", "R2start", ">=", "5", "{", "w", ".", "RemoveLastNRunes", "(", "len", "(", "suffixRunes", ")", ")", "\n", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}", "\n", "var", "repl", "string", "\n", "switch", "suffix", "{", "case", "\"ational\"", ":", "repl", "=", "\"ate\"", "\n", "case", "\"tional\"", ":", "repl", "=", "\"tion\"", "\n", "case", "\"alize\"", ":", "repl", "=", "\"al\"", "\n", "case", "\"icate\"", ",", "\"iciti\"", ",", "\"ical\"", ":", "repl", "=", "\"ic\"", "\n", "case", "\"ful\"", ",", "\"ness\"", ":", "repl", "=", "\"\"", "\n", "}", "\n", "w", ".", "ReplaceSuffixRunes", "(", "suffixRunes", ",", "[", "]", "rune", "(", "repl", ")", ",", "true", ")", "\n", "return", "true", "\n", "}" ]
// Step 3 is the stemming of various longer sufficies // found in R1. //
[ "Step", "3", "is", "the", "stemming", "of", "various", "longer", "sufficies", "found", "in", "R1", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/english/step3.go#L10-L56
test
kljensen/snowball
french/common.go
isStopWord
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
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 }
[ "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\",", "m", ",", " ", "moi\",", "m", ",", ",", ",", " ", ",", "mon\",", ",", "m", ",", ",", ",", " ", ",", "ne\",", ",", "n", ",", ",", ",", "\"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\",", ",", "m", ",", " ", "n\",", "n", ",", " ", "s\",", "s", ",", " ", "t\",", "t", ",", ",", ",", " ", ",", "y\",", ",", "y", ",", ",", " ", "été\",", "é", "\"étée\", ", ",", " ", ",", "\"", ",", "tées\", \"é", ",", "t", ",", "é", ",", "t", ",", "s\", \"éta", ",", "s", ",", "a", ",", "n", ",", "\", \"étan", "n", "t", ",", "\", \"étant", "t", "s", ", \"étante", ",", "e", "s", ",", ",", "\"suis\"", "\"es\"", "\"est\"", "\"sommes\"", ",", "\"êtes\",", ",", ",", ",", " ", ",", "sont\",", ",", "s", ",", ",", ",", " ", ",", "serai\",", ",", "s", ",", "\"seras\"", "\"sera\"", "\"serons\"", "\"serez\"", "\"seront\"", "\"serais\"", "\"serait\"", ",", "\"serions\"", ",", "\"seriez\"", ",", "\"seraient\"", ",", "\"étais\",", ",", ",", ",", " ", ",", "était\",", ",", "é", ",", "\"étions\",", ",", ",", ",", " ", ",", "étiez\", ", ",", "é", ",", " ", ",", "\"", ",", "taient\", \"", ",", "t", ",", "f", ",", "s\", \"", ",", "s", ",", "f", ",", "t\", \"", ",", "t", ",", "f", ",", "mes\", \"f", ",", "m", ",", "f", ",", "û", ",", "es\",", ",", "e", "\"furent\"", "\"sois\"", "\"soit\"", "\"soyons\"", "\"soyez\"", "\"soient\"", "\"fusse\"", "\"fusses\"", ",", "\"fût\",", ",", ",", ",", " ", ",", "fussions\",", ",", "f", ",", ",", ",", " ", ",", "fussiez\",", ",", "f", ",", ",", ":", " ", "\n", "}", "\n", "fussent\",", "\n", "}" ]
// Return `true` if the input `word` is a French stop word. //
[ "Return", "true", "if", "the", "input", "word", "is", "a", "French", "stop", "word", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/french/common.go#L10-L36
test
kljensen/snowball
french/common.go
capitalizeYUI
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
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 } }
[ "func", "capitalizeYUI", "(", "word", "*", "snowballword", ".", "SnowballWord", ")", "{", "vowelPreviously", ":=", "false", "\n", "vowelNext", ":=", "func", "(", "j", "int", ")", "bool", "{", "return", "(", "j", "+", "1", "<", "len", "(", "word", ".", "RS", ")", "&&", "isLowerVowel", "(", "word", ".", "RS", "[", "j", "+", "1", "]", ")", ")", "\n", "}", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "word", ".", "RS", ")", ";", "i", "++", "{", "if", "isLowerVowel", "(", "word", ".", "RS", "[", "i", "]", ")", "==", "false", "{", "vowelPreviously", "=", "false", "\n", "continue", "\n", "}", "\n", "vowelHere", ":=", "true", "\n", "switch", "word", ".", "RS", "[", "i", "]", "{", "case", "121", ":", "if", "vowelPreviously", "||", "vowelNext", "(", "i", ")", "{", "word", ".", "RS", "[", "i", "]", "=", "89", "\n", "vowelHere", "=", "false", "\n", "}", "\n", "case", "117", ":", "if", "(", "vowelPreviously", "&&", "vowelNext", "(", "i", ")", ")", "||", "(", "i", ">=", "1", "&&", "word", ".", "RS", "[", "i", "-", "1", "]", "==", "113", ")", "{", "word", ".", "RS", "[", "i", "]", "=", "85", "\n", "vowelHere", "=", "false", "\n", "}", "\n", "case", "105", ":", "if", "vowelPreviously", "&&", "vowelNext", "(", "i", ")", "{", "word", ".", "RS", "[", "i", "]", "=", "73", "\n", "vowelHere", "=", "false", "\n", "}", "\n", "}", "\n", "vowelPreviously", "=", "vowelHere", "\n", "}", "\n", "}" ]
// Capitalize Y, I, and U runes that are acting as consanants. // Put into upper case "u" or "i" preceded and followed by a // vowel, and "y" preceded or followed by a vowel. "u" after q is // also put into upper case. //
[ "Capitalize", "Y", "I", "and", "U", "runes", "that", "are", "acting", "as", "consanants", ".", "Put", "into", "upper", "case", "u", "or", "i", "preceded", "and", "followed", "by", "a", "vowel", "and", "y", "preceded", "or", "followed", "by", "a", "vowel", ".", "u", "after", "q", "is", "also", "put", "into", "upper", "case", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/french/common.go#L57-L105
test
kljensen/snowball
english/step2.go
step2
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
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 }
[ "func", "step2", "(", "w", "*", "snowballword", ".", "SnowballWord", ")", "bool", "{", "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\"", ",", ")", "\n", "if", "suffix", "==", "\"\"", "||", "len", "(", "suffixRunes", ")", ">", "len", "(", "w", ".", "RS", ")", "-", "w", ".", "R1start", "{", "return", "false", "\n", "}", "\n", "switch", "suffix", "{", "case", "\"li\"", ":", "rsLen", ":=", "len", "(", "w", ".", "RS", ")", "\n", "if", "rsLen", ">=", "3", "{", "switch", "w", ".", "RS", "[", "rsLen", "-", "3", "]", "{", "case", "99", ",", "100", ",", "101", ",", "103", ",", "104", ",", "107", ",", "109", ",", "110", ",", "114", ",", "116", ":", "w", ".", "RemoveLastNRunes", "(", "len", "(", "suffixRunes", ")", ")", "\n", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "case", "\"ogi\"", ":", "rsLen", ":=", "len", "(", "w", ".", "RS", ")", "\n", "if", "rsLen", ">=", "4", "&&", "w", ".", "RS", "[", "rsLen", "-", "4", "]", "==", "108", "{", "w", ".", "ReplaceSuffixRunes", "(", "suffixRunes", ",", "[", "]", "rune", "(", "\"og\"", ")", ",", "true", ")", "\n", "}", "\n", "return", "true", "\n", "}", "\n", "var", "repl", "string", "\n", "switch", "suffix", "{", "case", "\"tional\"", ":", "repl", "=", "\"tion\"", "\n", "case", "\"enci\"", ":", "repl", "=", "\"ence\"", "\n", "case", "\"anci\"", ":", "repl", "=", "\"ance\"", "\n", "case", "\"abli\"", ":", "repl", "=", "\"able\"", "\n", "case", "\"entli\"", ":", "repl", "=", "\"ent\"", "\n", "case", "\"izer\"", ",", "\"ization\"", ":", "repl", "=", "\"ize\"", "\n", "case", "\"ational\"", ",", "\"ation\"", ",", "\"ator\"", ":", "repl", "=", "\"ate\"", "\n", "case", "\"alism\"", ",", "\"aliti\"", ",", "\"alli\"", ":", "repl", "=", "\"al\"", "\n", "case", "\"fulness\"", ":", "repl", "=", "\"ful\"", "\n", "case", "\"ousli\"", ",", "\"ousness\"", ":", "repl", "=", "\"ous\"", "\n", "case", "\"iveness\"", ",", "\"iviti\"", ":", "repl", "=", "\"ive\"", "\n", "case", "\"biliti\"", ",", "\"bli\"", ":", "repl", "=", "\"ble\"", "\n", "case", "\"fulli\"", ":", "repl", "=", "\"ful\"", "\n", "case", "\"lessli\"", ":", "repl", "=", "\"less\"", "\n", "}", "\n", "w", ".", "ReplaceSuffixRunes", "(", "suffixRunes", ",", "[", "]", "rune", "(", "repl", ")", ",", "true", ")", "\n", "return", "true", "\n", "}" ]
// Step 2 is the stemming of various endings found in // R1 including "al", "ness", and "li". //
[ "Step", "2", "is", "the", "stemming", "of", "various", "endings", "found", "in", "R1", "including", "al", "ness", "and", "li", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/english/step2.go#L10-L97
test
kljensen/snowball
spanish/step3.go
step3
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
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 }
[ "func", "step3", "(", "word", "*", "snowballword", ".", "SnowballWord", ")", "bool", "{", "suffix", ",", "suffixRunes", ":=", "word", ".", "FirstSuffixIfIn", "(", "word", ".", "RVstart", ",", "len", "(", "word", ".", "RS", ")", ",", "\"os\"", ",", "\"a\"", ",", "\"o\"", ",", "\"á\",", ",", " ", "í\", ", "í", " ", "\"", "\", \"", "e", ",", ")", "\n", ", \"", "\n", ",", "\n", "é", "\n", ",", "\n", "}" ]
// Step 3 is the removal of residual suffixes. //
[ "Step", "3", "is", "the", "removal", "of", "residual", "suffixes", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/spanish/step3.go#L9-L33
test
kljensen/snowball
english/step0.go
step0
func step0(w *snowballword.SnowballWord) bool { suffix, suffixRunes := w.FirstSuffix("'s'", "'s", "'") if suffix == "" { return false } w.RemoveLastNRunes(len(suffixRunes)) return true }
go
func step0(w *snowballword.SnowballWord) bool { suffix, suffixRunes := w.FirstSuffix("'s'", "'s", "'") if suffix == "" { return false } w.RemoveLastNRunes(len(suffixRunes)) return true }
[ "func", "step0", "(", "w", "*", "snowballword", ".", "SnowballWord", ")", "bool", "{", "suffix", ",", "suffixRunes", ":=", "w", ".", "FirstSuffix", "(", "\"'s'\"", ",", "\"'s\"", ",", "\"'\"", ")", "\n", "if", "suffix", "==", "\"\"", "{", "return", "false", "\n", "}", "\n", "w", ".", "RemoveLastNRunes", "(", "len", "(", "suffixRunes", ")", ")", "\n", "return", "true", "\n", "}" ]
// Step 0 is to strip off apostrophes and "s". //
[ "Step", "0", "is", "to", "strip", "off", "apostrophes", "and", "s", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/english/step0.go#L9-L16
test
kljensen/snowball
romance/common.go
VnvSuffix
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
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) }
[ "func", "VnvSuffix", "(", "word", "*", "snowballword", ".", "SnowballWord", ",", "f", "isVowelFunc", ",", "start", "int", ")", "int", "{", "for", "i", ":=", "1", ";", "i", "<", "len", "(", "word", ".", "RS", "[", "start", ":", "]", ")", ";", "i", "++", "{", "j", ":=", "start", "+", "i", "\n", "if", "f", "(", "word", ".", "RS", "[", "j", "-", "1", "]", ")", "&&", "!", "f", "(", "word", ".", "RS", "[", "j", "]", ")", "{", "return", "j", "+", "1", "\n", "}", "\n", "}", "\n", "return", "len", "(", "word", ".", "RS", ")", "\n", "}" ]
// Finds the region after the first non-vowel following a vowel, // or a the null region at the end of the word if there is no // such non-vowel. Returns the index in the Word where the // region starts; optionally skips the first `start` characters. //
[ "Finds", "the", "region", "after", "the", "first", "non", "-", "vowel", "following", "a", "vowel", "or", "a", "the", "null", "region", "at", "the", "end", "of", "the", "word", "if", "there", "is", "no", "such", "non", "-", "vowel", ".", "Returns", "the", "index", "in", "the", "Word", "where", "the", "region", "starts", ";", "optionally", "skips", "the", "first", "start", "characters", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/romance/common.go#L17-L25
test
kljensen/snowball
swedish/step1.go
step1
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
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 }
[ "func", "step1", "(", "w", "*", "snowballword", ".", "SnowballWord", ")", "bool", "{", "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\"", ",", "}", "\n", "suffix", ",", "suffixRunes", ":=", "w", ".", "FirstSuffixIn", "(", "w", ".", "R1start", ",", "len", "(", "w", ".", "RS", ")", ",", "suffixes", "...", ")", "\n", "if", "suffix", "==", "\"\"", "||", "len", "(", "suffixRunes", ")", ">", "len", "(", "w", ".", "RS", ")", "-", "w", ".", "R1start", "{", "return", "false", "\n", "}", "\n", "if", "suffix", "==", "\"s\"", "{", "rsLen", ":=", "len", "(", "w", ".", "RS", ")", "\n", "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", ")", ")", "\n", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}", "\n", "w", ".", "RemoveLastNRunes", "(", "len", "(", "suffixRunes", ")", ")", "\n", "return", "true", "\n", "}" ]
// Step 1 is the stemming of various endings found in // R1 including "heterna", "ornas", and "andet". //
[ "Step", "1", "is", "the", "stemming", "of", "various", "endings", "found", "in", "R1", "including", "heterna", "ornas", "and", "andet", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/swedish/step1.go#L10-L48
test
kljensen/snowball
french/step2a.go
step2a
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
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 }
[ "func", "step2a", "(", "word", "*", "snowballword", ".", "SnowballWord", ")", "bool", "{", "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\", ", "î", " ", "\"", ",", "sse\", ", ",", "s", ",", " ", ",", "\"", ",", "rez\",", "r", "\"iras\"", "\"irai\"", "\"ira\"", "\"ies\"", "\"ît\",", ",", " ", "it\",", "i", ",", ")", "\n", ",", "\n", " ", "\n", "}" ]
// Step 2a is the removal of Verb suffixes beginning // with "i" in the RV region. //
[ "Step", "2a", "is", "the", "removal", "of", "Verb", "suffixes", "beginning", "with", "i", "in", "the", "RV", "region", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/french/step2a.go#L10-L31
test
kljensen/snowball
russian/step1.go
removePerfectiveGerundEnding
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
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 }
[ "func", "removePerfectiveGerundEnding", "(", "word", "*", "snowballword", ".", "SnowballWord", ")", "bool", "{", "suffix", ",", "suffixRunes", ":=", "word", ".", "FirstSuffixIn", "(", "word", ".", "RVstart", ",", "len", "(", "word", ".", "RS", ")", ",", "\"ившись\", \"ывш", "ш", "и", "ь\", \"вшись\", \"", "ь", "и", "ши\", \"ывши\",", ",", "ш", ",", "interpreted_string_literal", ",", "interpreted_string_literal", ",", "interpreted_string_literal", ",", "interpreted_string_literal", ",", ")", "\n", ",", "\n", " ", "\n", "вши\", \"ив\"", "\n", "}" ]
// Remove perfective gerund endings and return true if one was removed. //
[ "Remove", "perfective", "gerund", "endings", "and", "return", "true", "if", "one", "was", "removed", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/russian/step1.go#L60-L80
test
kljensen/snowball
russian/step1.go
removeAdjectivalEnding
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
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 }
[ "func", "removeAdjectivalEnding", "(", "word", "*", "snowballword", ".", "SnowballWord", ")", "bool", "{", "suffix", ",", "_", ":=", "word", ".", "RemoveFirstSuffixIn", "(", "word", ".", "RVstart", ",", "\"ими\", \"", "ы", "и\", \"его", "и", "о", "\"", " \"ого\", ", " ", " ", "\"", "му\", \"ом", ",", "interpreted_string_literal", ",", "interpreted_string_literal", ",", "м", "м", "у", ", \"ее\", ", ",", ",", " ", "\"", "е\",", "е", "\"ые\", ", ",", " ", ",", "interpreted_string_literal", ",", "interpreted_string_literal", ",", "\"", "е\", \"е", "е", "е", "й", ",", ", \"ий\"", ",", "\"ый\", ", " ", "\"", ",", "й\", \"е", ",", "interpreted_string_literal", ",", "interpreted_string_literal", ",", ")", "\n", "й", "\n", "е", "\n", "}" ]
// Remove adjectival endings and return true if one was removed. //
[ "Remove", "adjectival", "endings", "and", "return", "true", "if", "one", "was", "removed", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/russian/step1.go#L84-L118
test
kljensen/snowball
spanish/step2b.go
step2b
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
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 }
[ "func", "step2b", "(", "word", "*", "snowballword", ".", "SnowballWord", ")", "bool", "{", "suffix", ",", "suffixRunes", ":=", "word", ".", "FirstSuffixIn", "(", "word", ".", "RVstart", ",", "len", "(", "word", ".", "RS", ")", ",", "\"iésemos\",", ",", " ", "iéramos\", ", "i", " ", "\"", "ríamos\", \"", "r", "e", "íamos\", \"a", ",", "í", "a", "r", "amos\", \"ás", "a", "s", "e", "os\",", "o", "\"áramos\",", ",", ",", " ", ",", "ábamos\", ", "á", " ", "\"", "steis\", ", "s", " ", "\"", "ríais\", \"", ",", "r", "i", "emos\", \"", "e", "i", "seis\",", "s", "\"ierais\"", "\"eríais\",", ",", " ", "eremos\",", "e", ",", ",", ",", " ", ",", "asteis\",", ",", "a", ",", " ", "aríais\", ", "a", " ", "\"", ",", "remos\",", "r", "\"íamos\",", ",", " ", "irías\", ", "i", " ", "\"", "rían\", \"", "r", "i", "éis\", \"i", ",", "é", "i", "e", "es\", \"i", "e", "i", "e", "en\", \"i", "e", "i", "e", "on\",", "o", "\"ieras\"", "\"ieran\"", ",", "\"iendo\"", "\"erías\",", ",", " ", "erían\", ", "e", " ", "\"", "réis\", \"", "r", "a", "eis\",", "e", "\"arías\",", ",", ",", " ", "arían\", ", "a", " ", "\"", "réis\", \"", "r", "a", "ais\", \"", "a", "a", "ais\", \"", "a", "í", "is\", \"i", ",", "i", ",", "i", ",", "s", "e\",", "e", "\"iría\",", ",", " ", "irás\", ", "i", " ", "\"", "rán\", \"", "r", "interpreted_string_literal", ",", "i", ",", "os\", \"", "o", "i", "se\", \"", "s", "i", "ra\", \"", "r", "i", "os\", \"", "o", "i", "as\",", "a", "\"ería\",", ",", ",", ",", " ", ",", "erás\", ", "e", " ", "\"", "rán\", \"", "r", "a", "te\", \"", "t", "a", "es\", \"", "e", "a", "en\", \"", "e", ",", "a", ",", "ía\", \"a", ",", "í", ",", "a", ",", "r", ",", ")", "\n", "s\",", "\n", "s", "\n", "}" ]
// Step 2b is the removal of verb suffixes beginning y, // Search for the longest among the following suffixes // in RV, and if found, delete if preceded by u. //
[ "Step", "2b", "is", "the", "removal", "of", "verb", "suffixes", "beginning", "y", "Search", "for", "the", "longest", "among", "the", "following", "suffixes", "in", "RV", "and", "if", "found", "delete", "if", "preceded", "by", "u", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/spanish/step2b.go#L11-L46
test
kljensen/snowball
french/step4.go
step4
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
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 }
[ "func", "step4", "(", "word", "*", "snowballword", ".", "SnowballWord", ")", "bool", "{", "hadChange", ":=", "false", "\n", "if", "word", ".", "String", "(", ")", "==", "\"voudrion\"", "{", "log", ".", "Println", "(", "\"...\"", ",", "word", ")", "\n", "}", "\n", "if", "idx", ":=", "len", "(", "word", ".", "RS", ")", "-", "1", ";", "idx", ">=", "1", "&&", "word", ".", "RS", "[", "idx", "]", "==", "115", "{", "switch", "word", ".", "RS", "[", "idx", "-", "1", "]", "{", "case", "97", ",", "105", ",", "111", ",", "117", ",", "232", ",", "115", ":", "return", "false", "\n", "default", ":", "word", ".", "RemoveLastNRunes", "(", "1", ")", "\n", "hadChange", "=", "true", "\n", "}", "\n", "}", "\n", "suffix", ",", "suffixRunes", ":=", "word", ".", "FirstSuffixIn", "(", "word", ".", "RVstart", ",", "len", "(", "word", ".", "RS", ")", ",", "\"Ière\",", ",", " ", "ière\", ", "i", " ", "\"", "er\", ", "e", " ", "\"", "er\", ", "e", ",", ")", "\n", " ", "\n", "\"", "\n", "}" ]
// Step 4 is the cleaning up of residual suffixes. //
[ "Step", "4", "is", "the", "cleaning", "up", "of", "residual", "suffixes", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/french/step4.go#L10-L82
test
kljensen/snowball
english/step5.go
step5
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
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 }
[ "func", "step5", "(", "w", "*", "snowballword", ".", "SnowballWord", ")", "bool", "{", "lri", ":=", "len", "(", "w", ".", "RS", ")", "-", "1", "\n", "if", "w", ".", "R1start", ">", "lri", "{", "return", "false", "\n", "}", "\n", "if", "w", ".", "RS", "[", "lri", "]", "==", "101", "{", "if", "w", ".", "R2start", "<=", "lri", "||", "!", "endsShortSyllable", "(", "w", ",", "lri", ")", "{", "w", ".", "ReplaceSuffix", "(", "\"e\"", ",", "\"\"", ",", "true", ")", "\n", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}", "else", "if", "w", ".", "R2start", "<=", "lri", "&&", "w", ".", "RS", "[", "lri", "]", "==", "108", "&&", "lri", "-", "1", ">=", "0", "&&", "w", ".", "RS", "[", "lri", "-", "1", "]", "==", "108", "{", "w", ".", "ReplaceSuffix", "(", "\"l\"", ",", "\"\"", ",", "true", ")", "\n", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// Step 5 is the stemming of "e" and "l" sufficies // found in R2. //
[ "Step", "5", "is", "the", "stemming", "of", "e", "and", "l", "sufficies", "found", "in", "R2", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/english/step5.go#L10-L45
test
kljensen/snowball
spanish/stem.go
Stem
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
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() }
[ "func", "Stem", "(", "word", "string", ",", "stemStopwWords", "bool", ")", "string", "{", "word", "=", "strings", ".", "ToLower", "(", "strings", ".", "TrimSpace", "(", "word", ")", ")", "\n", "if", "len", "(", "word", ")", "<=", "2", "||", "(", "stemStopwWords", "==", "false", "&&", "isStopWord", "(", "word", ")", ")", "{", "return", "word", "\n", "}", "\n", "w", ":=", "snowballword", ".", "New", "(", "word", ")", "\n", "preprocess", "(", "w", ")", "\n", "step0", "(", "w", ")", "\n", "changeInStep1", ":=", "step1", "(", "w", ")", "\n", "if", "changeInStep1", "==", "false", "{", "changeInStep2a", ":=", "step2a", "(", "w", ")", "\n", "if", "changeInStep2a", "==", "false", "{", "step2b", "(", "w", ")", "\n", "}", "\n", "}", "\n", "step3", "(", "w", ")", "\n", "postprocess", "(", "w", ")", "\n", "return", "w", ".", "String", "(", ")", "\n", "}" ]
// Stem an Spanish word. This is the only exported // function in this package. //
[ "Stem", "an", "Spanish", "word", ".", "This", "is", "the", "only", "exported", "function", "in", "this", "package", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/spanish/stem.go#L18-L47
test
kljensen/snowball
russian/stem.go
Stem
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
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() }
[ "func", "Stem", "(", "word", "string", ",", "stemStopwWords", "bool", ")", "string", "{", "word", "=", "strings", ".", "ToLower", "(", "strings", ".", "TrimSpace", "(", "word", ")", ")", "\n", "w", ":=", "snowballword", ".", "New", "(", "word", ")", "\n", "if", "len", "(", "w", ".", "RS", ")", "<=", "2", "||", "(", "stemStopwWords", "==", "false", "&&", "isStopWord", "(", "word", ")", ")", "{", "return", "word", "\n", "}", "\n", "preprocess", "(", "w", ")", "\n", "step1", "(", "w", ")", "\n", "step2", "(", "w", ")", "\n", "step3", "(", "w", ")", "\n", "step4", "(", "w", ")", "\n", "return", "w", ".", "String", "(", ")", "\n", "}" ]
// Stem an Russian word. This is the only exported // function in this package. //
[ "Stem", "an", "Russian", "word", ".", "This", "is", "the", "only", "exported", "function", "in", "this", "package", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/russian/stem.go#L11-L28
test
kljensen/snowball
norwegian/common.go
isStopWord
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
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 }
[ "func", "isStopWord", "(", "word", "string", ")", "bool", "{", "switch", "word", "{", "case", "\"ut\"", ",", "\"få\",", ",", " ", "hadde\",", "h", ",", " ", "hva\",", "h", ",", " ", "tilbake\",", "t", ",", " ", "vil\",", "v", ",", " ", "han\",", "h", ",", ",", ",", " ", ",", "meget\",", ",", "m", ",", ",", ",", " ", ",", "men\",", ",", "m", ",", " ", "vi\",", "v", ",", " ", ",", "en\",", "e", ",", " ", "før\",", "f", "\"samme\"", "\"stille\"", "\"inn\"", "\"er\"", "\"kan\"", "\"makt\"", "\"ved\"", "\"forsøke\",", ",", " ", "hvis\",", "h", ",", " ", "part\",", "p", ",", ",", " ", ",", "rett\",", ",", "r", ",", ",", ",", "\"måte\",", ",", ",", ",", " ", ",", "denne\",", ",", "d", ",", ",", ",", " ", ",", "mer\",", ",", "m", ",", ",", ",", " ", "i\",", "i", ",", " ", "lang\",", "l", ",", " ", "ny\",", "n", ",", " ", "hans\",", "h", ",", ",", " ", "hvilken\",", "h", ",", " ", "tid\",", "t", ",", " ", "vite\",", "v", ",", " ", "her\",", "h", ",", " ", "opp\",", "o", ",", "\"var\"", "\"navn\"", ",", "\"mye\"", ",", "\"om\"", ",", "\"sant\"", ",", "\"tilstand\"", "\"der\"", "\"ikke\"", "\"mest\"", "\"punkt\"", "\"hvem\"", "\"skulle\"", "\"mange\"", "\"over\"", "\"vårt\",", ",", " ", "alle\",", "a", ",", " ", "arbeid\",", ",", "a", ",", ",", " ", "lik\",", "l", ",", " ", "like\",", "l", ",", " ", "gå\", ", "g", " ", "\"", "år\", \"", "å", "s", "den\",", "d", "\"å\",", ",", ",", " ", "begge\",", "b", ",", " ", "bruke\",", "b", ",", " ", "eller\",", "e", ",", " ", "og\",", "o", ",", " ", "til\",", "t", ",", " ", "da\",", "d", ",", " ", ",", "et\",", ",", "e", ",", ",", ",", " ", ",", "hvorfor\",", ",", "h", ",", " ", "nå\", ", "n", " ", "\"", "ist\", ", "i", " ", "\"", "lutt\",", "l", "\"deres\"", "\"det\"", ":", "\"hennes\"", "\n", "}", "\n", "\"så\",", "\n", "}" ]
// Return `true` if the input `word` is a Norwegian stop word. //
[ "Return", "true", "if", "the", "input", "word", "is", "a", "Norwegian", "stop", "word", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/norwegian/common.go#L37-L52
test
kljensen/snowball
swedish/common.go
isStopWord
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
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 }
[ "func", "isStopWord", "(", "word", "string", ")", "bool", "{", "switch", "word", "{", "case", "\"och\"", ",", "\"det\"", ",", "\"att\"", ",", "\"i\"", ",", "\"en\"", ",", "\"jag\"", ",", "\"hon\"", ",", "\"som\"", ",", "\"han\"", ",", "\"på\",", ",", " ", "den\",", "d", ",", " ", "med\",", "m", ",", " ", "var\",", "v", ",", " ", "sig\",", "s", ",", " ", ",", "för\", ", ",", "f", ",", " ", ",", "\"", ",", "å\", \"", ",", "å", ",", "t", ",", "ll\", \"", ",", "l", ",", "ä", ",", "\", \"m", ",", "m", ",", "e", ",", "\",", ",", "\"ett\"", ",", "\"om\"", ",", "\"hade\"", ",", "\"de\"", ",", "\"av\"", "\"icke\"", "\"mig\"", "\"du\"", "\"henne\"", "\"då\",", ",", "\"sin\"", "\"nu\"", "\"har\"", "\"inte\"", "\"hans\"", "\"honom\"", "\"skulle\"", "\"hennes\"", "\"där\",", ",", ",", " ", "min\",", "m", ",", " ", "man\",", "m", ",", " ", "ej\",", "e", ",", " ", "vid\",", "v", ",", " ", ",", "kunde\",", ",", "k", ",", ",", ",", " ", "något\", ", "n", " ", "\"", "rån\", \"", "r", "u", "\",", "\"när\",", ",", ",", " ", ",", "efter\",", ",", "e", ",", ",", ",", " ", ",", "upp\",", ",", "u", ",", " ", ",", "vi\",", "v", ",", " ", "dem\",", "d", ",", " ", "vara\",", "v", ",", " ", "vad\",", "v", ",", " ", "över\", ", ",", "ö", ",", " ", ",", "\"", ",", "n\",", "n", "\"dig\"", "\"kan\"", "\"sina\"", "\"här\",", ",", " ", "ha\",", ",", "h", ",", ",", ",", " ", "mot\",", "m", ",", " ", "alla\",", "a", ",", " ", "under\",", "u", ",", ",", " ", "någon\",", "n", "\"eller\"", "\"allt\"", "\"mycket\"", "\"sedan\"", "\"ju\"", "\"denna\"", "\"själv\",", ",", " ", ",", "detta\",", ",", "d", ",", "\"åt\",", ",", " ", "utan\",", "u", ",", " ", "varit\",", "v", ",", ",", ",", " ", ",", "hur\",", ":", "h", "\n", "}", "\n", ",", "\n", "}" ]
// Return `true` if the input `word` is a Swedish stop word. //
[ "Return", "true", "if", "the", "input", "word", "is", "a", "Swedish", "stop", "word", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/swedish/common.go#L37-L56
test
kljensen/snowball
snowballword/snowballword.go
New
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
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 }
[ "func", "New", "(", "in", "string", ")", "(", "word", "*", "SnowballWord", ")", "{", "word", "=", "&", "SnowballWord", "{", "RS", ":", "[", "]", "rune", "(", "in", ")", "}", "\n", "word", ".", "R1start", "=", "len", "(", "word", ".", "RS", ")", "\n", "word", ".", "R2start", "=", "len", "(", "word", ".", "RS", ")", "\n", "word", ".", "RVstart", "=", "len", "(", "word", ".", "RS", ")", "\n", "return", "\n", "}" ]
// Create a new SnowballWord struct
[ "Create", "a", "new", "SnowballWord", "struct" ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/snowballword/snowballword.go#L31-L37
test
kljensen/snowball
snowballword/snowballword.go
RemoveLastNRunes
func (w *SnowballWord) RemoveLastNRunes(n int) { w.RS = w.RS[:len(w.RS)-n] w.resetR1R2() }
go
func (w *SnowballWord) RemoveLastNRunes(n int) { w.RS = w.RS[:len(w.RS)-n] w.resetR1R2() }
[ "func", "(", "w", "*", "SnowballWord", ")", "RemoveLastNRunes", "(", "n", "int", ")", "{", "w", ".", "RS", "=", "w", ".", "RS", "[", ":", "len", "(", "w", ".", "RS", ")", "-", "n", "]", "\n", "w", ".", "resetR1R2", "(", ")", "\n", "}" ]
// Remove the last `n` runes from the SnowballWord. //
[ "Remove", "the", "last", "n", "runes", "from", "the", "SnowballWord", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/snowballword/snowballword.go#L67-L70
test
kljensen/snowball
snowballword/snowballword.go
resetR1R2
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
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 } }
[ "func", "(", "w", "*", "SnowballWord", ")", "resetR1R2", "(", ")", "{", "rsLen", ":=", "len", "(", "w", ".", "RS", ")", "\n", "if", "w", ".", "R1start", ">", "rsLen", "{", "w", ".", "R1start", "=", "rsLen", "\n", "}", "\n", "if", "w", ".", "R2start", ">", "rsLen", "{", "w", ".", "R2start", "=", "rsLen", "\n", "}", "\n", "if", "w", ".", "RVstart", ">", "rsLen", "{", "w", ".", "RVstart", "=", "rsLen", "\n", "}", "\n", "}" ]
// Resets R1start and R2start to ensure they // are within bounds of the current rune slice.
[ "Resets", "R1start", "and", "R2start", "to", "ensure", "they", "are", "within", "bounds", "of", "the", "current", "rune", "slice", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/snowballword/snowballword.go#L93-L104
test
kljensen/snowball
snowballword/snowballword.go
slice
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
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] }
[ "func", "(", "w", "*", "SnowballWord", ")", "slice", "(", "start", ",", "stop", "int", ")", "[", "]", "rune", "{", "startMin", ":=", "0", "\n", "if", "start", "<", "startMin", "{", "start", "=", "startMin", "\n", "}", "\n", "max", ":=", "len", "(", "w", ".", "RS", ")", "-", "1", "\n", "if", "start", ">", "max", "{", "start", "=", "max", "\n", "}", "\n", "if", "stop", ">", "max", "{", "stop", "=", "max", "\n", "}", "\n", "return", "w", ".", "RS", "[", "start", ":", "stop", "]", "\n", "}" ]
// Return a slice of w.RS, allowing the start // and stop to be out of bounds. //
[ "Return", "a", "slice", "of", "w", ".", "RS", "allowing", "the", "start", "and", "stop", "to", "be", "out", "of", "bounds", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/snowballword/snowballword.go#L109-L122
test
kljensen/snowball
snowballword/snowballword.go
FitsInR1
func (w *SnowballWord) FitsInR1(x int) bool { return w.R1start <= len(w.RS)-x }
go
func (w *SnowballWord) FitsInR1(x int) bool { return w.R1start <= len(w.RS)-x }
[ "func", "(", "w", "*", "SnowballWord", ")", "FitsInR1", "(", "x", "int", ")", "bool", "{", "return", "w", ".", "R1start", "<=", "len", "(", "w", ".", "RS", ")", "-", "x", "\n", "}" ]
// Returns true if `x` runes would fit into R1. //
[ "Returns", "true", "if", "x", "runes", "would", "fit", "into", "R1", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/snowballword/snowballword.go#L126-L128
test
kljensen/snowball
snowballword/snowballword.go
FitsInR2
func (w *SnowballWord) FitsInR2(x int) bool { return w.R2start <= len(w.RS)-x }
go
func (w *SnowballWord) FitsInR2(x int) bool { return w.R2start <= len(w.RS)-x }
[ "func", "(", "w", "*", "SnowballWord", ")", "FitsInR2", "(", "x", "int", ")", "bool", "{", "return", "w", ".", "R2start", "<=", "len", "(", "w", ".", "RS", ")", "-", "x", "\n", "}" ]
// Returns true if `x` runes would fit into R2. //
[ "Returns", "true", "if", "x", "runes", "would", "fit", "into", "R2", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/snowballword/snowballword.go#L132-L134
test
kljensen/snowball
snowballword/snowballword.go
FitsInRV
func (w *SnowballWord) FitsInRV(x int) bool { return w.RVstart <= len(w.RS)-x }
go
func (w *SnowballWord) FitsInRV(x int) bool { return w.RVstart <= len(w.RS)-x }
[ "func", "(", "w", "*", "SnowballWord", ")", "FitsInRV", "(", "x", "int", ")", "bool", "{", "return", "w", ".", "RVstart", "<=", "len", "(", "w", ".", "RS", ")", "-", "x", "\n", "}" ]
// Returns true if `x` runes would fit into RV. //
[ "Returns", "true", "if", "x", "runes", "would", "fit", "into", "RV", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/snowballword/snowballword.go#L138-L140
test
kljensen/snowball
snowballword/snowballword.go
FirstPrefix
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
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 }
[ "func", "(", "w", "*", "SnowballWord", ")", "FirstPrefix", "(", "prefixes", "...", "string", ")", "(", "foundPrefix", "string", ",", "foundPrefixRunes", "[", "]", "rune", ")", "{", "found", ":=", "false", "\n", "rsLen", ":=", "len", "(", "w", ".", "RS", ")", "\n", "for", "_", ",", "prefix", ":=", "range", "prefixes", "{", "prefixRunes", ":=", "[", "]", "rune", "(", "prefix", ")", "\n", "if", "len", "(", "prefixRunes", ")", ">", "rsLen", "{", "continue", "\n", "}", "\n", "found", "=", "true", "\n", "for", "i", ",", "r", ":=", "range", "prefixRunes", "{", "if", "i", ">", "rsLen", "-", "1", "||", "(", "w", ".", "RS", ")", "[", "i", "]", "!=", "r", "{", "found", "=", "false", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "found", "{", "foundPrefix", "=", "prefix", "\n", "foundPrefixRunes", "=", "prefixRunes", "\n", "break", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// Return the first prefix found or the empty string.
[ "Return", "the", "first", "prefix", "found", "or", "the", "empty", "string", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/snowballword/snowballword.go#L182-L206
test
kljensen/snowball
snowballword/snowballword.go
HasSuffixRunes
func (w *SnowballWord) HasSuffixRunes(suffixRunes []rune) bool { return w.HasSuffixRunesIn(0, len(w.RS), suffixRunes) }
go
func (w *SnowballWord) HasSuffixRunes(suffixRunes []rune) bool { return w.HasSuffixRunesIn(0, len(w.RS), suffixRunes) }
[ "func", "(", "w", "*", "SnowballWord", ")", "HasSuffixRunes", "(", "suffixRunes", "[", "]", "rune", ")", "bool", "{", "return", "w", ".", "HasSuffixRunesIn", "(", "0", ",", "len", "(", "w", ".", "RS", ")", ",", "suffixRunes", ")", "\n", "}" ]
// Return true if `w` ends with `suffixRunes` //
[ "Return", "true", "if", "w", "ends", "with", "suffixRunes" ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/snowballword/snowballword.go#L235-L237
test
kljensen/snowball
snowballword/snowballword.go
FirstSuffixIfIn
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
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 }
[ "func", "(", "w", "*", "SnowballWord", ")", "FirstSuffixIfIn", "(", "startPos", ",", "endPos", "int", ",", "suffixes", "...", "string", ")", "(", "suffix", "string", ",", "suffixRunes", "[", "]", "rune", ")", "{", "for", "_", ",", "suffix", ":=", "range", "suffixes", "{", "suffixRunes", ":=", "[", "]", "rune", "(", "suffix", ")", "\n", "if", "w", ".", "HasSuffixRunesIn", "(", "0", ",", "endPos", ",", "suffixRunes", ")", "{", "if", "endPos", "-", "len", "(", "suffixRunes", ")", ">=", "startPos", "{", "return", "suffix", ",", "suffixRunes", "\n", "}", "else", "{", "suffixRunes", "=", "suffixRunes", "[", ":", "0", "]", "\n", "return", "\"\"", ",", "suffixRunes", "\n", "}", "\n", "}", "\n", "}", "\n", "suffixRunes", "=", "suffixRunes", "[", ":", "0", "]", "\n", "return", "\"\"", ",", "suffixRunes", "\n", "}" ]
// Find the first suffix that ends at `endPos` in the word among // those provided; then, // check to see if it begins after startPos. If it does, return // it, else return the empty string and empty rune slice. This // may seem a counterintuitive manner to do this. However, it // matches what is required most of the time by the Snowball // stemmer steps. //
[ "Find", "the", "first", "suffix", "that", "ends", "at", "endPos", "in", "the", "word", "among", "those", "provided", ";", "then", "check", "to", "see", "if", "it", "begins", "after", "startPos", ".", "If", "it", "does", "return", "it", "else", "return", "the", "empty", "string", "and", "empty", "rune", "slice", ".", "This", "may", "seem", "a", "counterintuitive", "manner", "to", "do", "this", ".", "However", "it", "matches", "what", "is", "required", "most", "of", "the", "time", "by", "the", "Snowball", "stemmer", "steps", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/snowballword/snowballword.go#L247-L264
test
kljensen/snowball
snowballword/snowballword.go
RemoveFirstSuffixIfIn
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
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 }
[ "func", "(", "w", "*", "SnowballWord", ")", "RemoveFirstSuffixIfIn", "(", "startPos", "int", ",", "suffixes", "...", "string", ")", "(", "suffix", "string", ",", "suffixRunes", "[", "]", "rune", ")", "{", "suffix", ",", "suffixRunes", "=", "w", ".", "FirstSuffixIfIn", "(", "startPos", ",", "len", "(", "w", ".", "RS", ")", ",", "suffixes", "...", ")", "\n", "if", "suffix", "!=", "\"\"", "{", "w", ".", "RemoveLastNRunes", "(", "len", "(", "suffixRunes", ")", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Find the first suffix in the word among those provided; then, // check to see if it begins after startPos. If it does, // remove it. //
[ "Find", "the", "first", "suffix", "in", "the", "word", "among", "those", "provided", ";", "then", "check", "to", "see", "if", "it", "begins", "after", "startPos", ".", "If", "it", "does", "remove", "it", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/snowballword/snowballword.go#L283-L289
test
kljensen/snowball
snowballword/snowballword.go
RemoveFirstSuffix
func (w *SnowballWord) RemoveFirstSuffix(suffixes ...string) (suffix string, suffixRunes []rune) { return w.RemoveFirstSuffixIn(0, suffixes...) }
go
func (w *SnowballWord) RemoveFirstSuffix(suffixes ...string) (suffix string, suffixRunes []rune) { return w.RemoveFirstSuffixIn(0, suffixes...) }
[ "func", "(", "w", "*", "SnowballWord", ")", "RemoveFirstSuffix", "(", "suffixes", "...", "string", ")", "(", "suffix", "string", ",", "suffixRunes", "[", "]", "rune", ")", "{", "return", "w", ".", "RemoveFirstSuffixIn", "(", "0", ",", "suffixes", "...", ")", "\n", "}" ]
// Removes the first suffix found
[ "Removes", "the", "first", "suffix", "found" ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/snowballword/snowballword.go#L301-L303
test
kljensen/snowball
snowballword/snowballword.go
FirstSuffix
func (w *SnowballWord) FirstSuffix(suffixes ...string) (suffix string, suffixRunes []rune) { return w.FirstSuffixIfIn(0, len(w.RS), suffixes...) }
go
func (w *SnowballWord) FirstSuffix(suffixes ...string) (suffix string, suffixRunes []rune) { return w.FirstSuffixIfIn(0, len(w.RS), suffixes...) }
[ "func", "(", "w", "*", "SnowballWord", ")", "FirstSuffix", "(", "suffixes", "...", "string", ")", "(", "suffix", "string", ",", "suffixRunes", "[", "]", "rune", ")", "{", "return", "w", ".", "FirstSuffixIfIn", "(", "0", ",", "len", "(", "w", ".", "RS", ")", ",", "suffixes", "...", ")", "\n", "}" ]
// Return the first suffix found or the empty string.
[ "Return", "the", "first", "suffix", "found", "or", "the", "empty", "string", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/snowballword/snowballword.go#L306-L308
test
kljensen/snowball
english/preprocess.go
preprocess
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
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 }
[ "func", "preprocess", "(", "word", "*", "snowballword", ".", "SnowballWord", ")", "{", "normalizeApostrophes", "(", "word", ")", "\n", "trimLeftApostrophes", "(", "word", ")", "\n", "capitalizeYs", "(", "word", ")", "\n", "r1start", ",", "r2start", ":=", "r1r2", "(", "word", ")", "\n", "word", ".", "R1start", "=", "r1start", "\n", "word", ".", "R2start", "=", "r2start", "\n", "}" ]
// Applies various transformations necessary for the // other, subsequent stemming steps. Most important // of which is defining the two regions R1 & R2. //
[ "Applies", "various", "transformations", "necessary", "for", "the", "other", "subsequent", "stemming", "steps", ".", "Most", "important", "of", "which", "is", "defining", "the", "two", "regions", "R1", "&", "R2", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/english/preprocess.go#L11-L25
test
kljensen/snowball
spanish/step0.go
step0
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
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 }
[ "func", "step0", "(", "word", "*", "snowballword", ".", "SnowballWord", ")", "bool", "{", "suffix1", ",", "suffix1Runes", ":=", "word", ".", "FirstSuffixIn", "(", "word", ".", "RVstart", ",", "len", "(", "word", ".", "RS", ")", ",", "\"selas\"", ",", "\"selos\"", ",", "\"sela\"", ",", "\"selo\"", ",", "\"las\"", ",", "\"les\"", ",", "\"los\"", ",", "\"nos\"", ",", "\"me\"", ",", "\"se\"", ",", "\"la\"", ",", "\"le\"", ",", "\"lo\"", ",", ")", "\n", "if", "suffix1", "==", "\"\"", "{", "return", "false", "\n", "}", "\n", "suffix2", ",", "suffix2Runes", ":=", "word", ".", "FirstSuffixIn", "(", "word", ".", "RVstart", ",", "len", "(", "word", ".", "RS", ")", "-", "len", "(", "suffix1", ")", ",", "\"iéndo\",", ",", " ", "iendo\",", "i", ",", " ", "yendo\",", "y", ",", ",", " ", "ando\",", "a", ",", " ", "ándo\",", "á", "\"ár\",", ",", " ", ",", ")", "\n", "ér\", ", "\n", "é", "\n", "}" ]
// Step 0 is the removal of attached pronouns //
[ "Step", "0", "is", "the", "removal", "of", "attached", "pronouns" ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/spanish/step0.go#L9-L74
test
kljensen/snowball
english/step1b.go
step1b
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
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 }
[ "func", "step1b", "(", "w", "*", "snowballword", ".", "SnowballWord", ")", "bool", "{", "suffix", ",", "suffixRunes", ":=", "w", ".", "FirstSuffix", "(", "\"eedly\"", ",", "\"ingly\"", ",", "\"edly\"", ",", "\"ing\"", ",", "\"eed\"", ",", "\"ed\"", ")", "\n", "switch", "suffix", "{", "case", "\"\"", ":", "return", "false", "\n", "case", "\"eed\"", ",", "\"eedly\"", ":", "if", "len", "(", "suffixRunes", ")", "<=", "len", "(", "w", ".", "RS", ")", "-", "w", ".", "R1start", "{", "w", ".", "ReplaceSuffixRunes", "(", "suffixRunes", ",", "[", "]", "rune", "(", "\"ee\"", ")", ",", "true", ")", "\n", "}", "\n", "return", "true", "\n", "case", "\"ed\"", ",", "\"edly\"", ",", "\"ing\"", ",", "\"ingly\"", ":", "hasLowerVowel", ":=", "false", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "w", ".", "RS", ")", "-", "len", "(", "suffixRunes", ")", ";", "i", "++", "{", "if", "isLowerVowel", "(", "w", ".", "RS", "[", "i", "]", ")", "{", "hasLowerVowel", "=", "true", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "hasLowerVowel", "{", "originalR1start", ":=", "w", ".", "R1start", "\n", "originalR2start", ":=", "w", ".", "R2start", "\n", "w", ".", "RemoveLastNRunes", "(", "len", "(", "suffixRunes", ")", ")", "\n", "newSuffix", ",", "newSuffixRunes", ":=", "w", ".", "FirstSuffix", "(", "\"at\"", ",", "\"bl\"", ",", "\"iz\"", ",", "\"bb\"", ",", "\"dd\"", ",", "\"ff\"", ",", "\"gg\"", ",", "\"mm\"", ",", "\"nn\"", ",", "\"pp\"", ",", "\"rr\"", ",", "\"tt\"", ")", "\n", "switch", "newSuffix", "{", "case", "\"\"", ":", "if", "isShortWord", "(", "w", ")", "{", "w", ".", "RS", "=", "append", "(", "w", ".", "RS", ",", "[", "]", "rune", "(", "\"e\"", ")", "...", ")", "\n", "w", ".", "R1start", "=", "len", "(", "w", ".", "RS", ")", "\n", "w", ".", "R2start", "=", "len", "(", "w", ".", "RS", ")", "\n", "return", "true", "\n", "}", "\n", "case", "\"at\"", ",", "\"bl\"", ",", "\"iz\"", ":", "w", ".", "ReplaceSuffixRunes", "(", "newSuffixRunes", ",", "[", "]", "rune", "(", "newSuffix", "+", "\"e\"", ")", ",", "true", ")", "\n", "case", "\"bb\"", ",", "\"dd\"", ",", "\"ff\"", ",", "\"gg\"", ",", "\"mm\"", ",", "\"nn\"", ",", "\"pp\"", ",", "\"rr\"", ",", "\"tt\"", ":", "w", ".", "RemoveLastNRunes", "(", "1", ")", "\n", "}", "\n", "rsLen", ":=", "len", "(", "w", ".", "RS", ")", "\n", "if", "originalR1start", "<", "rsLen", "{", "w", ".", "R1start", "=", "originalR1start", "\n", "}", "else", "{", "w", ".", "R1start", "=", "rsLen", "\n", "}", "\n", "if", "originalR2start", "<", "rsLen", "{", "w", ".", "R2start", "=", "originalR2start", "\n", "}", "else", "{", "w", ".", "R2start", "=", "rsLen", "\n", "}", "\n", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// Step 1b is the normalization of various "ly" and "ed" sufficies. //
[ "Step", "1b", "is", "the", "normalization", "of", "various", "ly", "and", "ed", "sufficies", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/english/step1b.go#L9-L104
test
kljensen/snowball
french/step2b.go
step2b
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
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 }
[ "func", "step2b", "(", "word", "*", "snowballword", ".", "SnowballWord", ")", "bool", "{", "suffix", ",", "suffixRunes", ":=", "word", ".", "FirstSuffixIn", "(", "word", ".", "RVstart", ",", "len", "(", "word", ".", "RS", ")", ",", "\"eraIent\"", ",", "\"assions\"", ",", "\"erions\"", ",", "\"assiez\"", ",", "\"assent\"", ",", "\"èrent\",", ",", " ", "eront\",", "e", ",", " ", "erons\",", "e", ",", " ", ",", "eriez\",", ",", "e", ",", ",", ",", " ", "erait\",", "e", ",", " ", ",", "erais\",", ",", "e", ",", ",", ",", "\"asses\"", ",", "\"antes\"", ",", "\"aIent\"", ",", "\"âtes\",", ",", ",", ",", " ", ",", "âmes\", ", ",", "â", ",", " ", ",", "\"", "ons\",", "o", "\"erez\"", "\"eras\"", ",", "\"erai\"", ",", "\"asse\"", ",", "\"ants\"", ",", "\"ante\"", ",", "\"ées\",", ",", "\"iez\"", ",", ")", "\n", "\"era\"", "\n", "\"ant\"", "\n", "}" ]
// Step 2b is the removal of Verb suffixes in RV // that do not begin with "i". //
[ "Step", "2b", "is", "the", "removal", "of", "Verb", "suffixes", "in", "RV", "that", "do", "not", "begin", "with", "i", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/french/step2b.go#L10-L59
test
kljensen/snowball
english/common.go
capitalizeYs
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
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 }
[ "func", "capitalizeYs", "(", "word", "*", "snowballword", ".", "SnowballWord", ")", "(", "numCapitalizations", "int", ")", "{", "for", "i", ",", "r", ":=", "range", "word", ".", "RS", "{", "if", "r", "==", "121", "&&", "(", "i", "==", "0", "||", "isLowerVowel", "(", "word", ".", "RS", "[", "i", "-", "1", "]", ")", ")", "{", "word", ".", "RS", "[", "i", "]", "=", "89", "\n", "numCapitalizations", "+=", "1", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// Capitalize all 'Y's preceded by vowels or starting a word //
[ "Capitalize", "all", "Y", "s", "preceded", "by", "vowels", "or", "starting", "a", "word" ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/english/common.go#L53-L64
test
kljensen/snowball
english/common.go
uncapitalizeYs
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
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 }
[ "func", "uncapitalizeYs", "(", "word", "*", "snowballword", ".", "SnowballWord", ")", "{", "for", "i", ",", "r", ":=", "range", "word", ".", "RS", "{", "if", "r", "==", "89", "{", "word", ".", "RS", "[", "i", "]", "=", "121", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// Uncapitalize all 'Y's //
[ "Uncapitalize", "all", "Y", "s" ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/english/common.go#L68-L78
test
kljensen/snowball
english/common.go
stemSpecialWord
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
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 }
[ "func", "stemSpecialWord", "(", "word", "string", ")", "(", "stemmed", "string", ")", "{", "switch", "word", "{", "case", "\"skis\"", ":", "stemmed", "=", "\"ski\"", "\n", "case", "\"skies\"", ":", "stemmed", "=", "\"sky\"", "\n", "case", "\"dying\"", ":", "stemmed", "=", "\"die\"", "\n", "case", "\"lying\"", ":", "stemmed", "=", "\"lie\"", "\n", "case", "\"tying\"", ":", "stemmed", "=", "\"tie\"", "\n", "case", "\"idly\"", ":", "stemmed", "=", "\"idl\"", "\n", "case", "\"gently\"", ":", "stemmed", "=", "\"gentl\"", "\n", "case", "\"ugly\"", ":", "stemmed", "=", "\"ugli\"", "\n", "case", "\"early\"", ":", "stemmed", "=", "\"earli\"", "\n", "case", "\"only\"", ":", "stemmed", "=", "\"onli\"", "\n", "case", "\"singly\"", ":", "stemmed", "=", "\"singl\"", "\n", "case", "\"sky\"", ":", "stemmed", "=", "\"sky\"", "\n", "case", "\"news\"", ":", "stemmed", "=", "\"news\"", "\n", "case", "\"howe\"", ":", "stemmed", "=", "\"howe\"", "\n", "case", "\"atlas\"", ":", "stemmed", "=", "\"atlas\"", "\n", "case", "\"cosmos\"", ":", "stemmed", "=", "\"cosmos\"", "\n", "case", "\"bias\"", ":", "stemmed", "=", "\"bias\"", "\n", "case", "\"andes\"", ":", "stemmed", "=", "\"andes\"", "\n", "case", "\"inning\"", ":", "stemmed", "=", "\"inning\"", "\n", "case", "\"innings\"", ":", "stemmed", "=", "\"inning\"", "\n", "case", "\"outing\"", ":", "stemmed", "=", "\"outing\"", "\n", "case", "\"outings\"", ":", "stemmed", "=", "\"outing\"", "\n", "case", "\"canning\"", ":", "stemmed", "=", "\"canning\"", "\n", "case", "\"cannings\"", ":", "stemmed", "=", "\"canning\"", "\n", "case", "\"herring\"", ":", "stemmed", "=", "\"herring\"", "\n", "case", "\"herrings\"", ":", "stemmed", "=", "\"herring\"", "\n", "case", "\"earring\"", ":", "stemmed", "=", "\"earring\"", "\n", "case", "\"earrings\"", ":", "stemmed", "=", "\"earring\"", "\n", "case", "\"proceed\"", ":", "stemmed", "=", "\"proceed\"", "\n", "case", "\"proceeds\"", ":", "stemmed", "=", "\"proceed\"", "\n", "case", "\"proceeded\"", ":", "stemmed", "=", "\"proceed\"", "\n", "case", "\"proceeding\"", ":", "stemmed", "=", "\"proceed\"", "\n", "case", "\"exceed\"", ":", "stemmed", "=", "\"exceed\"", "\n", "case", "\"exceeds\"", ":", "stemmed", "=", "\"exceed\"", "\n", "case", "\"exceeded\"", ":", "stemmed", "=", "\"exceed\"", "\n", "case", "\"exceeding\"", ":", "stemmed", "=", "\"exceed\"", "\n", "case", "\"succeed\"", ":", "stemmed", "=", "\"succeed\"", "\n", "case", "\"succeeds\"", ":", "stemmed", "=", "\"succeed\"", "\n", "case", "\"succeeded\"", ":", "stemmed", "=", "\"succeed\"", "\n", "case", "\"succeeding\"", ":", "stemmed", "=", "\"succeed\"", "\n", "}", "\n", "return", "\n", "}" ]
// Returns the stemmed version of a word if it is a special // case, otherwise returns the empty string. //
[ "Returns", "the", "stemmed", "version", "of", "a", "word", "if", "it", "is", "a", "special", "case", "otherwise", "returns", "the", "empty", "string", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/english/common.go#L118-L202
test
kljensen/snowball
english/common.go
isShortWord
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
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)) }
[ "func", "isShortWord", "(", "w", "*", "snowballword", ".", "SnowballWord", ")", "(", "isShort", "bool", ")", "{", "if", "w", ".", "R1start", "<", "len", "(", "w", ".", "RS", ")", "{", "return", "\n", "}", "\n", "return", "endsShortSyllable", "(", "w", ",", "len", "(", "w", ".", "RS", ")", ")", "\n", "}" ]
// A word is called short if it ends in a short syllable, and if R1 is null. //
[ "A", "word", "is", "called", "short", "if", "it", "ends", "in", "a", "short", "syllable", "and", "if", "R1", "is", "null", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/english/common.go#L230-L239
test
kljensen/snowball
english/step1a.go
step1a
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
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 }
[ "func", "step1a", "(", "w", "*", "snowballword", ".", "SnowballWord", ")", "bool", "{", "suffix", ",", "suffixRunes", ":=", "w", ".", "FirstSuffix", "(", "\"sses\"", ",", "\"ied\"", ",", "\"ies\"", ",", "\"us\"", ",", "\"ss\"", ",", "\"s\"", ")", "\n", "switch", "suffix", "{", "case", "\"sses\"", ":", "w", ".", "ReplaceSuffixRunes", "(", "suffixRunes", ",", "[", "]", "rune", "(", "\"ss\"", ")", ",", "true", ")", "\n", "return", "true", "\n", "case", "\"ies\"", ",", "\"ied\"", ":", "var", "repl", "string", "\n", "if", "len", "(", "w", ".", "RS", ")", ">", "4", "{", "repl", "=", "\"i\"", "\n", "}", "else", "{", "repl", "=", "\"ie\"", "\n", "}", "\n", "w", ".", "ReplaceSuffixRunes", "(", "suffixRunes", ",", "[", "]", "rune", "(", "repl", ")", ",", "true", ")", "\n", "return", "true", "\n", "case", "\"us\"", ",", "\"ss\"", ":", "return", "false", "\n", "case", "\"s\"", ":", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "w", ".", "RS", ")", "-", "2", ";", "i", "++", "{", "if", "isLowerVowel", "(", "w", ".", "RS", "[", "i", "]", ")", "{", "w", ".", "RemoveLastNRunes", "(", "len", "(", "suffixRunes", ")", ")", "\n", "return", "true", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// Step 1a is normalization of various special "s"-endings. //
[ "Step", "1a", "is", "normalization", "of", "various", "special", "s", "-", "endings", "." ]
115fa8f6419dcfb9ec4653997b1c6803a5eff962
https://github.com/kljensen/snowball/blob/115fa8f6419dcfb9ec4653997b1c6803a5eff962/english/step1a.go#L9-L53
test
tylerb/gls
gls.go
Set
func Set(key string, value interface{}) { gid := curGoroutineID() dataLock.Lock() if data[gid] == nil { data[gid] = Values{} } data[gid][key] = value dataLock.Unlock() }
go
func Set(key string, value interface{}) { gid := curGoroutineID() dataLock.Lock() if data[gid] == nil { data[gid] = Values{} } data[gid][key] = value dataLock.Unlock() }
[ "func", "Set", "(", "key", "string", ",", "value", "interface", "{", "}", ")", "{", "gid", ":=", "curGoroutineID", "(", ")", "\n", "dataLock", ".", "Lock", "(", ")", "\n", "if", "data", "[", "gid", "]", "==", "nil", "{", "data", "[", "gid", "]", "=", "Values", "{", "}", "\n", "}", "\n", "data", "[", "gid", "]", "[", "key", "]", "=", "value", "\n", "dataLock", ".", "Unlock", "(", ")", "\n", "}" ]
// Set sets the value by key and associates it with the current goroutine.
[ "Set", "sets", "the", "value", "by", "key", "and", "associates", "it", "with", "the", "current", "goroutine", "." ]
e606233f194d6c314156dc6a35f21a42a470c6f6
https://github.com/tylerb/gls/blob/e606233f194d6c314156dc6a35f21a42a470c6f6/gls.go#L39-L47
test
tylerb/gls
gls.go
Get
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
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 }
[ "func", "Get", "(", "key", "string", ")", "interface", "{", "}", "{", "gid", ":=", "curGoroutineID", "(", ")", "\n", "dataLock", ".", "RLock", "(", ")", "\n", "if", "data", "[", "gid", "]", "==", "nil", "{", "dataLock", ".", "RUnlock", "(", ")", "\n", "return", "nil", "\n", "}", "\n", "value", ":=", "data", "[", "gid", "]", "[", "key", "]", "\n", "dataLock", ".", "RUnlock", "(", ")", "\n", "return", "value", "\n", "}" ]
// Get gets the value by key as it exists for the current goroutine.
[ "Get", "gets", "the", "value", "by", "key", "as", "it", "exists", "for", "the", "current", "goroutine", "." ]
e606233f194d6c314156dc6a35f21a42a470c6f6
https://github.com/tylerb/gls/blob/e606233f194d6c314156dc6a35f21a42a470c6f6/gls.go#L50-L60
test
tylerb/gls
gls.go
Cleanup
func Cleanup() { gid := curGoroutineID() dataLock.Lock() delete(data, gid) dataLock.Unlock() }
go
func Cleanup() { gid := curGoroutineID() dataLock.Lock() delete(data, gid) dataLock.Unlock() }
[ "func", "Cleanup", "(", ")", "{", "gid", ":=", "curGoroutineID", "(", ")", "\n", "dataLock", ".", "Lock", "(", ")", "\n", "delete", "(", "data", ",", "gid", ")", "\n", "dataLock", ".", "Unlock", "(", ")", "\n", "}" ]
// Cleanup removes all data associated with this goroutine. If this is not // called, the data may persist for the lifetime of your application. This // must be called from the very first goroutine to invoke Set
[ "Cleanup", "removes", "all", "data", "associated", "with", "this", "goroutine", ".", "If", "this", "is", "not", "called", "the", "data", "may", "persist", "for", "the", "lifetime", "of", "your", "application", ".", "This", "must", "be", "called", "from", "the", "very", "first", "goroutine", "to", "invoke", "Set" ]
e606233f194d6c314156dc6a35f21a42a470c6f6
https://github.com/tylerb/gls/blob/e606233f194d6c314156dc6a35f21a42a470c6f6/gls.go#L80-L85
test
tylerb/gls
gls.go
getValues
func getValues() Values { gid := curGoroutineID() dataLock.Lock() values := data[gid] dataLock.Unlock() return values }
go
func getValues() Values { gid := curGoroutineID() dataLock.Lock() values := data[gid] dataLock.Unlock() return values }
[ "func", "getValues", "(", ")", "Values", "{", "gid", ":=", "curGoroutineID", "(", ")", "\n", "dataLock", ".", "Lock", "(", ")", "\n", "values", ":=", "data", "[", "gid", "]", "\n", "dataLock", ".", "Unlock", "(", ")", "\n", "return", "values", "\n", "}" ]
// getValues unlinks two goroutines
[ "getValues", "unlinks", "two", "goroutines" ]
e606233f194d6c314156dc6a35f21a42a470c6f6
https://github.com/tylerb/gls/blob/e606233f194d6c314156dc6a35f21a42a470c6f6/gls.go#L88-L94
test
tylerb/gls
gls.go
linkGRs
func linkGRs(parentData Values) { childID := curGoroutineID() dataLock.Lock() data[childID] = parentData dataLock.Unlock() }
go
func linkGRs(parentData Values) { childID := curGoroutineID() dataLock.Lock() data[childID] = parentData dataLock.Unlock() }
[ "func", "linkGRs", "(", "parentData", "Values", ")", "{", "childID", ":=", "curGoroutineID", "(", ")", "\n", "dataLock", ".", "Lock", "(", ")", "\n", "data", "[", "childID", "]", "=", "parentData", "\n", "dataLock", ".", "Unlock", "(", ")", "\n", "}" ]
// linkGRs links two goroutines together, allowing the child to access the // data present in the parent.
[ "linkGRs", "links", "two", "goroutines", "together", "allowing", "the", "child", "to", "access", "the", "data", "present", "in", "the", "parent", "." ]
e606233f194d6c314156dc6a35f21a42a470c6f6
https://github.com/tylerb/gls/blob/e606233f194d6c314156dc6a35f21a42a470c6f6/gls.go#L98-L103
test
tylerb/gls
gls.go
unlinkGRs
func unlinkGRs() { childID := curGoroutineID() dataLock.Lock() delete(data, childID) dataLock.Unlock() }
go
func unlinkGRs() { childID := curGoroutineID() dataLock.Lock() delete(data, childID) dataLock.Unlock() }
[ "func", "unlinkGRs", "(", ")", "{", "childID", ":=", "curGoroutineID", "(", ")", "\n", "dataLock", ".", "Lock", "(", ")", "\n", "delete", "(", "data", ",", "childID", ")", "\n", "dataLock", ".", "Unlock", "(", ")", "\n", "}" ]
// unlinkGRs unlinks two goroutines
[ "unlinkGRs", "unlinks", "two", "goroutines" ]
e606233f194d6c314156dc6a35f21a42a470c6f6
https://github.com/tylerb/gls/blob/e606233f194d6c314156dc6a35f21a42a470c6f6/gls.go#L106-L111
test
cloudfoundry-incubator/cf-test-helpers
helpers/app_commands.go
AppUri
func AppUri(appName, path string, config helpersinternal.CurlConfig) string { uriCreator := &helpersinternal.AppUriCreator{CurlConfig: config} return uriCreator.AppUri(appName, path) }
go
func AppUri(appName, path string, config helpersinternal.CurlConfig) string { uriCreator := &helpersinternal.AppUriCreator{CurlConfig: config} return uriCreator.AppUri(appName, path) }
[ "func", "AppUri", "(", "appName", ",", "path", "string", ",", "config", "helpersinternal", ".", "CurlConfig", ")", "string", "{", "uriCreator", ":=", "&", "helpersinternal", ".", "AppUriCreator", "{", "CurlConfig", ":", "config", "}", "\n", "return", "uriCreator", ".", "AppUri", "(", "appName", ",", "path", ")", "\n", "}" ]
// Gets an app's endpoint with the specified path
[ "Gets", "an", "app", "s", "endpoint", "with", "the", "specified", "path" ]
83791edc4b0a2d48b602088c30332063b8f02f32
https://github.com/cloudfoundry-incubator/cf-test-helpers/blob/83791edc4b0a2d48b602088c30332063b8f02f32/helpers/app_commands.go#L12-L16
test
cloudfoundry-incubator/cf-test-helpers
helpers/app_commands.go
CurlAppWithTimeout
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
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...) }
[ "func", "CurlAppWithTimeout", "(", "cfg", "helpersinternal", ".", "CurlConfig", ",", "appName", ",", "path", "string", ",", "timeout", "time", ".", "Duration", ",", "args", "...", "string", ")", "string", "{", "appCurler", ":=", "helpersinternal", ".", "NewAppCurler", "(", "Curl", ",", "cfg", ")", "\n", "return", "appCurler", ".", "CurlAndWait", "(", "cfg", ",", "appName", ",", "path", ",", "timeout", ",", "args", "...", ")", "\n", "}" ]
// Curls an app's endpoint and exit successfully before the specified timeout
[ "Curls", "an", "app", "s", "endpoint", "and", "exit", "successfully", "before", "the", "specified", "timeout" ]
83791edc4b0a2d48b602088c30332063b8f02f32
https://github.com/cloudfoundry-incubator/cf-test-helpers/blob/83791edc4b0a2d48b602088c30332063b8f02f32/helpers/app_commands.go#L19-L22
test
cloudfoundry-incubator/cf-test-helpers
helpers/app_commands.go
CurlApp
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
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...) }
[ "func", "CurlApp", "(", "cfg", "helpersinternal", ".", "CurlConfig", ",", "appName", ",", "path", "string", ",", "args", "...", "string", ")", "string", "{", "appCurler", ":=", "helpersinternal", ".", "NewAppCurler", "(", "Curl", ",", "cfg", ")", "\n", "return", "appCurler", ".", "CurlAndWait", "(", "cfg", ",", "appName", ",", "path", ",", "CURL_TIMEOUT", ",", "args", "...", ")", "\n", "}" ]
// Curls an app's endpoint and exit successfully before the default timeout
[ "Curls", "an", "app", "s", "endpoint", "and", "exit", "successfully", "before", "the", "default", "timeout" ]
83791edc4b0a2d48b602088c30332063b8f02f32
https://github.com/cloudfoundry-incubator/cf-test-helpers/blob/83791edc4b0a2d48b602088c30332063b8f02f32/helpers/app_commands.go#L25-L28
test
cloudfoundry-incubator/cf-test-helpers
helpers/app_commands.go
CurlAppRoot
func CurlAppRoot(cfg helpersinternal.CurlConfig, appName string) string { appCurler := helpersinternal.NewAppCurler(Curl, cfg) return appCurler.CurlAndWait(cfg, appName, "/", CURL_TIMEOUT) }
go
func CurlAppRoot(cfg helpersinternal.CurlConfig, appName string) string { appCurler := helpersinternal.NewAppCurler(Curl, cfg) return appCurler.CurlAndWait(cfg, appName, "/", CURL_TIMEOUT) }
[ "func", "CurlAppRoot", "(", "cfg", "helpersinternal", ".", "CurlConfig", ",", "appName", "string", ")", "string", "{", "appCurler", ":=", "helpersinternal", ".", "NewAppCurler", "(", "Curl", ",", "cfg", ")", "\n", "return", "appCurler", ".", "CurlAndWait", "(", "cfg", ",", "appName", ",", "\"/\"", ",", "CURL_TIMEOUT", ")", "\n", "}" ]
// Curls an app's root endpoint and exit successfully before the default timeout
[ "Curls", "an", "app", "s", "root", "endpoint", "and", "exit", "successfully", "before", "the", "default", "timeout" ]
83791edc4b0a2d48b602088c30332063b8f02f32
https://github.com/cloudfoundry-incubator/cf-test-helpers/blob/83791edc4b0a2d48b602088c30332063b8f02f32/helpers/app_commands.go#L31-L34
test
gernest/mention
mention.go
GetTags
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
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 }
[ "func", "GetTags", "(", "prefix", "rune", ",", "str", "string", ",", "terminator", "...", "rune", ")", "(", "tags", "[", "]", "Tag", ")", "{", "if", "len", "(", "terminator", ")", "==", "0", "{", "terminator", "=", "[", "]", "rune", "(", "\" \"", ")", "\n", "}", "\n", "termIndexes", ":=", "[", "]", "int", "{", "-", "1", "}", "\n", "for", "i", ",", "char", ":=", "range", "str", "{", "if", "isTerminator", "(", "char", ",", "terminator", "...", ")", "{", "termIndexes", "=", "append", "(", "termIndexes", ",", "i", ")", "\n", "}", "\n", "}", "\n", "termIndexes", "=", "append", "(", "termIndexes", ",", "len", "(", "str", ")", ")", "\n", "for", "i", ",", "t", ":=", "range", "termIndexes", "{", "if", "t", ">=", "(", "len", "(", "str", ")", "-", "1", ")", "{", "break", "\n", "}", "\n", "if", "str", "[", "t", "+", "1", "]", "==", "byte", "(", "prefix", ")", "{", "tagText", ":=", "strings", ".", "TrimLeft", "(", "str", "[", "t", "+", "2", ":", "termIndexes", "[", "i", "+", "1", "]", "]", ",", "string", "(", "prefix", ")", ")", "\n", "if", "tagText", "==", "\"\"", "{", "continue", "\n", "}", "\n", "index", ":=", "t", "+", "1", "\n", "tags", "=", "append", "(", "tags", ",", "Tag", "{", "prefix", ",", "tagText", ",", "index", "}", ")", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// GetTags returns a slice of Tags, that is all characters after rune char up // to occurrence of space or another occurrence of rune char. Additionally you // can provide a coma separated unicode characters to be used as terminating // sequence.
[ "GetTags", "returns", "a", "slice", "of", "Tags", "that", "is", "all", "characters", "after", "rune", "char", "up", "to", "occurrence", "of", "space", "or", "another", "occurrence", "of", "rune", "char", ".", "Additionally", "you", "can", "provide", "a", "coma", "separated", "unicode", "characters", "to", "be", "used", "as", "terminating", "sequence", "." ]
d48aa4355f942e79e1a4ac2bd08c5c46371b78ca
https://github.com/gernest/mention/blob/d48aa4355f942e79e1a4ac2bd08c5c46371b78ca/mention.go#L27-L61
test
gernest/mention
mention.go
GetTagsAsUniqueStrings
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
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) }
[ "func", "GetTagsAsUniqueStrings", "(", "prefix", "rune", ",", "str", "string", ",", "terminator", "...", "rune", ")", "(", "strs", "[", "]", "string", ")", "{", "tags", ":=", "GetTags", "(", "prefix", ",", "str", ",", "terminator", "...", ")", "\n", "for", "_", ",", "tag", ":=", "range", "tags", "{", "strs", "=", "append", "(", "strs", ",", "tag", ".", "Tag", ")", "\n", "}", "\n", "return", "uniquify", "(", "strs", ")", "\n", "}" ]
// GetTagsAsUniqueStrings gets all tags as a slice of unique strings. This is // here to have a means of being somewhat backwards compatible with previous // versions of mention
[ "GetTagsAsUniqueStrings", "gets", "all", "tags", "as", "a", "slice", "of", "unique", "strings", ".", "This", "is", "here", "to", "have", "a", "means", "of", "being", "somewhat", "backwards", "compatible", "with", "previous", "versions", "of", "mention" ]
d48aa4355f942e79e1a4ac2bd08c5c46371b78ca
https://github.com/gernest/mention/blob/d48aa4355f942e79e1a4ac2bd08c5c46371b78ca/mention.go#L66-L72
test
gernest/mention
mention.go
isTerminator
func isTerminator(r rune, terminator ...rune) bool { for _, t := range terminator { if r == t { return true } } return unicode.IsSpace(r) || !unicode.IsPrint(r) }
go
func isTerminator(r rune, terminator ...rune) bool { for _, t := range terminator { if r == t { return true } } return unicode.IsSpace(r) || !unicode.IsPrint(r) }
[ "func", "isTerminator", "(", "r", "rune", ",", "terminator", "...", "rune", ")", "bool", "{", "for", "_", ",", "t", ":=", "range", "terminator", "{", "if", "r", "==", "t", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "unicode", ".", "IsSpace", "(", "r", ")", "||", "!", "unicode", ".", "IsPrint", "(", "r", ")", "\n", "}" ]
// Is given rune listed as a terminator
[ "Is", "given", "rune", "listed", "as", "a", "terminator" ]
d48aa4355f942e79e1a4ac2bd08c5c46371b78ca
https://github.com/gernest/mention/blob/d48aa4355f942e79e1a4ac2bd08c5c46371b78ca/mention.go#L75-L82
test
gernest/mention
mention.go
uniquify
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
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 }
[ "func", "uniquify", "(", "in", "[", "]", "string", ")", "(", "out", "[", "]", "string", ")", "{", "for", "_", ",", "i", ":=", "range", "in", "{", "if", "i", "==", "\"\"", "{", "continue", "\n", "}", "\n", "for", "_", ",", "o", ":=", "range", "out", "{", "if", "i", "==", "o", "{", "continue", "\n", "}", "\n", "}", "\n", "out", "=", "append", "(", "out", ",", "i", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Ensures the given slice of strings are unique and that none are empty // strings
[ "Ensures", "the", "given", "slice", "of", "strings", "are", "unique", "and", "that", "none", "are", "empty", "strings" ]
d48aa4355f942e79e1a4ac2bd08c5c46371b78ca
https://github.com/gernest/mention/blob/d48aa4355f942e79e1a4ac2bd08c5c46371b78ca/mention.go#L86-L99
test
gin-contrib/location
location.go
New
func New(config Config) gin.HandlerFunc { location := newLocation(config) return func(c *gin.Context) { location.applyToContext(c) } }
go
func New(config Config) gin.HandlerFunc { location := newLocation(config) return func(c *gin.Context) { location.applyToContext(c) } }
[ "func", "New", "(", "config", "Config", ")", "gin", ".", "HandlerFunc", "{", "location", ":=", "newLocation", "(", "config", ")", "\n", "return", "func", "(", "c", "*", "gin", ".", "Context", ")", "{", "location", ".", "applyToContext", "(", "c", ")", "\n", "}", "\n", "}" ]
// New returns the location middleware with user-defined custom configuration.
[ "New", "returns", "the", "location", "middleware", "with", "user", "-", "defined", "custom", "configuration", "." ]
0462caccbb9cc0b222a2d75a64830c360c603798
https://github.com/gin-contrib/location/blob/0462caccbb9cc0b222a2d75a64830c360c603798/location.go#L41-L47
test
gin-contrib/location
location.go
Get
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
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 }
[ "func", "Get", "(", "c", "*", "gin", ".", "Context", ")", "*", "url", ".", "URL", "{", "v", ",", "ok", ":=", "c", ".", "Get", "(", "key", ")", "\n", "if", "!", "ok", "{", "return", "nil", "\n", "}", "\n", "vv", ",", "ok", ":=", "v", ".", "(", "*", "url", ".", "URL", ")", "\n", "if", "!", "ok", "{", "return", "nil", "\n", "}", "\n", "return", "vv", "\n", "}" ]
// Get returns the Location information for the incoming http.Request from the // context. If the location is not set a nil value is returned.
[ "Get", "returns", "the", "Location", "information", "for", "the", "incoming", "http", ".", "Request", "from", "the", "context", ".", "If", "the", "location", "is", "not", "set", "a", "nil", "value", "is", "returned", "." ]
0462caccbb9cc0b222a2d75a64830c360c603798
https://github.com/gin-contrib/location/blob/0462caccbb9cc0b222a2d75a64830c360c603798/location.go#L51-L65
test
libp2p/go-libp2p-crypto
rsa.go
GenerateRSAKeyPair
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
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 }
[ "func", "GenerateRSAKeyPair", "(", "bits", "int", ",", "src", "io", ".", "Reader", ")", "(", "PrivKey", ",", "PubKey", ",", "error", ")", "{", "if", "bits", "<", "512", "{", "return", "nil", ",", "nil", ",", "ErrRsaKeyTooSmall", "\n", "}", "\n", "priv", ",", "err", ":=", "rsa", ".", "GenerateKey", "(", "src", ",", "bits", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "pk", ":=", "&", "priv", ".", "PublicKey", "\n", "return", "&", "RsaPrivateKey", "{", "sk", ":", "priv", "}", ",", "&", "RsaPublicKey", "{", "pk", "}", ",", "nil", "\n", "}" ]
// GenerateRSAKeyPair generates a new rsa private and public key
[ "GenerateRSAKeyPair", "generates", "a", "new", "rsa", "private", "and", "public", "key" ]
9d2fed53443f745e6dc4d02bdcc94d9742a0ca84
https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/rsa.go#L33-L43
test
libp2p/go-libp2p-crypto
rsa.go
Verify
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
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 }
[ "func", "(", "pk", "*", "RsaPublicKey", ")", "Verify", "(", "data", ",", "sig", "[", "]", "byte", ")", "(", "bool", ",", "error", ")", "{", "hashed", ":=", "sha256", ".", "Sum256", "(", "data", ")", "\n", "err", ":=", "rsa", ".", "VerifyPKCS1v15", "(", "pk", ".", "k", ",", "crypto", ".", "SHA256", ",", "hashed", "[", ":", "]", ",", "sig", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "return", "true", ",", "nil", "\n", "}" ]
// Verify compares a signature against input data
[ "Verify", "compares", "a", "signature", "against", "input", "data" ]
9d2fed53443f745e6dc4d02bdcc94d9742a0ca84
https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/rsa.go#L46-L53
test
libp2p/go-libp2p-crypto
rsa.go
Encrypt
func (pk *RsaPublicKey) Encrypt(b []byte) ([]byte, error) { return rsa.EncryptPKCS1v15(rand.Reader, pk.k, b) }
go
func (pk *RsaPublicKey) Encrypt(b []byte) ([]byte, error) { return rsa.EncryptPKCS1v15(rand.Reader, pk.k, b) }
[ "func", "(", "pk", "*", "RsaPublicKey", ")", "Encrypt", "(", "b", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "rsa", ".", "EncryptPKCS1v15", "(", "rand", ".", "Reader", ",", "pk", ".", "k", ",", "b", ")", "\n", "}" ]
// Encrypt returns encrypted bytes from the inpu data
[ "Encrypt", "returns", "encrypted", "bytes", "from", "the", "inpu", "data" ]
9d2fed53443f745e6dc4d02bdcc94d9742a0ca84
https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/rsa.go#L69-L71
test
libp2p/go-libp2p-crypto
rsa.go
Sign
func (sk *RsaPrivateKey) Sign(message []byte) ([]byte, error) { hashed := sha256.Sum256(message) return rsa.SignPKCS1v15(rand.Reader, sk.sk, crypto.SHA256, hashed[:]) }
go
func (sk *RsaPrivateKey) Sign(message []byte) ([]byte, error) { hashed := sha256.Sum256(message) return rsa.SignPKCS1v15(rand.Reader, sk.sk, crypto.SHA256, hashed[:]) }
[ "func", "(", "sk", "*", "RsaPrivateKey", ")", "Sign", "(", "message", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "hashed", ":=", "sha256", ".", "Sum256", "(", "message", ")", "\n", "return", "rsa", ".", "SignPKCS1v15", "(", "rand", ".", "Reader", ",", "sk", ".", "sk", ",", "crypto", ".", "SHA256", ",", "hashed", "[", ":", "]", ")", "\n", "}" ]
// Sign returns a signature of the input data
[ "Sign", "returns", "a", "signature", "of", "the", "input", "data" ]
9d2fed53443f745e6dc4d02bdcc94d9742a0ca84
https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/rsa.go#L79-L82
test
libp2p/go-libp2p-crypto
rsa.go
GetPublic
func (sk *RsaPrivateKey) GetPublic() PubKey { if sk.pk == nil { sk.pk = &sk.sk.PublicKey } return &RsaPublicKey{sk.pk} }
go
func (sk *RsaPrivateKey) GetPublic() PubKey { if sk.pk == nil { sk.pk = &sk.sk.PublicKey } return &RsaPublicKey{sk.pk} }
[ "func", "(", "sk", "*", "RsaPrivateKey", ")", "GetPublic", "(", ")", "PubKey", "{", "if", "sk", ".", "pk", "==", "nil", "{", "sk", ".", "pk", "=", "&", "sk", ".", "sk", ".", "PublicKey", "\n", "}", "\n", "return", "&", "RsaPublicKey", "{", "sk", ".", "pk", "}", "\n", "}" ]
// GetPublic returns a public key
[ "GetPublic", "returns", "a", "public", "key" ]
9d2fed53443f745e6dc4d02bdcc94d9742a0ca84
https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/rsa.go#L85-L90
test
libp2p/go-libp2p-crypto
rsa.go
Decrypt
func (sk *RsaPrivateKey) Decrypt(b []byte) ([]byte, error) { return rsa.DecryptPKCS1v15(rand.Reader, sk.sk, b) }
go
func (sk *RsaPrivateKey) Decrypt(b []byte) ([]byte, error) { return rsa.DecryptPKCS1v15(rand.Reader, sk.sk, b) }
[ "func", "(", "sk", "*", "RsaPrivateKey", ")", "Decrypt", "(", "b", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "rsa", ".", "DecryptPKCS1v15", "(", "rand", ".", "Reader", ",", "sk", ".", "sk", ",", "b", ")", "\n", "}" ]
// Decrypt returns decrypted bytes of the input encrypted bytes
[ "Decrypt", "returns", "decrypted", "bytes", "of", "the", "input", "encrypted", "bytes" ]
9d2fed53443f745e6dc4d02bdcc94d9742a0ca84
https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/rsa.go#L93-L95
test
libp2p/go-libp2p-crypto
rsa.go
UnmarshalRsaPrivateKey
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
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 }
[ "func", "UnmarshalRsaPrivateKey", "(", "b", "[", "]", "byte", ")", "(", "PrivKey", ",", "error", ")", "{", "sk", ",", "err", ":=", "x509", ".", "ParsePKCS1PrivateKey", "(", "b", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "sk", ".", "N", ".", "BitLen", "(", ")", "<", "512", "{", "return", "nil", ",", "ErrRsaKeyTooSmall", "\n", "}", "\n", "return", "&", "RsaPrivateKey", "{", "sk", ":", "sk", "}", ",", "nil", "\n", "}" ]
// UnmarshalRsaPrivateKey returns a private key from the input x509 bytes
[ "UnmarshalRsaPrivateKey", "returns", "a", "private", "key", "from", "the", "input", "x509", "bytes" ]
9d2fed53443f745e6dc4d02bdcc94d9742a0ca84
https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/rsa.go#L117-L126
test
libp2p/go-libp2p-crypto
key.go
GenerateKeyPair
func GenerateKeyPair(typ, bits int) (PrivKey, PubKey, error) { return GenerateKeyPairWithReader(typ, bits, rand.Reader) }
go
func GenerateKeyPair(typ, bits int) (PrivKey, PubKey, error) { return GenerateKeyPairWithReader(typ, bits, rand.Reader) }
[ "func", "GenerateKeyPair", "(", "typ", ",", "bits", "int", ")", "(", "PrivKey", ",", "PubKey", ",", "error", ")", "{", "return", "GenerateKeyPairWithReader", "(", "typ", ",", "bits", ",", "rand", ".", "Reader", ")", "\n", "}" ]
// GenerateKeyPair generates a private and public key
[ "GenerateKeyPair", "generates", "a", "private", "and", "public", "key" ]
9d2fed53443f745e6dc4d02bdcc94d9742a0ca84
https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/key.go#L113-L115
test
libp2p/go-libp2p-crypto
key.go
GenerateKeyPairWithReader
func GenerateKeyPairWithReader(typ, bits int, src io.Reader) (PrivKey, PubKey, error) { switch typ { case RSA: return GenerateRSAKeyPair(bits, src) case Ed25519: return GenerateEd25519Key(src) case Secp256k1: return GenerateSecp256k1Key(src) case ECDSA: return GenerateECDSAKeyPair(src) default: return nil, nil, ErrBadKeyType } }
go
func GenerateKeyPairWithReader(typ, bits int, src io.Reader) (PrivKey, PubKey, error) { switch typ { case RSA: return GenerateRSAKeyPair(bits, src) case Ed25519: return GenerateEd25519Key(src) case Secp256k1: return GenerateSecp256k1Key(src) case ECDSA: return GenerateECDSAKeyPair(src) default: return nil, nil, ErrBadKeyType } }
[ "func", "GenerateKeyPairWithReader", "(", "typ", ",", "bits", "int", ",", "src", "io", ".", "Reader", ")", "(", "PrivKey", ",", "PubKey", ",", "error", ")", "{", "switch", "typ", "{", "case", "RSA", ":", "return", "GenerateRSAKeyPair", "(", "bits", ",", "src", ")", "\n", "case", "Ed25519", ":", "return", "GenerateEd25519Key", "(", "src", ")", "\n", "case", "Secp256k1", ":", "return", "GenerateSecp256k1Key", "(", "src", ")", "\n", "case", "ECDSA", ":", "return", "GenerateECDSAKeyPair", "(", "src", ")", "\n", "default", ":", "return", "nil", ",", "nil", ",", "ErrBadKeyType", "\n", "}", "\n", "}" ]
// GenerateKeyPairWithReader returns a keypair of the given type and bitsize
[ "GenerateKeyPairWithReader", "returns", "a", "keypair", "of", "the", "given", "type", "and", "bitsize" ]
9d2fed53443f745e6dc4d02bdcc94d9742a0ca84
https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/key.go#L118-L131
test
libp2p/go-libp2p-crypto
key.go
GenerateEKeyPair
func GenerateEKeyPair(curveName string) ([]byte, GenSharedKey, error) { var curve elliptic.Curve switch curveName { case "P-256": curve = elliptic.P256() case "P-384": curve = elliptic.P384() case "P-521": curve = elliptic.P521() } priv, x, y, err := elliptic.GenerateKey(curve, rand.Reader) if err != nil { return nil, nil, err } pubKey := elliptic.Marshal(curve, x, y) done := func(theirPub []byte) ([]byte, error) { // Verify and unpack node's public key. x, y := elliptic.Unmarshal(curve, theirPub) if x == nil { return nil, fmt.Errorf("malformed public key: %d %v", len(theirPub), theirPub) } if !curve.IsOnCurve(x, y) { return nil, errors.New("invalid public key") } // Generate shared secret. secret, _ := curve.ScalarMult(x, y, priv) return secret.Bytes(), nil } return pubKey, done, nil }
go
func GenerateEKeyPair(curveName string) ([]byte, GenSharedKey, error) { var curve elliptic.Curve switch curveName { case "P-256": curve = elliptic.P256() case "P-384": curve = elliptic.P384() case "P-521": curve = elliptic.P521() } priv, x, y, err := elliptic.GenerateKey(curve, rand.Reader) if err != nil { return nil, nil, err } pubKey := elliptic.Marshal(curve, x, y) done := func(theirPub []byte) ([]byte, error) { // Verify and unpack node's public key. x, y := elliptic.Unmarshal(curve, theirPub) if x == nil { return nil, fmt.Errorf("malformed public key: %d %v", len(theirPub), theirPub) } if !curve.IsOnCurve(x, y) { return nil, errors.New("invalid public key") } // Generate shared secret. secret, _ := curve.ScalarMult(x, y, priv) return secret.Bytes(), nil } return pubKey, done, nil }
[ "func", "GenerateEKeyPair", "(", "curveName", "string", ")", "(", "[", "]", "byte", ",", "GenSharedKey", ",", "error", ")", "{", "var", "curve", "elliptic", ".", "Curve", "\n", "switch", "curveName", "{", "case", "\"P-256\"", ":", "curve", "=", "elliptic", ".", "P256", "(", ")", "\n", "case", "\"P-384\"", ":", "curve", "=", "elliptic", ".", "P384", "(", ")", "\n", "case", "\"P-521\"", ":", "curve", "=", "elliptic", ".", "P521", "(", ")", "\n", "}", "\n", "priv", ",", "x", ",", "y", ",", "err", ":=", "elliptic", ".", "GenerateKey", "(", "curve", ",", "rand", ".", "Reader", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "pubKey", ":=", "elliptic", ".", "Marshal", "(", "curve", ",", "x", ",", "y", ")", "\n", "done", ":=", "func", "(", "theirPub", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "x", ",", "y", ":=", "elliptic", ".", "Unmarshal", "(", "curve", ",", "theirPub", ")", "\n", "if", "x", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"malformed public key: %d %v\"", ",", "len", "(", "theirPub", ")", ",", "theirPub", ")", "\n", "}", "\n", "if", "!", "curve", ".", "IsOnCurve", "(", "x", ",", "y", ")", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"invalid public key\"", ")", "\n", "}", "\n", "secret", ",", "_", ":=", "curve", ".", "ScalarMult", "(", "x", ",", "y", ",", "priv", ")", "\n", "return", "secret", ".", "Bytes", "(", ")", ",", "nil", "\n", "}", "\n", "return", "pubKey", ",", "done", ",", "nil", "\n", "}" ]
// GenerateEKeyPair returns an ephemeral public key and returns a function that will compute // the shared secret key. Used in the identify module. // // Focuses only on ECDH now, but can be made more general in the future.
[ "GenerateEKeyPair", "returns", "an", "ephemeral", "public", "key", "and", "returns", "a", "function", "that", "will", "compute", "the", "shared", "secret", "key", ".", "Used", "in", "the", "identify", "module", ".", "Focuses", "only", "on", "ECDH", "now", "but", "can", "be", "made", "more", "general", "in", "the", "future", "." ]
9d2fed53443f745e6dc4d02bdcc94d9742a0ca84
https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/key.go#L137-L174
test
libp2p/go-libp2p-crypto
key.go
UnmarshalPublicKey
func UnmarshalPublicKey(data []byte) (PubKey, error) { pmes := new(pb.PublicKey) err := proto.Unmarshal(data, pmes) if err != nil { return nil, err } um, ok := PubKeyUnmarshallers[pmes.GetType()] if !ok { return nil, ErrBadKeyType } return um(pmes.GetData()) }
go
func UnmarshalPublicKey(data []byte) (PubKey, error) { pmes := new(pb.PublicKey) err := proto.Unmarshal(data, pmes) if err != nil { return nil, err } um, ok := PubKeyUnmarshallers[pmes.GetType()] if !ok { return nil, ErrBadKeyType } return um(pmes.GetData()) }
[ "func", "UnmarshalPublicKey", "(", "data", "[", "]", "byte", ")", "(", "PubKey", ",", "error", ")", "{", "pmes", ":=", "new", "(", "pb", ".", "PublicKey", ")", "\n", "err", ":=", "proto", ".", "Unmarshal", "(", "data", ",", "pmes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "um", ",", "ok", ":=", "PubKeyUnmarshallers", "[", "pmes", ".", "GetType", "(", ")", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "ErrBadKeyType", "\n", "}", "\n", "return", "um", "(", "pmes", ".", "GetData", "(", ")", ")", "\n", "}" ]
// UnmarshalPublicKey converts a protobuf serialized public key into its // representative object
[ "UnmarshalPublicKey", "converts", "a", "protobuf", "serialized", "public", "key", "into", "its", "representative", "object" ]
9d2fed53443f745e6dc4d02bdcc94d9742a0ca84
https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/key.go#L274-L287
test
libp2p/go-libp2p-crypto
key.go
MarshalPublicKey
func MarshalPublicKey(k PubKey) ([]byte, error) { pbmes := new(pb.PublicKey) pbmes.Type = k.Type() data, err := k.Raw() if err != nil { return nil, err } pbmes.Data = data return proto.Marshal(pbmes) }
go
func MarshalPublicKey(k PubKey) ([]byte, error) { pbmes := new(pb.PublicKey) pbmes.Type = k.Type() data, err := k.Raw() if err != nil { return nil, err } pbmes.Data = data return proto.Marshal(pbmes) }
[ "func", "MarshalPublicKey", "(", "k", "PubKey", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "pbmes", ":=", "new", "(", "pb", ".", "PublicKey", ")", "\n", "pbmes", ".", "Type", "=", "k", ".", "Type", "(", ")", "\n", "data", ",", "err", ":=", "k", ".", "Raw", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "pbmes", ".", "Data", "=", "data", "\n", "return", "proto", ".", "Marshal", "(", "pbmes", ")", "\n", "}" ]
// MarshalPublicKey converts a public key object into a protobuf serialized // public key
[ "MarshalPublicKey", "converts", "a", "public", "key", "object", "into", "a", "protobuf", "serialized", "public", "key" ]
9d2fed53443f745e6dc4d02bdcc94d9742a0ca84
https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/key.go#L291-L301
test
libp2p/go-libp2p-crypto
key.go
UnmarshalPrivateKey
func UnmarshalPrivateKey(data []byte) (PrivKey, error) { pmes := new(pb.PrivateKey) err := proto.Unmarshal(data, pmes) if err != nil { return nil, err } um, ok := PrivKeyUnmarshallers[pmes.GetType()] if !ok { return nil, ErrBadKeyType } return um(pmes.GetData()) }
go
func UnmarshalPrivateKey(data []byte) (PrivKey, error) { pmes := new(pb.PrivateKey) err := proto.Unmarshal(data, pmes) if err != nil { return nil, err } um, ok := PrivKeyUnmarshallers[pmes.GetType()] if !ok { return nil, ErrBadKeyType } return um(pmes.GetData()) }
[ "func", "UnmarshalPrivateKey", "(", "data", "[", "]", "byte", ")", "(", "PrivKey", ",", "error", ")", "{", "pmes", ":=", "new", "(", "pb", ".", "PrivateKey", ")", "\n", "err", ":=", "proto", ".", "Unmarshal", "(", "data", ",", "pmes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "um", ",", "ok", ":=", "PrivKeyUnmarshallers", "[", "pmes", ".", "GetType", "(", ")", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "ErrBadKeyType", "\n", "}", "\n", "return", "um", "(", "pmes", ".", "GetData", "(", ")", ")", "\n", "}" ]
// UnmarshalPrivateKey converts a protobuf serialized private key into its // representative object
[ "UnmarshalPrivateKey", "converts", "a", "protobuf", "serialized", "private", "key", "into", "its", "representative", "object" ]
9d2fed53443f745e6dc4d02bdcc94d9742a0ca84
https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/key.go#L305-L318
test
libp2p/go-libp2p-crypto
key.go
MarshalPrivateKey
func MarshalPrivateKey(k PrivKey) ([]byte, error) { pbmes := new(pb.PrivateKey) pbmes.Type = k.Type() data, err := k.Raw() if err != nil { return nil, err } pbmes.Data = data return proto.Marshal(pbmes) }
go
func MarshalPrivateKey(k PrivKey) ([]byte, error) { pbmes := new(pb.PrivateKey) pbmes.Type = k.Type() data, err := k.Raw() if err != nil { return nil, err } pbmes.Data = data return proto.Marshal(pbmes) }
[ "func", "MarshalPrivateKey", "(", "k", "PrivKey", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "pbmes", ":=", "new", "(", "pb", ".", "PrivateKey", ")", "\n", "pbmes", ".", "Type", "=", "k", ".", "Type", "(", ")", "\n", "data", ",", "err", ":=", "k", ".", "Raw", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "pbmes", ".", "Data", "=", "data", "\n", "return", "proto", ".", "Marshal", "(", "pbmes", ")", "\n", "}" ]
// MarshalPrivateKey converts a key object into its protobuf serialized form.
[ "MarshalPrivateKey", "converts", "a", "key", "object", "into", "its", "protobuf", "serialized", "form", "." ]
9d2fed53443f745e6dc4d02bdcc94d9742a0ca84
https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/key.go#L321-L331
test
libp2p/go-libp2p-crypto
key.go
KeyEqual
func KeyEqual(k1, k2 Key) bool { if k1 == k2 { return true } b1, err1 := k1.Bytes() b2, err2 := k2.Bytes() return bytes.Equal(b1, b2) && err1 == err2 }
go
func KeyEqual(k1, k2 Key) bool { if k1 == k2 { return true } b1, err1 := k1.Bytes() b2, err2 := k2.Bytes() return bytes.Equal(b1, b2) && err1 == err2 }
[ "func", "KeyEqual", "(", "k1", ",", "k2", "Key", ")", "bool", "{", "if", "k1", "==", "k2", "{", "return", "true", "\n", "}", "\n", "b1", ",", "err1", ":=", "k1", ".", "Bytes", "(", ")", "\n", "b2", ",", "err2", ":=", "k2", ".", "Bytes", "(", ")", "\n", "return", "bytes", ".", "Equal", "(", "b1", ",", "b2", ")", "&&", "err1", "==", "err2", "\n", "}" ]
// KeyEqual checks whether two
[ "KeyEqual", "checks", "whether", "two" ]
9d2fed53443f745e6dc4d02bdcc94d9742a0ca84
https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/key.go#L344-L352
test
libp2p/go-libp2p-crypto
ecdsa.go
GenerateECDSAKeyPair
func GenerateECDSAKeyPair(src io.Reader) (PrivKey, PubKey, error) { return GenerateECDSAKeyPairWithCurve(ECDSACurve, src) }
go
func GenerateECDSAKeyPair(src io.Reader) (PrivKey, PubKey, error) { return GenerateECDSAKeyPairWithCurve(ECDSACurve, src) }
[ "func", "GenerateECDSAKeyPair", "(", "src", "io", ".", "Reader", ")", "(", "PrivKey", ",", "PubKey", ",", "error", ")", "{", "return", "GenerateECDSAKeyPairWithCurve", "(", "ECDSACurve", ",", "src", ")", "\n", "}" ]
// GenerateECDSAKeyPair generates a new ecdsa private and public key
[ "GenerateECDSAKeyPair", "generates", "a", "new", "ecdsa", "private", "and", "public", "key" ]
9d2fed53443f745e6dc4d02bdcc94d9742a0ca84
https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/ecdsa.go#L45-L47
test
libp2p/go-libp2p-crypto
ecdsa.go
GenerateECDSAKeyPairWithCurve
func GenerateECDSAKeyPairWithCurve(curve elliptic.Curve, src io.Reader) (PrivKey, PubKey, error) { priv, err := ecdsa.GenerateKey(curve, src) if err != nil { return nil, nil, err } return &ECDSAPrivateKey{priv}, &ECDSAPublicKey{&priv.PublicKey}, nil }
go
func GenerateECDSAKeyPairWithCurve(curve elliptic.Curve, src io.Reader) (PrivKey, PubKey, error) { priv, err := ecdsa.GenerateKey(curve, src) if err != nil { return nil, nil, err } return &ECDSAPrivateKey{priv}, &ECDSAPublicKey{&priv.PublicKey}, nil }
[ "func", "GenerateECDSAKeyPairWithCurve", "(", "curve", "elliptic", ".", "Curve", ",", "src", "io", ".", "Reader", ")", "(", "PrivKey", ",", "PubKey", ",", "error", ")", "{", "priv", ",", "err", ":=", "ecdsa", ".", "GenerateKey", "(", "curve", ",", "src", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "return", "&", "ECDSAPrivateKey", "{", "priv", "}", ",", "&", "ECDSAPublicKey", "{", "&", "priv", ".", "PublicKey", "}", ",", "nil", "\n", "}" ]
// GenerateECDSAKeyPairWithCurve generates a new ecdsa private and public key with a speicified curve
[ "GenerateECDSAKeyPairWithCurve", "generates", "a", "new", "ecdsa", "private", "and", "public", "key", "with", "a", "speicified", "curve" ]
9d2fed53443f745e6dc4d02bdcc94d9742a0ca84
https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/ecdsa.go#L50-L57
test
libp2p/go-libp2p-crypto
ecdsa.go
ECDSAKeyPairFromKey
func ECDSAKeyPairFromKey(priv *ecdsa.PrivateKey) (PrivKey, PubKey, error) { if priv == nil { return nil, nil, ErrNilPrivateKey } return &ECDSAPrivateKey{priv}, &ECDSAPublicKey{&priv.PublicKey}, nil }
go
func ECDSAKeyPairFromKey(priv *ecdsa.PrivateKey) (PrivKey, PubKey, error) { if priv == nil { return nil, nil, ErrNilPrivateKey } return &ECDSAPrivateKey{priv}, &ECDSAPublicKey{&priv.PublicKey}, nil }
[ "func", "ECDSAKeyPairFromKey", "(", "priv", "*", "ecdsa", ".", "PrivateKey", ")", "(", "PrivKey", ",", "PubKey", ",", "error", ")", "{", "if", "priv", "==", "nil", "{", "return", "nil", ",", "nil", ",", "ErrNilPrivateKey", "\n", "}", "\n", "return", "&", "ECDSAPrivateKey", "{", "priv", "}", ",", "&", "ECDSAPublicKey", "{", "&", "priv", ".", "PublicKey", "}", ",", "nil", "\n", "}" ]
// ECDSAKeyPairFromKey generates a new ecdsa private and public key from an input private key
[ "ECDSAKeyPairFromKey", "generates", "a", "new", "ecdsa", "private", "and", "public", "key", "from", "an", "input", "private", "key" ]
9d2fed53443f745e6dc4d02bdcc94d9742a0ca84
https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/ecdsa.go#L60-L66
test
libp2p/go-libp2p-crypto
ecdsa.go
UnmarshalECDSAPrivateKey
func UnmarshalECDSAPrivateKey(data []byte) (PrivKey, error) { priv, err := x509.ParseECPrivateKey(data) if err != nil { return nil, err } return &ECDSAPrivateKey{priv}, nil }
go
func UnmarshalECDSAPrivateKey(data []byte) (PrivKey, error) { priv, err := x509.ParseECPrivateKey(data) if err != nil { return nil, err } return &ECDSAPrivateKey{priv}, nil }
[ "func", "UnmarshalECDSAPrivateKey", "(", "data", "[", "]", "byte", ")", "(", "PrivKey", ",", "error", ")", "{", "priv", ",", "err", ":=", "x509", ".", "ParseECPrivateKey", "(", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "ECDSAPrivateKey", "{", "priv", "}", ",", "nil", "\n", "}" ]
// UnmarshalECDSAPrivateKey returns a private key from x509 bytes
[ "UnmarshalECDSAPrivateKey", "returns", "a", "private", "key", "from", "x509", "bytes" ]
9d2fed53443f745e6dc4d02bdcc94d9742a0ca84
https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/ecdsa.go#L79-L86
test
libp2p/go-libp2p-crypto
ecdsa.go
UnmarshalECDSAPublicKey
func UnmarshalECDSAPublicKey(data []byte) (PubKey, error) { pubIfc, err := x509.ParsePKIXPublicKey(data) if err != nil { return nil, err } pub, ok := pubIfc.(*ecdsa.PublicKey) if !ok { return nil, ErrNotECDSAPubKey } return &ECDSAPublicKey{pub}, nil }
go
func UnmarshalECDSAPublicKey(data []byte) (PubKey, error) { pubIfc, err := x509.ParsePKIXPublicKey(data) if err != nil { return nil, err } pub, ok := pubIfc.(*ecdsa.PublicKey) if !ok { return nil, ErrNotECDSAPubKey } return &ECDSAPublicKey{pub}, nil }
[ "func", "UnmarshalECDSAPublicKey", "(", "data", "[", "]", "byte", ")", "(", "PubKey", ",", "error", ")", "{", "pubIfc", ",", "err", ":=", "x509", ".", "ParsePKIXPublicKey", "(", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "pub", ",", "ok", ":=", "pubIfc", ".", "(", "*", "ecdsa", ".", "PublicKey", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "ErrNotECDSAPubKey", "\n", "}", "\n", "return", "&", "ECDSAPublicKey", "{", "pub", "}", ",", "nil", "\n", "}" ]
// UnmarshalECDSAPublicKey returns the public key from x509 bytes
[ "UnmarshalECDSAPublicKey", "returns", "the", "public", "key", "from", "x509", "bytes" ]
9d2fed53443f745e6dc4d02bdcc94d9742a0ca84
https://github.com/libp2p/go-libp2p-crypto/blob/9d2fed53443f745e6dc4d02bdcc94d9742a0ca84/ecdsa.go#L89-L101
test