ws = [' ']
pu = ['!','.','?',',']
--Първата дума от низ
getWord [] = []
getWord (h:t)
| elem h ws = []
| otherwise = h : (getWord t)
--Изтрива първата дума от низ
drE [] = []
drE (h:t)
| elem h ws = t
| otherwise = drE t
--Подрежда низа в списък от думи
spW [] = []
spW s = (getWord(s)) : (spW (drE(s)))
cS [] = []
cS (h:t)
| elem h pu = cS t
| otherwise = h : (cS t)
--Само уникалните елементи
unW [] = []
unW (h:t)
| [ s | s<-t , s == h ] == [] = h : (unW t)
| otherwise = unW t
--Броя на уникалните елементи по ред на появяване в низа
bR [] = []
bR (h:t) = ((length [ s | s<-t ,s == h]) + 1) : (bR [ s | s<-t ,s /= h ])
--Нареждане в редове!
respl l = spL (spW l)
spL [] = []
spL l = (ml l 30) : ( spL (drL (ml l 30) l))
ml [] k =[]
ml s k
| length (head s) <= k = (head s) : ( ml (tail s) ( k - 1 - length (head s)))
| otherwise = []
drL [] l = l
drL (h:t) (s:q) = drL t q
--Ляво подреждане
mr [] = "/n"
mr (h:t) = h ++ " " ++ mr t
mwh [] = []
mwh (h:t) = (mr h) : (mwh t)
reshenie l = mwh (respl l)
whiteSpaces = [' ','\n']
letters=['A'..'Z']++['a'..'z']
getword a
|null a || elem (head a) whiteSpaces || not(elem (head a) letters)= []
|otherwise = (head a):(getword (tail a))
dropword a = drop (length (getword a)) a
--dropspaces a = [i|i<-a, not(elem i whiteSpaces)]
dropspaces a
|elem (head a) whiteSpaces = dropspaces(tail a)
|otherwise = a
splitwords a
|a==[] = []
|otherwise = (getword a) : [getword (dropspaces(dropword a))]
clearword a = [i|i<-a,elem i letters]
uniqwords a
|null a = []
|null d = (c:[])
|elem c q = uniqwords d
|otherwise = c:(uniqwords d)
where q = [clearword i|i<-(tail a)]
c = clearword (head a)
d = tail a
countword a c
|null c = 0
|a == head c = 1+(countword a (tail c))
|otherwise = countword a (tail c)
wordcounter a
|null a = []
|otherwise = zip q ([countword i [clearword t|t<-a]|i<-q])
where q = uniqwords a
mgetline [] l = []
mgetline (a:b) l
|length a <= l = a:(mgetline b (l-(length a)-1))
|otherwise = []
where q = head b
f = tail b
mdropline [] l = []
mdropline (a:b) l
|length a <= l = mdropline b (l-(length a)-1)
|otherwise = (a:b)
where q = head b
f = tail b
splitlines words l
|null words = []
|otherwise = (mgetline words l):[(mgetline (mdropline words l) l)]
getWord s
|s==[] =[]
|elem (head s) whiteSpaces==True =[]
|otherwise =[head s] ++ getWord (tail s)
dropWord s
|s==[] =[]
|elem (head s) whiteSpaces = s
|otherwise = drop (length (getWord s)) s
whiteSpaces=['\n',' ']
dropSpaces s
|null s = []
|elem (head s) whiteSpaces =dropSpaces (tail s)
|otherwise =s
splitWords s
|null s =[]
|otherwise = (getWord s) : splitWords ( dropSpaces ( dropWord s ))
znaciP=['!',',','.']
clearWord s
|s==[] =[]
|elem (head s) znaciP = clearWord (tail s)
|otherwise =(head s) :( clearWord (tail s))
uniqueWords s
|s==[] = []
|elem (head s) (tail s) = uniqueWords (tail s)
|otherwise = (clearWord (head s)): (uniqueWords (tail s))
pomosht x list
|list==[] =0
|x == (head list) =1+(pomosht x (tail list))
|otherwise =(pomosht x (tail list))
wordCounter unique all = [(word,pomosht word all) | word <- unique]
whiteSpaces=[' ','\n']
spaces=['.',',',':',';','!','?','(',')','*']
getWord [] = []
getWord (s:hs)
|elem s whiteSpaces = []
|otherwise = s:getWord hs
dropWord [] = []
dropWord (s:hs)
|elem s whiteSpaces = s:hs
|otherwise = dropWord hs
dropSpaces [] = []
dropSpaces (s:hs)
|elem s whiteSpaces =dropSpaces hs
|otherwise = (s:hs)
splitWords s
|s==[]=[]
|otherwise = (getWord s):splitWords (dropSpaces (dropWord s))
clearWord [] = []
clearWord (s:hs)
|elem s spaces = clearWord hs
|otherwise = s:clearWord hs
uniqueWord [] = []
uniqueWord (s:hs)
|s==[]=[]
|elem s hs = uniqueWord hs
|otherwise = (clearWord s):uniqueWord hs
memCount x [] = 0
memCount x (s:hs)
|x==s=1+memCount x hs
|otherwise = memCount x hs
wordCounter u a = [ (w , memCount w a )| w <- u]
getline (s:hs) l
|l<length s = []
|otherwise = s : (getline hs (l-(length s)))
uniqueWord l
|l==[] =[]
|elem (head l) (tail l) = uniqueWord (tail l)
|otherwise = (head l):(uniqueWord (tail l))
memCount x l
|l==[] =0
|x==(head l) = 1+(memCount x (tail l))
|otherwise = memCount x (tail l)
wordCounter u l
|u==[] =[]
|otherwise = ((head u),(memCount (head u) l)): (wordCounter (tail u) l)
u=["aaa","bbb"]
l=["aaa","aaa","bb","bbb"]
wordCounter1 u l
| ((head u),(memCount (head u) l)): (wordCounter1 (tail u) l)