Example #1
0
func (m Meaning) Features() []mlearning.Feature {
	fs := make([]mlearning.Feature, 0)
	fs = append(fs, "bias")

	// if m.Predicate != "" {
	// 	fs = append(fs, mlearning.Feature("predicate="+m.Predicate))
	// }
	// if m.Object != "" {
	// 	fs = append(fs, mlearning.Feature("object="+m.Object))
	// }
	for i, t := range m.Tokens {
		if i == 0 {
			fs = append(fs, mlearning.Feature("first="+t.Lemma))
		}
		if i == 1 {
			fs = append(fs, mlearning.Feature("second="+t.Lemma))
		}

		fs = append(fs, mlearning.Feature("word="+t.Lemma))
	}
	for _, v := range m.Vars {
		fs = append(fs, mlearning.Feature("var="+v.Name))
	}
	return fs
}
Example #2
0
func (f *varFeature) Features() []mlearning.Feature {
	fs := map[string]struct{}{}

	addFeat(fs, "bias")
	if f.Pos > 0 {
		addFeat(fs, "1 word", f.Sentence[0].Lemma)
		addFeat(fs, "i-1 word", f.Sentence[f.Pos-1].Lemma)
	}
	if f.Pos > 1 {
		addFeat(fs, "2 word", f.Sentence[1].Lemma)
		addFeat(fs, "i-2 word", f.Sentence[f.Pos-2].Lemma)
	}
	if f.Action != "" {
		addFeat(fs, "action", f.Action)

		parts := strings.SplitN(f.Action, "/", 4)
		for i := 0; i < len(parts); i++ {
			addFeat(fs, strconv.Itoa(i)+" action", strings.Join(parts[0:i], "/"))
		}
	}

	fslice := make([]mlearning.Feature, 0, len(fs))
	for f := range fs {
		fslice = append(fslice, mlearning.Feature(f))
	}
	return fslice
}