Ramaraunt1

interpreter so far

May 30th, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. func simpleSlicer(phrase string) []string {
  2. slice := ""
  3. returns := make([]string, 0, 0)
  4. for x := 0; x < len(phrase); x++ {
  5. if string(phrase[x]) == " " {
  6. returns = append(returns, slice)
  7. slice = ""
  8. } else {
  9. slice += string(phrase[x])
  10. }
  11. }
  12.  
  13. for x := 0; x < len(returns); x++ {
  14. if returns[x] == "a" || returns[x] == "an" || returns[x] == "the" {
  15. returns[x] = "^"
  16. }
  17. }
  18.  
  19. return returns
  20. }
  21. func interpret(verbs []verb, nouns []*thing, phrase string) (verb, *thing, *thing) {
  22. slicedPhrase := simpleSlicer(phrase)
  23. subPhrases := make([]string, 0, 0)
  24. samples := make([]samp, 0, 0)
  25. for x := 0; x < len(slicedPhrase); x++ {
  26. subPhrases = append(subPhrases, "")
  27. for y := 0; y < len(subPhrases)-1; y++ {
  28. subPhrases[y] += " " + slicedPhrase[x]
  29. }
  30. subPhrases[len(subPhrases)-1] = slicedPhrase[x]
  31. pos := 1
  32. for y := 0; y < len(subPhrases); y++ {
  33. samps := interpretWord(verbs, nouns, subPhrases[y], pos)
  34. for z := 0; z < len(samps); z++ {
  35. samples = append(samples, samps[z])
  36. }
  37. pos++
  38. }
  39. }
  40.  
  41. return nil, nil, nil
  42. }
  43.  
  44. func interpretWord(verbs []verb, nouns []*thing, phrase string, pos int) []samp {
  45.  
  46. samps := make([]samp, 0, 0)
  47. for _, v := range verbs {
  48. for _, vi := range v.verbs {
  49. if phrase == vi {
  50. // isVerb = true
  51. samps = append(samps, samp{true, false, &v, nil, vi, pos})
  52. }
  53. }
  54.  
  55. for _, avi := range v.adverbs {
  56. if phrase == avi {
  57. // isAdverb = true
  58. samps = append(samps, samp{true, true, &v, nil, avi, pos})
  59. }
  60. }
  61. }
  62.  
  63. for _, n := range nouns {
  64. for _, ni := range n.terms {
  65. if ni == phrase {
  66. // isNoun = true
  67. samps = append(samps, samp{false, false, nil, n, ni, pos})
  68. }
  69. }
  70.  
  71. for _, aji := range n.adjectives {
  72. if phrase == aji {
  73. // isAdjective = true
  74. samps = append(samps, samp{false, true, nil, n, aji, pos})
  75. }
  76. }
  77. }
  78.  
  79. return samps
  80.  
  81. }
  82.  
  83. type samp struct {
  84. verb bool
  85. secondary bool
  86. ver *verb
  87. nou *thing
  88. term string
  89. pos int
  90. }
Advertisement
Add Comment
Please, Sign In to add comment