_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3
values | text stringlengths 52 85.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q34100 | MarshalJSON | train | func (c *BoxComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
Layout FlexBoxLayoutType `json:"layout"`
Contents []FlexComponent `json:"contents"`
Flex *int `json:"flex,omitempty"`
Spacing FlexCom... | go | {
"resource": ""
} |
q34101 | MarshalJSON | train | func (c *ButtonComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
Action TemplateAction `json:"action"`
Flex *int `json:"flex,omitempty"`
Margin FlexComponentMarginType `json:"margin,omitempty"`
Height F... | go | {
"resource": ""
} |
q34102 | MarshalJSON | train | func (c *FillerComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
}{
Type: FlexComponentTypeFiller,
})
} | go | {
"resource": ""
} |
q34103 | MarshalJSON | train | func (c *IconComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
URL string `json:"url"`
Margin FlexComponentMarginType `json:"margin,omitempty"`
Size FlexIconSizeType `json:"size,omitempty"`
As... | go | {
"resource": ""
} |
q34104 | MarshalJSON | train | func (c *ImageComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
URL string `json:"url"`
Flex *int `json:"flex,omitempty"`
Margin FlexComponentMarginType `json:"ma... | go | {
"resource": ""
} |
q34105 | MarshalJSON | train | func (c *SeparatorComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
Margin FlexComponentMarginType `json:"margin,omitempty"`
Color string `json:"color,omitempty"`
}{
Type: FlexComponentTypeSeparator,
Margin: c.Margin,
... | go | {
"resource": ""
} |
q34106 | MarshalJSON | train | func (c *SpacerComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
Size FlexSpacerSizeType `json:"size,omitempty"`
}{
Type: FlexComponentTypeSpacer,
Size: c.Size,
})
} | go | {
"resource": ""
} |
q34107 | MarshalJSON | train | func (c *TextComponent) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type FlexComponentType `json:"type"`
Text string `json:"text"`
Flex *int `json:"flex,omitempty"`
Margin FlexComponentMarginType `json:"margin,omitempty"`
Size FlexT... | go | {
"resource": ""
} |
q34108 | MarshalJSON | train | func (e *Event) MarshalJSON() ([]byte, error) {
raw := rawEvent{
ReplyToken: e.ReplyToken,
Type: e.Type,
Timestamp: e.Timestamp.Unix()*millisecPerSec + int64(e.Timestamp.Nanosecond())/int64(time.Millisecond),
Source: e.Source,
Postback: e.Postback,
}
if e.Beacon != nil {
raw.Beacon = &rawBea... | go | {
"resource": ""
} |
q34109 | UnmarshalJSON | train | func (e *Event) UnmarshalJSON(body []byte) (err error) {
rawEvent := rawEvent{}
if err = json.Unmarshal(body, &rawEvent); err != nil {
return
}
e.ReplyToken = rawEvent.ReplyToken
e.Type = rawEvent.Type
e.Timestamp = time.Unix(rawEvent.Timestamp/millisecPerSec, (rawEvent.Timestamp%millisecPerSec)*nanosecPerMill... | go | {
"resource": ""
} |
q34110 | MarshalJSON | train | func (b *QuickReplyButton) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type string `json:"type"`
ImageURL string `json:"imageUrl,omitempty"`
Action QuickReplyAction `json:"action"`
}{
Type: "action",
ImageURL: b.ImageURL,
Action: b.Action,
})
} | go | {
"resource": ""
} |
q34111 | MarshalJSON | train | func (a *URIAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ActionType `json:"type"`
Label string `json:"label,omitempty"`
URI string `json:"uri"`
AltURI *URIActionAltURI `json:"altUri,omitempty"`
}{
Type: ActionTypeURI,
Label: a.Label,
URI: ... | go | {
"resource": ""
} |
q34112 | MarshalJSON | train | func (a *MessageAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ActionType `json:"type"`
Label string `json:"label,omitempty"`
Text string `json:"text"`
}{
Type: ActionTypeMessage,
Label: a.Label,
Text: a.Text,
})
} | go | {
"resource": ""
} |
q34113 | MarshalJSON | train | func (a *PostbackAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ActionType `json:"type"`
Label string `json:"label,omitempty"`
Data string `json:"data"`
Text string `json:"text,omitempty"`
DisplayText string `json:"displayText,omitempty"`... | go | {
"resource": ""
} |
q34114 | MarshalJSON | train | func (a *DatetimePickerAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ActionType `json:"type"`
Label string `json:"label,omitempty"`
Data string `json:"data"`
Mode string `json:"mode"`
Initial string `json:"initial,omitempty"`
Max string `json:... | go | {
"resource": ""
} |
q34115 | MarshalJSON | train | func (a *CameraAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ActionType `json:"type"`
Label string `json:"label"`
}{
Type: ActionTypeCamera,
Label: a.Label,
})
} | go | {
"resource": ""
} |
q34116 | MarshalJSON | train | func (a *CameraRollAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ActionType `json:"type"`
Label string `json:"label"`
}{
Type: ActionTypeCameraRoll,
Label: a.Label,
})
} | go | {
"resource": ""
} |
q34117 | MarshalJSON | train | func (a *LocationAction) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type ActionType `json:"type"`
Label string `json:"label"`
}{
Type: ActionTypeLocation,
Label: a.Label,
})
} | go | {
"resource": ""
} |
q34118 | MarshalJSON | train | func (m *TextMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
Text string `json:"text"`
QuickReply *QuickReplyItems `json:"quickReply,omitempty"`
}{
Type: MessageTypeText,
Text: m.Text,
QuickReply: m.quickReplyitem... | go | {
"resource": ""
} |
q34119 | WithQuickReplies | train | func (m *TextMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
} | go | {
"resource": ""
} |
q34120 | MarshalJSON | train | func (m *ImageMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
OriginalContentURL string `json:"originalContentUrl"`
PreviewImageURL string `json:"previewImageUrl"`
QuickReply *QuickReplyItems `json:"quickRep... | go | {
"resource": ""
} |
q34121 | WithQuickReplies | train | func (m *ImageMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
} | go | {
"resource": ""
} |
q34122 | MarshalJSON | train | func (m *VideoMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
OriginalContentURL string `json:"originalContentUrl"`
PreviewImageURL string `json:"previewImageUrl"`
QuickReply *QuickReplyItems `json:"quickRep... | go | {
"resource": ""
} |
q34123 | WithQuickReplies | train | func (m *VideoMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
} | go | {
"resource": ""
} |
q34124 | MarshalJSON | train | func (m *AudioMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
OriginalContentURL string `json:"originalContentUrl"`
Duration int `json:"duration"`
QuickReply *QuickReplyItems `json:"quickReply,omit... | go | {
"resource": ""
} |
q34125 | WithQuickReplies | train | func (m *AudioMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
} | go | {
"resource": ""
} |
q34126 | MarshalJSON | train | func (m *LocationMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
Title string `json:"title"`
Address string `json:"address"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"... | go | {
"resource": ""
} |
q34127 | WithQuickReplies | train | func (m *LocationMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
} | go | {
"resource": ""
} |
q34128 | MarshalJSON | train | func (m *StickerMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
PackageID string `json:"packageId"`
StickerID string `json:"stickerId"`
QuickReply *QuickReplyItems `json:"quickReply,omitempty"`
}{
Type: MessageTypeS... | go | {
"resource": ""
} |
q34129 | WithQuickReplies | train | func (m *StickerMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
} | go | {
"resource": ""
} |
q34130 | MarshalJSON | train | func (m *TemplateMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
AltText string `json:"altText"`
Template Template `json:"template"`
QuickReply *QuickReplyItems `json:"quickReply,omitempty"`
}{
Type: MessageTypeTem... | go | {
"resource": ""
} |
q34131 | WithQuickReplies | train | func (m *TemplateMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
} | go | {
"resource": ""
} |
q34132 | MarshalJSON | train | func (m *ImagemapMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
BaseURL string `json:"baseUrl"`
AltText string `json:"altText"`
BaseSize ImagemapBaseSize `json:"baseSize"`
Actions []ImagemapAction `json:"actions"... | go | {
"resource": ""
} |
q34133 | WithQuickReplies | train | func (m *ImagemapMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
} | go | {
"resource": ""
} |
q34134 | MarshalJSON | train | func (m *FlexMessage) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Type MessageType `json:"type"`
AltText string `json:"altText"`
Contents interface{} `json:"contents"`
QuickReply *QuickReplyItems `json:"quickReply,omitempty"`
}{
Type: MessageTypeFlex,
... | go | {
"resource": ""
} |
q34135 | WithQuickReplies | train | func (m *FlexMessage) WithQuickReplies(items *QuickReplyItems) SendingMessage {
m.quickReplyitems = items
return m
} | go | {
"resource": ""
} |
q34136 | NewScanner | train | func (call *GetGroupMemberIDsCall) NewScanner() *IDsScanner {
var ctx context.Context
if call.ctx != nil {
ctx = call.ctx
} else {
ctx = context.Background()
}
c2 := &GetGroupMemberIDsCall{}
*c2 = *call
c2.ctx = ctx
return &IDsScanner{
caller: c2,
ctx: ctx,
}
} | go | {
"resource": ""
} |
q34137 | ID | train | func (s *IDsScanner) ID() string {
if len(s.ids) == 0 {
return ""
}
return s.ids[s.start : s.start+1][0]
} | go | {
"resource": ""
} |
q34138 | New | train | func New(channelSecret, channelToken string) (*WebhookHandler, error) {
if channelSecret == "" {
return nil, errors.New("missing channel secret")
}
if channelToken == "" {
return nil, errors.New("missing channel access token")
}
h := &WebhookHandler{
channelSecret: channelSecret,
channelToken: channelToke... | go | {
"resource": ""
} |
q34139 | Localize | train | func (l *Localizer) Localize(lc *LocalizeConfig) (string, error) {
msg, _, err := l.LocalizeWithTag(lc)
return msg, err
} | go | {
"resource": ""
} |
q34140 | LocalizeWithTag | train | func (l *Localizer) LocalizeWithTag(lc *LocalizeConfig) (string, language.Tag, error) {
messageID := lc.MessageID
if lc.DefaultMessage != nil {
if messageID != "" && messageID != lc.DefaultMessage.ID {
return "", language.Und, &messageIDMismatchErr{messageID: messageID, defaultMessageID: lc.DefaultMessage.ID}
... | go | {
"resource": ""
} |
q34141 | MustLocalize | train | func (l *Localizer) MustLocalize(lc *LocalizeConfig) string {
localized, err := l.Localize(lc)
if err != nil {
panic(err)
}
return localized
} | go | {
"resource": ""
} |
q34142 | ParseMessageFileBytes | train | func ParseMessageFileBytes(buf []byte, path string, unmarshalFuncs map[string]UnmarshalFunc) (*MessageFile, error) {
lang, format := parsePath(path)
tag := language.Make(lang)
messageFile := &MessageFile{
Path: path,
Tag: tag,
Format: format,
}
if len(buf) == 0 {
return messageFile, nil
}
unmarshalF... | go | {
"resource": ""
} |
q34143 | recGetMessages | train | func recGetMessages(raw interface{}, isMapMessage, isInitialCall bool) ([]*Message, error) {
var messages []*Message
var err error
switch data := raw.(type) {
case string:
if isInitialCall {
return nil, errInvalidTranslationFile
}
m, err := NewMessage(data)
return []*Message{m}, err
case map[string]in... | go | {
"resource": ""
} |
q34144 | extractMessages | train | func extractMessages(buf []byte) ([]*i18n.Message, error) {
fset := token.NewFileSet()
file, err := parser.ParseFile(fset, "", buf, parser.AllErrors)
if err != nil {
return nil, err
}
extractor := newExtractor(file)
ast.Walk(extractor, file)
return extractor.messages, nil
} | go | {
"resource": ""
} |
q34145 | RegisterPluralSpec | train | func RegisterPluralSpec(ids []string, ps *PluralSpec) {
for _, id := range ids {
id = normalizePluralSpecID(id)
pluralSpecs[id] = ps
}
} | go | {
"resource": ""
} |
q34146 | Plural | train | func (ps *PluralSpec) Plural(number interface{}) (Plural, error) {
ops, err := newOperands(number)
if err != nil {
return Invalid, err
}
return ps.PluralFunc(ops), nil
} | go | {
"resource": ""
} |
q34147 | GetPluralSpec | train | func GetPluralSpec(tag string) *PluralSpec {
tag = NormalizeTag(tag)
subtag := tag
for {
if spec := pluralSpecs[subtag]; spec != nil {
return spec
}
end := strings.LastIndex(subtag, "-")
if end == -1 {
return nil
}
subtag = subtag[:end]
}
} | go | {
"resource": ""
} |
q34148 | Parse | train | func Parse(src string) []*Language {
var langs []*Language
start := 0
for end, chr := range src {
switch chr {
case ',', ';', '.':
tag := strings.TrimSpace(src[start:end])
if spec := GetPluralSpec(tag); spec != nil {
langs = append(langs, &Language{NormalizeTag(tag), spec})
}
start = end + 1
}
... | go | {
"resource": ""
} |
q34149 | MustParse | train | func MustParse(src string) []*Language {
langs := Parse(src)
if len(langs) == 0 {
panic(fmt.Errorf("unable to parse language from %q", src))
}
return langs
} | go | {
"resource": ""
} |
q34150 | Add | train | func Add(l *Language) {
tag := NormalizeTag(l.Tag)
pluralSpecs[tag] = l.PluralSpec
} | go | {
"resource": ""
} |
q34151 | NormalizeTag | train | func NormalizeTag(tag string) string {
tag = strings.ToLower(tag)
return strings.Replace(tag, "_", "-", -1)
} | go | {
"resource": ""
} |
q34152 | TfuncAndLanguage | train | func TfuncAndLanguage(languageSource string, languageSources ...string) (TranslateFunc, *language.Language, error) {
tfunc, lang, err := defaultBundle.TfuncAndLanguage(languageSource, languageSources...)
return TranslateFunc(tfunc), lang, err
} | go | {
"resource": ""
} |
q34153 | RegisterUnmarshalFunc | train | func (b *Bundle) RegisterUnmarshalFunc(format string, unmarshalFunc UnmarshalFunc) {
if b.unmarshalFuncs == nil {
b.unmarshalFuncs = make(map[string]UnmarshalFunc)
}
b.unmarshalFuncs[format] = unmarshalFunc
} | go | {
"resource": ""
} |
q34154 | LoadMessageFile | train | func (b *Bundle) LoadMessageFile(path string) (*MessageFile, error) {
buf, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
return b.ParseMessageFileBytes(buf, path)
} | go | {
"resource": ""
} |
q34155 | MustLoadMessageFile | train | func (b *Bundle) MustLoadMessageFile(path string) {
if _, err := b.LoadMessageFile(path); err != nil {
panic(err)
}
} | go | {
"resource": ""
} |
q34156 | ParseMessageFileBytes | train | func (b *Bundle) ParseMessageFileBytes(buf []byte, path string) (*MessageFile, error) {
messageFile, err := internal.ParseMessageFileBytes(buf, path, b.unmarshalFuncs)
if err != nil {
return nil, err
}
if err := b.AddMessages(messageFile.Tag, messageFile.Messages...); err != nil {
return nil, err
}
return mes... | go | {
"resource": ""
} |
q34157 | MustParseMessageFileBytes | train | func (b *Bundle) MustParseMessageFileBytes(buf []byte, path string) {
if _, err := b.ParseMessageFileBytes(buf, path); err != nil {
panic(err)
}
} | go | {
"resource": ""
} |
q34158 | AddMessages | train | func (b *Bundle) AddMessages(tag language.Tag, messages ...*Message) error {
pluralRule := b.pluralRules.Rule(tag)
if pluralRule == nil {
return fmt.Errorf("no plural rule registered for %s", tag)
}
if b.messageTemplates == nil {
b.messageTemplates = map[language.Tag]map[string]*internal.MessageTemplate{}
}
i... | go | {
"resource": ""
} |
q34159 | MustAddMessages | train | func (b *Bundle) MustAddMessages(tag language.Tag, messages ...*Message) {
if err := b.AddMessages(tag, messages...); err != nil {
panic(err)
}
} | go | {
"resource": ""
} |
q34160 | NequalsAny | train | func (o *Operands) NequalsAny(any ...int64) bool {
for _, i := range any {
if o.I == i && o.T == 0 {
return true
}
}
return false
} | go | {
"resource": ""
} |
q34161 | NmodEqualsAny | train | func (o *Operands) NmodEqualsAny(mod int64, any ...int64) bool {
modI := o.I % mod
for _, i := range any {
if modI == i && o.T == 0 {
return true
}
}
return false
} | go | {
"resource": ""
} |
q34162 | NewMessage | train | func NewMessage(data interface{}) (*Message, error) {
m := &Message{}
if err := m.unmarshalInterface(data); err != nil {
return nil, err
}
return m, nil
} | go | {
"resource": ""
} |
q34163 | MustNewMessage | train | func MustNewMessage(data interface{}) *Message {
m, err := NewMessage(data)
if err != nil {
panic(err)
}
return m
} | go | {
"resource": ""
} |
q34164 | unmarshalInterface | train | func (m *Message) unmarshalInterface(v interface{}) error {
strdata, err := stringMap(v)
if err != nil {
return err
}
for k, v := range strdata {
switch strings.ToLower(k) {
case "id":
m.ID = v
case "description":
m.Description = v
case "hash":
m.Hash = v
case "leftdelim":
m.LeftDelim = v
... | go | {
"resource": ""
} |
q34165 | NewMessageTemplate | train | func NewMessageTemplate(m *Message) *MessageTemplate {
pluralTemplates := map[plural.Form]*Template{}
setPluralTemplate(pluralTemplates, plural.Zero, m.Zero)
setPluralTemplate(pluralTemplates, plural.One, m.One)
setPluralTemplate(pluralTemplates, plural.Two, m.Two)
setPluralTemplate(pluralTemplates, plural.Few, m.... | go | {
"resource": ""
} |
q34166 | Execute | train | func (mt *MessageTemplate) Execute(pluralForm plural.Form, data interface{}, funcs template.FuncMap) (string, error) {
t := mt.PluralTemplates[pluralForm]
if t == nil {
return "", pluralFormNotFoundError{
pluralForm: pluralForm,
messageID: mt.Message.ID,
}
}
if err := t.parse(mt.LeftDelim, mt.RightDelim,... | go | {
"resource": ""
} |
q34167 | NewOperands | train | func NewOperands(number interface{}) (*Operands, error) {
switch number := number.(type) {
case int:
return newOperandsInt64(int64(number)), nil
case int8:
return newOperandsInt64(int64(number)), nil
case int16:
return newOperandsInt64(int64(number)), nil
case int32:
return newOperandsInt64(int64(number)),... | go | {
"resource": ""
} |
q34168 | Name | train | func (pg *PluralGroup) Name() string {
n := strings.Title(pg.Locales)
return strings.Replace(n, " ", "", -1)
} | go | {
"resource": ""
} |
q34169 | Condition | train | func (pr *PluralRule) Condition() string {
i := strings.Index(pr.Rule, "@")
return pr.Rule[:i]
} | go | {
"resource": ""
} |
q34170 | Examples | train | func (pr *PluralRule) Examples() (integer []string, decimal []string) {
ex := strings.Replace(pr.Rule, ", …", "", -1)
ddelim := "@decimal"
if i := strings.Index(ex, ddelim); i > 0 {
dex := strings.TrimSpace(ex[i+len(ddelim):])
decimal = strings.Split(dex, ", ")
ex = ex[:i]
}
idelim := "@integer"
if i := str... | go | {
"resource": ""
} |
q34171 | activeDst | train | func activeDst(src, dst *internal.MessageTemplate, pluralRule *plural.Rule) (active *internal.MessageTemplate, translateMessageTemplate *internal.MessageTemplate) {
pluralForms := pluralRule.PluralForms
if len(src.PluralTemplates) == 1 {
pluralForms = map[plural.Form]struct{}{
plural.Other: {},
}
}
for plura... | go | {
"resource": ""
} |
q34172 | NewPlural | train | func NewPlural(src string) (Plural, error) {
switch src {
case "zero":
return Zero, nil
case "one":
return One, nil
case "two":
return Two, nil
case "few":
return Few, nil
case "many":
return Many, nil
case "other":
return Other, nil
}
return Invalid, fmt.Errorf("invalid plural category %s", src)
} | go | {
"resource": ""
} |
q34173 | New | train | func New() *Bundle {
return &Bundle{
translations: make(map[string]map[string]translation.Translation),
fallbackTranslations: make(map[string]map[string]translation.Translation),
}
} | go | {
"resource": ""
} |
q34174 | MustLoadTranslationFile | train | func (b *Bundle) MustLoadTranslationFile(filename string) {
if err := b.LoadTranslationFile(filename); err != nil {
panic(err)
}
} | go | {
"resource": ""
} |
q34175 | deleteLeadingComments | train | func deleteLeadingComments(ext string, buf []byte) []byte {
if ext != ".yaml" {
return buf
}
for {
buf = bytes.TrimLeftFunc(buf, unicode.IsSpace)
if buf[0] == '#' {
buf = deleteLine(buf)
} else {
break
}
}
return buf
} | go | {
"resource": ""
} |
q34176 | Translations | train | func (b *Bundle) Translations() map[string]map[string]translation.Translation {
t := make(map[string]map[string]translation.Translation)
b.RLock()
for tag, translations := range b.translations {
t[tag] = make(map[string]translation.Translation)
for id, translation := range translations {
t[tag][id] = translat... | go | {
"resource": ""
} |
q34177 | LanguageTags | train | func (b *Bundle) LanguageTags() []string {
var tags []string
b.RLock()
for k := range b.translations {
tags = append(tags, k)
}
b.RUnlock()
return tags
} | go | {
"resource": ""
} |
q34178 | LanguageTranslationIDs | train | func (b *Bundle) LanguageTranslationIDs(languageTag string) []string {
var ids []string
b.RLock()
for id := range b.translations[languageTag] {
ids = append(ids, id)
}
b.RUnlock()
return ids
} | go | {
"resource": ""
} |
q34179 | Tfunc | train | func (b *Bundle) Tfunc(pref string, prefs ...string) (TranslateFunc, error) {
tfunc, _, err := b.TfuncAndLanguage(pref, prefs...)
return tfunc, err
} | go | {
"resource": ""
} |
q34180 | supportedLanguage | train | func (b *Bundle) supportedLanguage(pref string, prefs ...string) *language.Language {
lang := b.translatedLanguage(pref)
if lang == nil {
for _, pref := range prefs {
lang = b.translatedLanguage(pref)
if lang != nil {
break
}
}
}
return lang
} | go | {
"resource": ""
} |
q34181 | Rule | train | func (r Rules) Rule(tag language.Tag) *Rule {
t := tag
for {
if rule := r[t]; rule != nil {
return rule
}
t = t.Parent()
if t.IsRoot() {
break
}
}
base, _ := tag.Base()
baseTag, _ := language.Parse(base.String())
return r[baseTag]
} | go | {
"resource": ""
} |
q34182 | ReadTagged | train | func ReadTagged(text, sep string) TupleSlice {
t := TupleSlice{}
for _, sent := range strings.Split(text, "\n") {
tokens := []string{}
tags := []string{}
for _, token := range strings.Split(sent, " ") {
parts := strings.Split(token, sep)
tokens = append(tokens, parts[0])
tags = append(tags, parts[1])
... | go | {
"resource": ""
} |
q34183 | Tokenize | train | func (r RegexpTokenizer) Tokenize(text string) []string {
var tokens []string
if r.gaps {
temp := r.regex.Split(text, -1)
if r.discard {
for _, s := range temp {
if s != "" {
tokens = append(tokens, s)
}
}
} else {
tokens = temp
}
} else {
tokens = r.regex.FindAllString(text, -1)
}
... | go | {
"resource": ""
} |
q34184 | NewBlanklineTokenizer | train | func NewBlanklineTokenizer() *RegexpTokenizer {
return &RegexpTokenizer{
regex: regexp.MustCompile(`\s*\n\s*\n\s*`), gaps: true, discard: true}
} | go | {
"resource": ""
} |
q34185 | quadsString | train | func quadsString(tagged []tag.Token) string {
tagQuads := ""
for _, tok := range tagged {
padding := ""
pos := tok.Tag
switch len(pos) {
case 0:
padding = "____" // should not exist
case 1:
padding = "___"
case 2:
padding = "__"
case 3:
padding = "_"
case 4: // no padding required
defaul... | go | {
"resource": ""
} |
q34186 | Chunk | train | func Chunk(tagged []tag.Token, rx *regexp.Regexp) []string {
chunks := []string{}
for _, loc := range Locate(tagged, rx) {
res := ""
for t, tt := range tagged[loc[0]:loc[1]] {
if t != 0 {
res += " "
}
res += tt.Text
}
chunks = append(chunks, res)
}
return chunks
} | go | {
"resource": ""
} |
q34187 | Locate | train | func Locate(tagged []tag.Token, rx *regexp.Regexp) [][]int {
rx.Longest() // make sure we find the longest possible sequences
rs := rx.FindAllStringIndex(quadsString(tagged), -1)
for i, ii := range rs {
for j := range ii {
// quadsString makes every offset 4x what it should be
rs[i][j] /= 4
}
}
return rs... | go | {
"resource": ""
} |
q34188 | Title | train | func (tc *TitleConverter) Title(s string) string {
idx, pos := 0, 0
t := sanitizer.Replace(s)
end := len(t)
return splitRE.ReplaceAllStringFunc(s, func(m string) string {
sm := strings.ToLower(m)
pos = strings.Index(t[idx:], m) + idx
prev := charAt(t, pos-1)
ext := utf8.RuneCountInString(m)
idx = pos + ex... | go | {
"resource": ""
} |
q34189 | charAt | train | func charAt(s string, i int) byte {
if i >= 0 && i < len(s) {
return s[i]
}
return s[0]
} | go | {
"resource": ""
} |
q34190 | toTitle | train | func toTitle(m string, prev byte) string {
r, size := utf8.DecodeRuneInString(m)
return string(unicode.ToTitle(r)) + m[size:]
} | go | {
"resource": ""
} |
q34191 | NewAveragedPerceptron | train | func NewAveragedPerceptron(weights map[string]map[string]float64,
tags map[string]string, classes []string) *AveragedPerceptron {
return &AveragedPerceptron{
totals: make(map[string]float64), stamps: make(map[string]float64),
classes: classes, tagMap: tags, weights: weights}
} | go | {
"resource": ""
} |
q34192 | NewPerceptronTagger | train | func NewPerceptronTagger() *PerceptronTagger {
var wts map[string]map[string]float64
var tags map[string]string
var classes []string
dec := model.GetAsset("classes.gob")
util.CheckError(dec.Decode(&classes))
dec = model.GetAsset("tags.gob")
util.CheckError(dec.Decode(&tags))
dec = model.GetAsset("weights.gob... | go | {
"resource": ""
} |
q34193 | Tag | train | func (pt *PerceptronTagger) Tag(words []string) []Token {
var tokens []Token
var clean []string
var tag string
var found bool
p1, p2 := "-START-", "-START2-"
context := []string{p1, p2}
for _, w := range words {
if w == "" {
continue
}
context = append(context, normalize(w))
clean = append(clean, w)
... | go | {
"resource": ""
} |
q34194 | Train | train | func (pt *PerceptronTagger) Train(sentences TupleSlice, iterations int) {
var guess string
var found bool
pt.makeTagMap(sentences)
for i := 0; i < iterations; i++ {
for _, tuple := range sentences {
words, tags := tuple[0], tuple[1]
p1, p2 := "-START-", "-START2-"
context := []string{p1, p2}
for _, w... | go | {
"resource": ""
} |
q34195 | Pascal | train | func Pascal(s string) string {
out := ""
wasSpace := false
for i, c := range removeCase(s, " ", unicode.ToLower) {
if i == 0 || wasSpace {
c = unicode.ToUpper(c)
}
wasSpace = c == ' '
if !wasSpace {
out += string(c)
}
}
return out
} | go | {
"resource": ""
} |
q34196 | Camel | train | func Camel(s string) string {
first := ' '
for _, c := range s {
if unicode.IsLetter(c) || unicode.IsNumber(c) {
first = c
break
}
}
return strings.TrimSpace(string(unicode.ToLower(first)) + Pascal(s)[1:])
} | go | {
"resource": ""
} |
q34197 | ReadDataFile | train | func ReadDataFile(path string) []byte {
p, err := filepath.Abs(path)
CheckError(err)
data, ferr := ioutil.ReadFile(p)
CheckError(ferr)
return data
} | go | {
"resource": ""
} |
q34198 | IsPunct | train | func IsPunct(c byte) bool {
for _, r := range []byte("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~") {
if c == r {
return true
}
}
return false
} | go | {
"resource": ""
} |
q34199 | IsSpace | train | func IsSpace(c byte) bool {
for _, r := range []byte("\t\n\r\f\v") {
if c == r {
return true
}
}
return false
} | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.