Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sfp
- //////////////////////////////////////////////////////////////////////////////////////////
- const (
- VERB string = "KIND_verb"
- ADVERB string = "KIND_adv"
- NOUN string = "KIND_noun"
- ADJECTIVE string = "KIND_adj"
- NONE string = "none"
- )
- func (g game) calculateInput(input string) {
- wordCount := countWords(input)
- local := g.determineLocalObjectsOfActor(g.player)
- Slice := simpleSlicer(input)
- ArticleSlice := getArticlePositions(Slice)
- permutations := getPermutations(Slice, ArticleSlice, g.verbs, local, wordCount)
- }
- func getPermutations(Slice []string, ArticleSlice []article, verbs []verb, local []*thing, wordCount int) []samp {
- sampList := make([]samp, 0, 0)
- for x := -1; x < len(ArticleSlice); x++ { //for each space between the articles
- var rangeTop int //first lets the determine the top and bottom positions between these two articles
- var rangeBottom int
- if x == -1 { //we are before the first article
- rangeBottom = 0
- if len(ArticleSlice) == 0 {
- rangeTop = wordCount - 1
- } else {
- rangeTop = ArticleSlice[0].position
- }
- } else if x >= 0 && x < len(ArticleSlice)-1 { //we are in between the first and the last article
- rangeBottom = ArticleSlice[x].position + 1
- rangeTop = ArticleSlice[x+1].position
- } else if x == len(ArticleSlice)-1 { //we are after the last article
- rangeBottom = ArticleSlice[x].position + 1
- rangeTop = wordCount - 1
- }
- for y := rangeBottom; y < rangeTop; y++ { //for each index in the range between articles (between rangeBottom and rangeTop)
- for z := 0; z < rangeTop; z++ { //for every possible size of a term within this space
- if y+z < rangeTop { //if the selection fits between the articles
- testString := ""
- for a := y; a < y+z; a++ {
- testString += Slice[a]
- if a < y+z-1 {
- testString += " "
- }
- }
- }
- }
- }
- }
- return sampList
- }
- func getArticlePositions(Slice []string) []article {
- returnSlice := make([]article, 0, 0)
- for x := 0; x < len(Slice); x++ {
- if isInteger(Slice[x]) {
- test := returnInteger(Slice[x])
- if test == 1 {
- returnSlice = append(returnSlice, article{test, false, x})
- } else {
- returnSlice = append(returnSlice, article{test, true, x})
- }
- } else if Slice[x] == "the" || Slice[x] == "this" || Slice[x] == "that" {
- returnSlice = append(returnSlice, article{1, false, x})
- } else if Slice[x] == "some" || Slice[x] == "those" || Slice[x] == "these" {
- returnSlice = append(returnSlice, article{1, true, x})
- }
- }
- }
- func simpleSlicer(phrase string) []string {
- slice := ""
- returns := make([]string, 0, 0)
- for x := 0; x < len(phrase); x++ {
- if string(phrase[x]) == " " && slice != "" {
- returns = append(returns, slice)
- slice = ""
- } else if x < len(phrase)-1 && string(phrase[x]) != "," {
- slice += string(phrase[x])
- } else if x == len(phrase)-1 && !isPunctuation(string(phrase[x])) {
- slice += string(phrase[x])
- }
- }
- if slice != "" {
- returns = append(returns, slice)
- }
- return returns
- }
- func interpretWord(verbs []verb, nouns []*thing, phrase string, pos int, art int) []samp {
- samps := make([]samp, 0, 0)
- for _, v := range verbs {
- for _, vi := range v.verbs {
- if phrase == vi {
- // isVerb = true
- samps = append(samps, samp{true, false, &v, nil, vi, pos, art})
- }
- }
- for _, avi := range v.adverbs {
- if phrase == avi {
- // isAdverb = true
- samps = append(samps, samp{true, true, &v, nil, avi, pos, art})
- }
- }
- }
- for _, n := range nouns {
- for _, ni := range n.terms {
- if ni == phrase {
- // isNoun = true
- samps = append(samps, samp{false, false, nil, n, ni, pos, art})
- }
- }
- for _, aji := range n.adjectives {
- if phrase == aji {
- // isAdjective = true
- samps = append(samps, samp{false, true, nil, n, aji, pos, art})
- }
- }
- }
- return samps
- }
- type samp struct {
- verb bool
- secondary bool
- ver *verb
- nou *thing
- term string
- pos int
- article int
- }
- type article struct {
- amount int
- plural bool
- position int
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement