Advertisement
Ramaraunt1

Permutation Algorithm

May 31st, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. package sfp
  2.  
  3. //////////////////////////////////////////////////////////////////////////////////////////
  4.  
  5. const (
  6. VERB string = "KIND_verb"
  7. ADVERB string = "KIND_adv"
  8. NOUN string = "KIND_noun"
  9. ADJECTIVE string = "KIND_adj"
  10.  
  11. NONE string = "none"
  12. )
  13.  
  14. func (g game) calculateInput(input string) {
  15. wordCount := countWords(input)
  16. local := g.determineLocalObjectsOfActor(g.player)
  17. Slice := simpleSlicer(input)
  18. ArticleSlice := getArticlePositions(Slice)
  19. permutations := getPermutations(Slice, ArticleSlice, g.verbs, local, wordCount)
  20. }
  21.  
  22. func getPermutations(Slice []string, ArticleSlice []article, verbs []verb, local []*thing, wordCount int) []samp {
  23. sampList := make([]samp, 0, 0)
  24. for x := -1; x < len(ArticleSlice); x++ { //for each space between the articles
  25. var rangeTop int //first lets the determine the top and bottom positions between these two articles
  26. var rangeBottom int
  27. if x == -1 { //we are before the first article
  28. rangeBottom = 0
  29. if len(ArticleSlice) == 0 {
  30. rangeTop = wordCount - 1
  31. } else {
  32. rangeTop = ArticleSlice[0].position
  33. }
  34. } else if x >= 0 && x < len(ArticleSlice)-1 { //we are in between the first and the last article
  35. rangeBottom = ArticleSlice[x].position + 1
  36. rangeTop = ArticleSlice[x+1].position
  37. } else if x == len(ArticleSlice)-1 { //we are after the last article
  38. rangeBottom = ArticleSlice[x].position + 1
  39. rangeTop = wordCount - 1
  40. }
  41. for y := rangeBottom; y < rangeTop; y++ { //for each index in the range between articles (between rangeBottom and rangeTop)
  42. for z := 0; z < rangeTop; z++ { //for every possible size of a term within this space
  43. if y+z < rangeTop { //if the selection fits between the articles
  44. testString := ""
  45. for a := y; a < y+z; a++ {
  46. testString += Slice[a]
  47. if a < y+z-1 {
  48. testString += " "
  49. }
  50. }
  51. }
  52. }
  53. }
  54. }
  55. return sampList
  56. }
  57.  
  58. func getArticlePositions(Slice []string) []article {
  59. returnSlice := make([]article, 0, 0)
  60. for x := 0; x < len(Slice); x++ {
  61. if isInteger(Slice[x]) {
  62. test := returnInteger(Slice[x])
  63. if test == 1 {
  64. returnSlice = append(returnSlice, article{test, false, x})
  65. } else {
  66. returnSlice = append(returnSlice, article{test, true, x})
  67. }
  68. } else if Slice[x] == "the" || Slice[x] == "this" || Slice[x] == "that" {
  69. returnSlice = append(returnSlice, article{1, false, x})
  70. } else if Slice[x] == "some" || Slice[x] == "those" || Slice[x] == "these" {
  71. returnSlice = append(returnSlice, article{1, true, x})
  72. }
  73. }
  74. }
  75.  
  76. func simpleSlicer(phrase string) []string {
  77. slice := ""
  78. returns := make([]string, 0, 0)
  79. for x := 0; x < len(phrase); x++ {
  80. if string(phrase[x]) == " " && slice != "" {
  81. returns = append(returns, slice)
  82. slice = ""
  83. } else if x < len(phrase)-1 && string(phrase[x]) != "," {
  84. slice += string(phrase[x])
  85. } else if x == len(phrase)-1 && !isPunctuation(string(phrase[x])) {
  86. slice += string(phrase[x])
  87. }
  88. }
  89.  
  90. if slice != "" {
  91. returns = append(returns, slice)
  92. }
  93.  
  94. return returns
  95. }
  96.  
  97. func interpretWord(verbs []verb, nouns []*thing, phrase string, pos int, art int) []samp {
  98.  
  99. samps := make([]samp, 0, 0)
  100. for _, v := range verbs {
  101. for _, vi := range v.verbs {
  102. if phrase == vi {
  103. // isVerb = true
  104. samps = append(samps, samp{true, false, &v, nil, vi, pos, art})
  105. }
  106. }
  107.  
  108. for _, avi := range v.adverbs {
  109. if phrase == avi {
  110. // isAdverb = true
  111. samps = append(samps, samp{true, true, &v, nil, avi, pos, art})
  112. }
  113. }
  114. }
  115.  
  116. for _, n := range nouns {
  117. for _, ni := range n.terms {
  118. if ni == phrase {
  119. // isNoun = true
  120. samps = append(samps, samp{false, false, nil, n, ni, pos, art})
  121. }
  122. }
  123.  
  124. for _, aji := range n.adjectives {
  125. if phrase == aji {
  126. // isAdjective = true
  127. samps = append(samps, samp{false, true, nil, n, aji, pos, art})
  128. }
  129. }
  130. }
  131.  
  132. return samps
  133.  
  134. }
  135.  
  136. type samp struct {
  137. verb bool
  138. secondary bool
  139. ver *verb
  140. nou *thing
  141. term string
  142. pos int
  143. article int
  144. }
  145.  
  146. type article struct {
  147. amount int
  148. plural bool
  149. position int
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement