Imam malo cudno pitanje/zahtev, ali, da li bi neko mogao da mi isformatira ovaj kod (tj. najbitnija mi je indentacija da bude pravilna) pravilno :-)
Code (python):
import re
from itertools import groupby
def viterbi_segment(text):
probs, lasts = [1.0], [0]
for i in range(1, len(text) + 1):
prob_k, k = max((probs[j] * word_prob(text[j:i]), j)
for j in range(max(0, i - max_word_length), i))
probs.append(prob_k)
lasts.append(k)
words = []
i = len(text)
while 0 < i:
words.append(text[lasts[i]:i])
i = lasts[i]
words.reverse()
return words, probs[-1]
def word_prob(word): return dictionary.get(word, 0) / total
def words(text): return re.findall('[a-z]+', text.lower())
dictionary = dict((w, len(list(ws)))
for w, ws in groupby(sorted(words(open('word_list.txt').read()))))
max_word_length = max(map(len, dictionary))
total = float(sum(dictionary.values()))
import re
from itertools import groupby
def viterbi_segment(text):
probs, lasts = [1.0], [0]
for i in range(1, len(text) + 1):
prob_k, k = max((probs[j] * word_prob(text[j:i]), j)
for j in range(max(0, i - max_word_length), i))
probs.append(prob_k)
lasts.append(k)
words = []
i = len(text)
while 0 < i:
words.append(text[lasts[i]:i])
i = lasts[i]
words.reverse()
return words, probs[-1]
def word_prob(word): return dictionary.get(word, 0) / total
def words(text): return re.findall('[a-z]+', text.lower())
dictionary = dict((w, len(list(ws)))
for w, ws in groupby(sorted(words(open('word_list.txt').read()))))
max_word_length = max(map(len, dictionary))
total = float(sum(dictionary.values()))
Problem je sto Python, malo je reci da pojma nemam, al posto znam sta ovaj kod treba da radi i delimicno kako radi, problem mi je samo da pohvatam celine (gde se zavrsava koji "def" / loop) da bih mogao ovo da prekucam u PHP :-)
Hvala ;)))