I have a code segment in my project that is set to Auto → JS because I am trying to get my study online to pavlovia. However, I am getting the error “/* Syntax Error: Fix Pyth code */”. I know that the issue is with the tuple code ’ for word,tag in pairs: ’ but I don’t know how to write the respective code in JS. Does anyone know how to do this in JS?
Here is the code:
thisExp.addData("typedWord", text_6.text)
displayed_text = text_6.text
print(displayed_text)
sentences = nltk.word_tokenize(displayed_text)
words = [nltk.word_tokenize(word) for word in sentences]
tagged_words = [nltk.pos_tag(sent) for sent in words] #tagged_words is a list of lists of tuples (ordered pairs basically)
print(tagged_words)
#make an empty freqDist object
tags = nltk.FreqDist()
#for each list in tagged words, get the (word, tag) tuple, ex. (action, 'NN')
# 'NN' is the tag in this case
for pairs in tagged_words:
for word,tag in pairs:
#add 1 to the counts for each tag
tags[tag] += 1
#how to get (and print) the frequency of 'NN's
print(tags.freq('CC'))
#how to print the FreqDist object
print(tags.most_common())
#sums up the desired frequencies, k is the 'NN' or 'VRB' or whatever
freq_sum = 0
for k in tags:
#if it starts with capital n, its a noun, change this to 'V' if u want verbs
if(k.startswith('CC')):
freq_sum += tags.freq(k)
print("Frequency: ", freq_sum)
print("Frequency (as %): ", round((freq_sum*(100)),2))
if hcount <= 3 and freq_sum >= 0.1:
nextRoutineNreps = 1
hcount+=1
elif hcount <=6 and freq_sum >= 0.15:
nextRoutineNreps = 1
hcount+=1
elif hcount <=9 and freq_sum >= 0.2:
nextRoutineNreps = 1
hcount+=1
elif hcount <=12 and freq_sum >= 0.25:
nextRoutineNreps = 1
hcount+=1
elif hcount <=15 and freq_sum >= 0.3:
nextRoutineNreps = 1
hcount+=1
elif hcount <= 18 and freq_sum >= 0.35:
nextRoutineNreps = 1
hcount+=1
elif hcount <= 21 and freq_sum >= 0.4:
nextRoutineNreps = 1
hcount+=1
elif hcount <= 24 and freq_sum >= 0.45:
nextRoutineNreps = 1
hcount+=1
elif hcount <= 27 and freq_sum >= 0.5:
nextRoutineNreps = 1
hcount+=1
elif hcount <= 30 and freq_sum >= 0.55:
nextRoutineNreps = 1
hcount+=1
elif hcount <= 33 and freq_sum >= 0.6:
nextRoutineNreps = 1
hcount+=1
elif hcount <= 36 and freq_sum >= 0.65:
nextRoutineNreps = 1
hcount+=1
elif hcount <= 39 and freq_sum >= 0.7:
nextRoutineNreps = 1
hcount+=1
else:
nextRoutineNreps = 0