Markov chain using processing - Python

0 votes

I have a function def for Markov chain to create sentences. This is def:

def createProbabilityHash(words):
    numWords = len(words)
    wordCount = {}
    for word in words:
        if wordCount.has_key(word):
            wordCount[word] += 1
        else:
            wordCount[word] = 1

Now I want a definition to build the same thing in processing. Can someone help me out with it? Thank you!

Aug 2 in Machine Learning by Gujjar
7 views

1 answer to this question.

0 votes

Try something like this @Gujjar

HashMap<String, int> wordCount;

int createProbabilityHash(words):
    int numWords = words.size();
    wordCount = new HashMap<String, int>();
    for (int i = 0;i < numWords; ++i) {
        if wordCount.containsKey(words[i]) {
            wordCount.put(words[i], wordCount.get(words[i]) + 1);
        } else {
            wordCount.put(words[i], 1);
        }
    }
answered Aug 2 by Ashish

Related Questions In Machine Learning

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Example to run KNN algorithm using python

Have a look at this one: from sklearn.datasets ...READ MORE

answered May 8 in Machine Learning by Harvy
59 views
0 votes
1 answer
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 169 views
+4 votes
6 answers
0 votes
1 answer