Commit 160a3842 authored by GURPARKASH SINGH's avatar GURPARKASH SINGH

Added all the Files of the Project

parents
#lang racket
(struct dictionary (word branches) #:transparent)
(define my-dictionary (dictionary "" (make-vector 26 #f)))
(define (null-string? s) (equal? s ""))
(define (add-to-dictionary-word word book)
(define (add-to-dictionary-helper current word book)
(cond [(null-string? current) (if (dictionary? book) (dictionary word (dictionary-branches book))
(dictionary word (make-vector 26 #f)))]
[else
(let* ([n (get-index (string-ref current 0))]
[d (if (dictionary? book) book (dictionary "" (make-vector 26 #f)))]
[w (dictionary-word d)]
[b (dictionary-branches d)]
[v (vector-ref b n)])
(set! v (add-to-dictionary-helper (substring current 1) word (if (not (equal? #f v)) v (dictionary "" (make-vector 26 #f)))))
(vector-set! b n v)
(dictionary w b))]))
(set! book (add-to-dictionary-helper word word book)))
(define (add-to-dictionary-list words book)
(map (lambda (w) (begin (add-to-dictionary-word w book) w)) words)
(set! words words))
(define (get-index c)
(cond [(char=? c #\a) 00] [(char=? c #\b) 01] [(char=? c #\c) 02] [(char=? c #\d) 03]
[(char=? c #\e) 04] [(char=? c #\f) 05] [(char=? c #\g) 06] [(char=? c #\h) 07]
[(char=? c #\i) 08] [(char=? c #\j) 09] [(char=? c #\k) 10] [(char=? c #\l) 11]
[(char=? c #\m) 12] [(char=? c #\n) 13] [(char=? c #\o) 14] [(char=? c #\p) 15]
[(char=? c #\q) 16] [(char=? c #\r) 17] [(char=? c #\s) 18] [(char=? c #\t) 19]
[(char=? c #\u) 20] [(char=? c #\v) 21] [(char=? c #\w) 22] [(char=? c #\x) 23]
[(char=? c #\y) 24] [(char=? c #\z) 25]))
(define (print-dictionary book)
(let ([ans '()]
[w (dictionary-word book)]
[v (dictionary-branches book)])
(cond [(not (null-string? w)) (set! ans (cons w ans))])
(begin
(map (lambda (b) (begin (cond [(not (eq? #f b)) (set! ans (append ans (print-dictionary b)))]) #t)) (vector->list v))
ans)))
(define (auto-complete word book)
(cond [(not (dictionary? book)) '()]
[(null-string? word) (print-dictionary book)]
[else (auto-complete (substring word 1) (vector-ref (dictionary-branches book) (get-index (string-ref word 0))))]))
\ No newline at end of file
#lang racket
; Delete later
(struct dictionary (word frequency branches) #:transparent)
(define my-dictionary (dictionary "" 0 (make-vector 26 #f)))
(define (null-string? s) (equal? s ""))
(define (get-index c)
(cond [(char=? c #\a) 00] [(char=? c #\b) 01] [(char=? c #\c) 02] [(char=? c #\d) 03]
[(char=? c #\e) 04] [(char=? c #\f) 05] [(char=? c #\g) 06] [(char=? c #\h) 07]
[(char=? c #\i) 08] [(char=? c #\j) 09] [(char=? c #\k) 10] [(char=? c #\l) 11]
[(char=? c #\m) 12] [(char=? c #\n) 13] [(char=? c #\o) 14] [(char=? c #\p) 15]
[(char=? c #\q) 16] [(char=? c #\r) 17] [(char=? c #\s) 18] [(char=? c #\t) 19]
[(char=? c #\u) 20] [(char=? c #\v) 21] [(char=? c #\w) 22] [(char=? c #\x) 23]
[(char=? c #\y) 24] [(char=? c #\z) 25]))
(define (sort-words vec)
(vector-sort vec (lambda (a b) (> (cdr a) (cdr b)))))
; Delete later
(define alphabets '( #\a #\b #\c #\d #\e #\f #\g #\h #\i #\j #\k #\l #\m
#\n #\o #\p #\q #\r #\s #\t #\u #\v #\w #\x #\y #\z))
(define (correct? word book)
(define (correct?-helper current book)
(cond [(not (dictionary? book)) #f]
[(null-string? current)
(if (string=? word (dictionary-word book))
(dictionary-frequency book)
#f)]
[else
(let ([n (get-index (string-ref current 0))])
(correct?-helper
(substring current 1)
(vector-ref (dictionary-branches book) n)))]))
(correct?-helper word book))
(define (auto-correct word)
(if
(correct? word my-dictionary)
word
(let* ([a (type-1 word)]
[b (type-2 word)]
[c (type-3 word)]
[d (type-4 word)]
[e (add-ranks (append a b c d))])
(vector->list (sort-words (list->vector e))))))
(define (type-1 word)
(let ([l (string->list word)]
[ans '()])
(begin (map (lambda (c) (begin (set! ans (cons (list->string (remove c l)) ans)) c)) l)
ans)))
(define (type-2 word)
(define (type-2-helper start d end ans)
(cond [(null? end) (cons (list->string (append start (list d))) ans)]
[else
(type-2-helper (append start (list (car end)))
d
(cdr end)
(cons (list->string (append start (list d) end)) ans))]))
(let ([ans '()])
(begin (map (lambda (d) (begin (set! ans (cons (type-2-helper '() d (string->list word) '()) ans)) d)) alphabets)
(flatten ans))))
(define (type-3 word)
(define (type-3-helper start d end ans)
(cond [(null? end) ans]
[(type-3-helper (append start (list (car end))) d (cdr end) (cons (list->string (append start (list d) (cdr end))) ans))]))
(let ([ans '()])
(begin (map (lambda (d) (begin (set! ans (cons (type-3-helper '() d (string->list word) '()) ans)) d)) alphabets)
(flatten ans))))
(define (type-4 word)
(define (type-4-helper start w1 w2 end ans)
(cond [(null? end) (cons (list->string (append start (list w2) (list w1))) ans)]
[(type-4-helper (append start (list w1))
w2 (car end) (cdr end)
(cons (list->string (append start (list w2) (list w1) end)) ans))]))
(let ([ans '()]
[l (string->list word)])
(type-4-helper '() (car l) (cadr l) (cddr l) '())))
(define (add-ranks words)
(define (refine l ans)
(if (null? l) ans
(let* ([a (car l)]
[b (if (eq? #f (cdr a)) ans (cons a ans))])
(refine (cdr l) b))))
(refine (map (lambda (w) (cons w (correct? w my-dictionary))) words) '()))
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#lang racket
(provide s1 s2 s3)
(define s1
"it is my dream college i worked hard for it
my exam ruined scored only one three five in
jee mains because of the thought of my friends
teacher pressure or expectations from my side
i used to score above two three zero in mock
test in jee mains i used to solve and collect
each mock test of my friends and solved it my
teachers used to say")
(define s2
"before the third round of international olympiad
of astronomy and astrophysics two zero one five which
was held in indonesia i got food poisoned i realized it
the night before the examination in the middle of the night")
(define s3
"i woke up in the cold breeze of the air conditioner
i knew something was wrong my body was aching i was feeling
extreme cold and my head was spinning i noticed my nausea and
walked to the toilet shortly after i vomited twice on the morning
things were worse i was still extremely unwell but most importantly
i was sad that it happened on my examination day i wanted that medal
for which i worked day and night")
;
;I didn’t give up and did everything I could even when weak.
;
;I was sent to the examination hall with a special, arranged-for-me car. A medic was staying close to me, in case there was an emergency.
;
;During the exam, I felt weak, but each time I wanted to leave the hall, I kept telling myself to
;
;GO ON.
;
;There was a time when I demanded my hands to take the pen and finish the problems.
;
;In the end, THIS happened."
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment