main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
var sonnet = ["A man who", "has never seen", "fire", "(before) would never think", "that", "it could burn", "rather", "would strike him", "as a delight", "(and) great fun", "its splendor", "when he first saw it", "if he", "(ever) touched it", "anywhere", "then", "it would seem", "to him it burned", "(and) bad", "the one", "(that belongs) to Love", "has touched me", "a little", "a lot", "it burns me", "God", "if it only took hold!", "If it only took hold", "in you", "my lady", "who", "make me", "think you mean to comfort me", "by loving me", "and you", "(you) give me", "(only) distress", "and torments", "certainly", "Love", "acts", "ignobly", "for he does not tie you down", "who", "come forth", "only with words", "to me", "I serve", "Yet he gives me no", "happiness"];

// Create a function writeLine that takes a Markov Chain (object) and a length of words n and returns a line of poetry.

// writeLine will need a helper function that takes a word and randomly chooses a word from its Markov Chain array. When a word has no entries in it's Markov Chain, the program should choose a new word and continue the line until it meets the word count.

function poem(sonnet){
    
      //class notes//
//     var obj = {}; 
     //obj.hello = "world"; 
// console.log(obj) // { hello: "world" }


    //empty object variable//
    //var wordPairs = {};
    //console.log(wordPairs.corpus);
    var wordPairs = {};
    
    for(var i=0; i<sonnet.length - 1; i++){
      var key = sonnet[i];
      var value = sonnet[i + 1];
      
      wordPairs[key] = [value];
      
    }//end of for loop//

    return wordPairs;
    
}//end of function// 

var markovChain = poem(sonnet);
//var random = Math.random();
//var engTranslate = [];
//function writeLine//
function writeLine(markovChain, n){
  
  //n is the length of words; 
  for(var i=0; i<n; i++){
  
  
  //push 7 random verses into empty array//
 
 
    var random = parseInt(Math.random()*Object.values(markovChain).length);
    console.log(Object.values(markovChain)[random][0]);
    
   //console.log(Object.values(markovChain));
 
 
 //use key to get value 
 //with key, get key's value
 //math.random()
 
 //^random number is for array of random words  
 //from key you get the value

 
  }

}

  writeLine(markovChain, 7);   
        
  poem(sonnet);
  
        //wordPairs = console.log(sonetto[i] + ":" + " [" + sonetto[i + 1] + "],");//
      
      
      
        //if (typeof Object.keys(wordPairs) !== 'undefined' && Object.keys(wordPairs).length > 0) {
        // You have an array 
         //return Object.keys(wordPairs);
          
        //}
        
      
      //console.log(sonetto[i]);
     // wordPairs = sonetto[i];
      //var corpus = sonetto[i];
      //wordPairs.corpus == sonetto[i + 1];
      //wordPairs[sonetto[1]];
      
      //coerce string to value pair//
      
      
        //crazyObj[myKey] = crazyObj[boolean]
       //var myKey = "boolean";
      //crazyObj[myKey];

      
      // var newKey = sonetto[1];
      // newKey[sonetto[1]];
      
      //wordPairs.corpus = sonetto[i];
      //console.log(wordPairs.corpus);
      
      //Chicken Scratch
      //sonetto[i + 1];
      
    //Second Idea  
    //wordPairs = console.log(wordPairs + "." + sonetto[i]);
    //console.log(Object.keys(wordPairs));
      
      //First Idea
      //wordPairs = console.log(sonetto[i] + ":" + " [" +  sonetto[i + 1] + "],");
Native Browser JavaScript