Beispiel #1
0
func Test1(t *testing.T) {
	mockNounOpt := map[string]interface{}{
		"cars": map[string]interface{}{
			"composed_of": []interface{}{"testModuleA"},
		},
	}
	spkr := speaker.New(moduleHasVerb, mockNounOpt)
	if spkr.IsNoun("comments") {
		t.Fatal()
	}
	if spkr.NounHasVerb("cars", "verbB") {
		t.Fatal()
	}
}
Beispiel #2
0
func TestVerbLocation(t *testing.T) {
	mockNounOpt := map[string]interface{}{
		"cars": map[string]interface{}{
			"composed_of": []interface{}{"testModuleA"},
		},
	}
	spkr := speaker.New(moduleHasVerb, mockNounOpt)
	if spkr.VerbLocation("cars", "verbA") != "testModuleA" {
		t.Fatal()
	}
	if spkr.VerbLocation("x", "y") != "" {
		t.Fatal()
	}
	spkr.Fallback = "fakeModule"
	if spkr.VerbLocation("x", "y") != "fakeModule" {
		t.Fatal()
	}
}
Beispiel #3
0
func Identify(path string, nouns map[string]interface{}, inp map[string]interface{}) (*Descriptor, error) {
	desc := &Descriptor{}
	r, err := lang.NewRoute(path, inp)
	if err != nil {
		return nil, err
	}
	desc.Route = r
	speaker := speaker.New(moduleHasVerb, nouns)
	sentence, err := lang.NewSentence(r, speaker)
	if err != nil {
		return nil, err
	}
	desc.Sentence = sentence
	nounOpt, has := nouns[sentence.Noun].(map[string]interface{})
	if !has {
		return nil, fmt.Errorf("Noun opt is missing or not a map.")
	}
	desc.nounOpt = nounOpt
	loc := speaker.VerbLocation(sentence.Noun, sentence.Verb)
	desc.VerbLocation = loc
	return desc, nil
}