-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMini Project 8.rkt
More file actions
872 lines (756 loc) · 40.4 KB
/
Mini Project 8.rkt
File metadata and controls
872 lines (756 loc) · 40.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
#lang racket
(require csc151)
(require csc151/rex)
(require rackunit)
(require rackunit/text-ui)
;;; CSC-151 - Rebelsky
;;; Mini Project 8: Sentence and Word Analysis
;;; Date: November 19 - December 5
;;; Names: Elliot Swaim, Jules Wood, Matilda Carne, Nifemi Ogunmesa
;;; Acknowledgements:
;;; - Verb forms dictionary taken from https://github.com/monolithpl/verb.forms.dictionary
;;; - Adjective, Adverb, Conjunction, Interjection and Preposition Dictionaries taken from https://github.com/verachell/English-word-lists-parts-of-speech-approximate/tree/main/other-categories
;;; - Noun dictionary taken from https://github.com/djstrong/nouns-with-plurals
;;; - Edgar Allen Poe (The Raven) for the sample text
#|
User's Guide
Word analysis
Input a word, output a struct which includes:
* the given word
* the part of speech
* additional characteristics if applicable to part of speech
* (so with nouns, will tell if it was singular or plural)
* we use dictionaries
* it can also look at larger text bodies
Can input word of specific type if noun/verb/pronoun to get description:
> (string->verb "leverage")
(word-kernel "leverage" (conjuclention-kernel "verb" (conjugation-kernel 'base)))
> (string->noun "egg")
(word-kernel "egg" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
> (string->pronoun "her")
(word-kernel "her" (conjuclention-kernel "pronoun" (declention-kernel "singular" "feminine" '())))
Can input word without telling type and have it find type of word:
> (string->word "cats")
(word-kernel "cats" (conjuclention-kernel "noun" (declention-kernel "plural" '() '())))
> (string->word "crunchy")
(word-kernel "crunchy" (conjuclention-kernel "adjective" '()))
> (string->word "jumping")
(word-kernel "jumping" (conjuclention-kernel "verb" (conjugation-kernel 'present-participle)))
> (string->word "sakhkjhdjkahskjh")
(word-kernel "sakhkjhdjkahskjh" (conjuclention-kernel "unknown" '()))
Can work on longer strings of words:
> (string->sentence "this is an example sentence, that should have some nouns and some verbs.")
(sentence-kernel
(list
(word-kernel "this" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "is" (conjuclention-kernel "verb" (conjugation-kernel 'present-simple)))
(word-kernel "an" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "example" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "sentence" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "that" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "should" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "have" (conjuclention-kernel "verb" (conjugation-kernel 'base)))
(word-kernel "some" (conjuclention-kernel "indefinite pronoun" (declention-kernel '() '() '())))
(word-kernel "nouns" (conjuclention-kernel "noun" (declention-kernel "plural" '() '())))
(word-kernel "and" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "some" (conjuclention-kernel "indefinite pronoun" (declention-kernel '() '() '())))
(word-kernel "verbs" (conjuclention-kernel "noun" (declention-kernel "plural" '() '())))))
can work on a file
> (file->paragraphs "sample-text.txt")
(paragraph-kernel
(list
(sentence-kernel
(list
(word-kernel "once" (conjuclention-kernel "adverb" '()))
(word-kernel "upon" (conjuclention-kernel "preposition" '()))
(word-kernel "a" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "midnight" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "dreary" (conjuclention-kernel "adjective" '()))
(word-kernel "while" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "i" (conjuclention-kernel "unknown" '()))
(word-kernel "pondered" (conjuclention-kernel "verb" (conjugation-kernel 'past-simple)))
(word-kernel "weak" (conjuclention-kernel "adjective" '()))
(word-kernel "and" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "weary" (conjuclention-kernel "verb" (conjugation-kernel 'base)))))
(sentence-kernel
(list
(word-kernel "over" (conjuclention-kernel "adjective" '()))
(word-kernel "many" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "a" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "quaint" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "and" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "curious" (conjuclention-kernel "adjective" '()))
(word-kernel "volume" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "of" (conjuclention-kernel "preposition" '()))
(word-kernel "forgotten" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "lore" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))))
(sentence-kernel
(list
(word-kernel "while" (conjuclention-kernel "preposition" '()))
(word-kernel "i" (conjuclention-kernel "unknown" '()))
(word-kernel "nodded" (conjuclention-kernel "verb" (conjugation-kernel 'past-simple)))
(word-kernel "nearly" (conjuclention-kernel "adverb" '()))
(word-kernel "napping" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "suddenly" (conjuclention-kernel "adverb" '()))
(word-kernel "there" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "came" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "a" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "tapping" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))))
(sentence-kernel
(list
(word-kernel "as" (conjuclention-kernel "preposition" '()))
(word-kernel "of" (conjuclention-kernel "preposition" '()))
(word-kernel "some" (conjuclention-kernel "indefinite pronoun" (declention-kernel '() '() '())))
(word-kernel "one" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "gently" (conjuclention-kernel "adverb" '()))
(word-kernel "rapping" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "rapping" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "at" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "my" (conjuclention-kernel "pronoun" (declention-kernel "singular" '() '())))
(word-kernel "chamber" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "door" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))))
(sentence-kernel
(list
(word-kernel "tis" (conjuclention-kernel "unknown" '()))
(word-kernel "some" (conjuclention-kernel "indefinite pronoun" (declention-kernel '() '() '())))
(word-kernel "visitor" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "i" (conjuclention-kernel "unknown" '()))
(word-kernel "muttered" (conjuclention-kernel "verb" (conjugation-kernel 'past-simple)))
(word-kernel "tapping" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "at" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "my" (conjuclention-kernel "pronoun" (declention-kernel "singular" '() '())))
(word-kernel "chamber" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "door" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))))
(sentence-kernel
(list
(word-kernel "only" (conjuclention-kernel "adjective" '()))
(word-kernel "this" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "and" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "nothing" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "more" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))))
(sentence-kernel
(list
(word-kernel "ah" (conjuclention-kernel "unknown" '()))
(word-kernel "distinctly" (conjuclention-kernel "adverb" '()))
(word-kernel "i" (conjuclention-kernel "unknown" '()))
(word-kernel "remember" (conjuclention-kernel "verb" (conjugation-kernel 'base)))
(word-kernel "it" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "was" (conjuclention-kernel "verb" (conjugation-kernel 'past-simple)))
(word-kernel "in" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "the" (conjuclention-kernel "adjective" '()))
(word-kernel "bleak" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "december" (conjuclention-kernel "unknown" '()))))
(sentence-kernel
(list
(word-kernel "and" (conjuclention-kernel "conjunction" '()))
(word-kernel "each" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "separate" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "dying" (conjuclention-kernel "verb" (conjugation-kernel 'present-participle)))
(word-kernel "ember" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "wrought" (conjuclention-kernel "verb" (conjugation-kernel 'base)))
(word-kernel "its" (conjuclention-kernel "noun" (declention-kernel "plural" '() '())))
(word-kernel "ghost" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "upon" (conjuclention-kernel "preposition" '()))
(word-kernel "the" (conjuclention-kernel "adjective" '()))
(word-kernel "floor" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))))
(sentence-kernel
(list
(word-kernel "eagerly" (conjuclention-kernel "adverb" '()))
(word-kernel "i" (conjuclention-kernel "unknown" '()))
(word-kernel "wished" (conjuclention-kernel "verb" (conjugation-kernel 'past-simple)))
(word-kernel "the" (conjuclention-kernel "adjective" '()))
(word-kernel "morrow" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "vainly" (conjuclention-kernel "adverb" '()))
(word-kernel "i" (conjuclention-kernel "unknown" '()))
(word-kernel "had" (conjuclention-kernel "verb" (conjugation-kernel 'past-simple)))
(word-kernel "sought" (conjuclention-kernel "verb" (conjugation-kernel 'past-simple)))
(word-kernel "to" (conjuclention-kernel "adverb" '()))
(word-kernel "borrow" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))))
(sentence-kernel
(list
(word-kernel "from" (conjuclention-kernel "preposition" '()))
(word-kernel "my" (conjuclention-kernel "pronoun" (declention-kernel "singular" '() '())))
(word-kernel "books" (conjuclention-kernel "noun" (declention-kernel "plural" '() '())))
(word-kernel "surcease" (conjuclention-kernel "verb" (conjugation-kernel 'base)))
(word-kernel "of" (conjuclention-kernel "preposition" '()))
(word-kernel "sorrow" (conjuclention-kernel "verb" (conjugation-kernel 'base)))
(word-kernel "sorrow" (conjuclention-kernel "verb" (conjugation-kernel 'base)))
(word-kernel "for" (conjuclention-kernel "preposition" '()))
(word-kernel "the" (conjuclention-kernel "adjective" '()))
(word-kernel "lost" (conjuclention-kernel "verb" (conjugation-kernel 'past-simple)))
(word-kernel "lenore" (conjuclention-kernel "unknown" '()))))
(sentence-kernel
(list
(word-kernel "for" (conjuclention-kernel "preposition" '()))
(word-kernel "the" (conjuclention-kernel "adjective" '()))
(word-kernel "rare" (conjuclention-kernel "adjective" '()))
(word-kernel "and" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "radiant" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "maiden" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "whom" (conjuclention-kernel "interrogative pronoun" (declention-kernel '() '() '())))
(word-kernel "the" (conjuclention-kernel "adjective" '()))
(word-kernel "angels" (conjuclention-kernel "noun" (declention-kernel "plural" '() '())))
(word-kernel "name" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "lenore" (conjuclention-kernel "unknown" '()))))
(sentence-kernel
(list
(word-kernel "nameless" (conjuclention-kernel "adjective" '()))
(word-kernel "here" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "for" (conjuclention-kernel "preposition" '()))
(word-kernel "evermore" (conjuclention-kernel "adverb" '()))))
(sentence-kernel
(list
(word-kernel "and" (conjuclention-kernel "conjunction" '()))
(word-kernel "the" (conjuclention-kernel "adjective" '()))
(word-kernel "silken" (conjuclention-kernel "adjective" '()))
(word-kernel "sad" (conjuclention-kernel "adjective" '()))
(word-kernel "uncertain" (conjuclention-kernel "adjective" '()))
(word-kernel "rustling" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "of" (conjuclention-kernel "preposition" '()))
(word-kernel "each" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "purple" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "curtain" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))))
(sentence-kernel
(list
(word-kernel "thrilled" (conjuclention-kernel "unknown" '()))
(word-kernel "me" (conjuclention-kernel "pronoun" (declention-kernel "singular" '() '())))
(word-kernel "filled" (conjuclention-kernel "verb" (conjugation-kernel 'past-simple)))
(word-kernel "me" (conjuclention-kernel "pronoun" (declention-kernel "singular" '() '())))
(word-kernel "with" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "fantastic" (conjuclention-kernel "adjective" '()))
(word-kernel "terrors" (conjuclention-kernel "unknown" '()))
(word-kernel "never" (conjuclention-kernel "adverb" '()))
(word-kernel "felt" (conjuclention-kernel "verb" (conjugation-kernel 'past-simple)))
(word-kernel "before" (conjuclention-kernel "adverb" '()))))
(sentence-kernel
(list
(word-kernel "so" (conjuclention-kernel "adjective" '()))
(word-kernel "that" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "now" (conjuclention-kernel "adverb" '()))
(word-kernel "to" (conjuclention-kernel "adverb" '()))
(word-kernel "still" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "the" (conjuclention-kernel "adjective" '()))
(word-kernel "beating" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "of" (conjuclention-kernel "preposition" '()))
(word-kernel "my" (conjuclention-kernel "pronoun" (declention-kernel "singular" '() '())))
(word-kernel "heart" (conjuclention-kernel "verb" (conjugation-kernel 'base)))
(word-kernel "i" (conjuclention-kernel "unknown" '()))
(word-kernel "stood" (conjuclention-kernel "verb" (conjugation-kernel 'past-simple)))
(word-kernel "repeating" (conjuclention-kernel "verb" (conjugation-kernel 'present-participle)))))
(sentence-kernel
(list
(word-kernel "tis" (conjuclention-kernel "unknown" '()))
(word-kernel "some" (conjuclention-kernel "indefinite pronoun" (declention-kernel '() '() '())))
(word-kernel "visitor" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "entreating" (conjuclention-kernel "verb" (conjugation-kernel 'present-participle)))
(word-kernel "entrance" (conjuclention-kernel "verb" (conjugation-kernel 'base)))
(word-kernel "at" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "my" (conjuclention-kernel "pronoun" (declention-kernel "singular" '() '())))
(word-kernel "chamber" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "door" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))))
(sentence-kernel
(list
(word-kernel "some" (conjuclention-kernel "adverb" '()))
(word-kernel "late" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "visitor" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "entreating" (conjuclention-kernel "verb" (conjugation-kernel 'present-participle)))
(word-kernel "entrance" (conjuclention-kernel "verb" (conjugation-kernel 'base)))
(word-kernel "at" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "my" (conjuclention-kernel "pronoun" (declention-kernel "singular" '() '())))
(word-kernel "chamber" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "door" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))))
(sentence-kernel
(list
(word-kernel "this" (conjuclention-kernel "adverb" '()))
(word-kernel "it" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "is" (conjuclention-kernel "verb" (conjugation-kernel 'present-simple)))
(word-kernel "and" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "nothing" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))
(word-kernel "more" (conjuclention-kernel "noun" (declention-kernel "singular" '() '())))))))
|#
#| STRUCTS FOR PARAGRAPHS, SENTENCES, WORDS, AND conjuclentions |#
#| Conjugation Struct |#
;;; (conjugation form) -> conjugation
;;; form : tense and person identifier ex: 'present-simple
;;; Stores information about a verb's conjugation
(struct conjugation-kernel (form)
#:transparent)
(define conjugation
(lambda (form)
(cond
[(not (or (equal? 'base form)
(equal? 'present-simple form)
(equal? 'past-simple form)
(equal? 'past-participle form)
(equal? 'present-participle form)))
(error "conjugation :" form)]
[else
(conjugation-kernel form)])))
#| Declention Struct |#
;;; (declention number gender case) -> declention?
;;; number : "singular" or "plural"
;;; gender : "masculine", "feminine", or "neuter" (default is "neuter")
;;; case : 'nominative, 'objective, or 'possessive (not implemented)
;;; Stores information about a noun's (or pronoun's) declention
;;; Note:
;;; * Nominative case is for subjects and complements
;;; - "She ate the cake."
;;; - "The person who ate the cake is she."
;;; * Objective is used direct objects, indirect objects, and objects of preposition
;;; - "I bought them."
;;; - "I bought them a cake."
;;; - "I bought a cake for them."
;;; * Possessive case is used for possession
;;; - "That's his cake."
;;; - "That cake is his."
(struct declention-kernel (number gender case)
#:transparent)
(define declention
(lambda (number [gender null] [case null])
(cond
[(not (or (equal? "singular" number)
(equal? "plural" number)
(null? number)))
(error "declention : number" number)]
[(not (or (equal? "masculine" gender)
(equal? "feminine" gender)
(equal? "neuter" gender)
(null? gender)))
(error "declention : gender" gender)]
[(not (or (equal? "possessive" case)
(equal? "objective" case)
(null? case)))
(error "declention : case" case)]
[else
(declention-kernel number gender case)])))
(define sample-dec (declention "singular"))
(test-true "sample declention" (declention-kernel? sample-dec))
#| Conjuclention Struct |#
;;; (conjuclention part-of-speech conjucline) -> conjuclention?
;;; part-of-speech : one of:
;;; 'noun, 'verb, 'adjective, 'adverb, 'pronoun, 'preposition, 'conjunction, 'interjection, or #f
;;; (various types of pronouns also have distinct part-of-speech names, e.g. "relative pronoun")
;;; conjucline : declention? or conjugation? or #f
;;; Stores information about a words part of speech and conjugation or declention
(struct conjuclention-kernel (part-of-speech conjucline)
#:transparent)
(define conjuclention
(lambda (part-of-speech conjucline)
(cond
[(not (string? part-of-speech))
(error "conjuclention: part-of-speech contract violation. Given: " part-of-speech)]
[(not (or (declention-kernel? conjucline)
(conjugation-kernel? conjucline)
null))
(error "conjuclention : conjucline contract violation. Given: " conjucline)]
[else
(conjuclention-kernel part-of-speech conjucline)])))
#| Word Struct |#
;;; (word str conjuclention) -> word?
;;; str : string?
;;; conjuclention : conjuclention?
;;; Creates a word struct
(struct word-kernel (str conjuclention)
#:transparent)
(define word
(lambda (wordstr conjuclention)
(cond
[(not (string? wordstr))
(error "word : expected string" wordstr)]
[(not (or (conjuclention-kernel? conjuclention)
(null? conjuclention)))
(error "word : expected conjuclention" conjuclention)]
[else
(word-kernel wordstr conjuclention)])))
#| Sentence Struct |#
;;; (all-strings? lst) -> boolean
;;; lst : list
;;; checks if every element in list is a string
(define all-strings?
(lambda (lst)
(cond [(empty? lst) #t]
[(string? (first lst))
(all-strings? (cdr lst))]
[else #f])))
(test-true "long string list true" (all-strings? (make-list 20 "cat")))
(test-false "not all elements strings" (all-strings? '("cat" "kitten" 65)))
(test-false "no elements strings" (all-strings? (make-list 20 54)))
;;; (sentence-kernel words) -> sentence?
;;; words : list? of word?
;;; Struct for storing information about each sentence
(struct sentence-kernel (words)
#:transparent)
;;; (sentence sentences) -> void? or error
;;; sentences : list?
;;; calls sentence-kernel if input can be applied to sentence-kernel
;;; else returns error
(define sentence
(lambda (sentences)
(cond
[(not (list? sentences))
(error "sentence not word list")]
[else
(sentence-kernel sentences)])))
#| Paragraph Struct |#
;;; (paragraph-kernel sentences) -> paragraph?
;;; sentences: list? of sentences?
;;; Struct for storing information about each paragraph
(struct paragraph-kernel (sentences)
#:transparent)
;;; (paragraph sentences) -> void? or error
;;; sentences : list? of sentences?
;;; checks if conditions for paragraph-kernel struct are met
;;; if not, returns error.
;;; if so, creates paragraph-kernel struct
(define paragraph
(lambda (sentences)
(cond
[(not (list? sentences))
(error "paragraph not sentences. Given: " sentences)]
[else
(paragraph-kernel sentences)])))
#| IDENTIFYING PARAGRAPHS, SENTENCES, AND WORDS |#
;;; (string->conjuclention str) -> conjuclention?
;;; str : string?
;;; Analyses the word and returns the appropriate conjuclention struct
;;; NOTE: we won't actually analyze the word until part two. For now, just
;;; make it give a default value, such as clasifying all words as singular,
;;; neuter, nominative nouns.
;;; TODO: Make this actually word (during part two)
(define string->conjuclention
(lambda (str)
(declention "singular" "neuter" 'nominative)))
;;; (string->words-list str) -> list? of string?
;;; str : string?
;;; Creates a list of words represented by strings
(define string->words-list
(let* ([rex-alphabetical (rex-any-of (rex-char-range #\a #\z)
(rex-char-range #\A #\Z))]
[rex-contractions (rex-concat (rex-repeat rex-alphabetical)
(rex-char-set "'")
(rex-repeat rex-alphabetical))])
(lambda (str)
(rex-find-matches (rex-any-of rex-contractions
(rex-repeat rex-alphabetical))
str))))
(test-equal? "Empty string"
(string->words-list "")
'())
(test-equal? "Hyphens, Contractions, and Punctuation"
(string->words-list "Hello")
'("Hello"))
(test-equal? "Hyphens, Contractions, and Punctuation"
(string->words-list "Test test-ing nope- -not don't 'try this' Punctuation? Not.Fun")
'("Test" "test" "ing" "nope" "not" "don't" "try" "this" "Punctuation" "Not" "Fun"))
;;; (string->sentences-list str) -> list? of string?
;;; str : string?
;;; Breaks apart a string into a list of sentences contained within the string
;;; Includes the end punctuation with each sentence (including new line characters)
;;; If str does not end in any punctuation, it treats the end of str as a new line character
(define string->sentences-list
(lambda (str)
(let ([endmarks ".?\n"])
(rex-find-matches (rex-concat (rex-char-antiset (string-append endmarks
" \t\n\r"))
(rex-repeat (rex-char-antiset endmarks))
(rex-char-set endmarks))
(string-append str
"\n")))))
(test-equal? "string->sentences-list: Empty string"
(string->sentences-list "")
'())
(test-equal? "string->sentences-list: Single sentence"
(string->sentences-list "Hello, how are you?")
'("Hello, how are you?"))
(test-equal? "string->sentences-list: Multiple sentences"
(string->sentences-list "I'm doing good. How about you? Are you doing good?")
'("I'm doing good." "How about you?" "Are you doing good?"))
(test-equal? "string->sentences-list: New line"
(string->sentences-list "First thing\nSecond thing\nThird thing")
'("First thing\n" "Second thing\n" "Third thing\n"))
(test-equal? "string->sentences-list: Single sentence without punctuation"
(string->sentences-list "I'm going to test this sentence")
'("I'm going to test this sentence\n"))
;;; (string->paragraph-list str) -> list-of-string?
;;; str : s(test-equal? "a singular paragraph"
;;; breaks apart string into its paragraphs
;;; if the strings ends without any new line it adds two new lines
(define string->paragraph-list
(lambda (str)
(let* ([parsep1 "\n\n"]
[parsep2 "\n\t"]
[rex-letter (rex-repeat-0 (rex-char-antiset "\n"))])
(map string-trim (rex-find-matches (rex-concat rex-letter
(rex-any-of (rex-string "\n")
rex-letter)
(rex-repeat (rex-char-antiset parsep2))
(rex-any-of (rex-string parsep1)
(rex-string parsep2)))
(string-append str
parsep1))))))
(test-equal? "a singular paragraph"
(string->paragraph-list "i'm a little paragraph. ok.")
'("i'm a little paragraph. ok."))
(test-equal? "multiple paragraphs"
(string->paragraph-list "i'm a little paragraph\n\n ok.\n\t I like cs.")
'("i'm a little paragraph" "ok." "I like cs."))
(test-equal? "empty string"
(string->paragraph-list "")
'())
(test-equal? "single tab"
(string->paragraph-list "I'm a little tea pot.\t short and stout")
'("I'm a little tea pot.\t short and stout"))
(test-equal? "single new-line"
(string->paragraph-list "I'm a little tea pot.\n short and stout")
'("I'm a little tea pot.\n short and stout"))
;;; (string->sentence str) -> sentence?
;;; str : string?
;;; Converts a string into a sentence struct.
;;; Assumes str contains one sentence
(define string->sentence
(lambda (str)
(sentence (map string->word (string->words-list str)))))
;;; (string->paragraphs str) -> list? of paragraph?
;;; str : string?
;;; Creates a list of paragraphs contained within the string
(define string->paragraphs
(lambda (str)
(paragraph (map string->sentence (string->sentences-list str)))))
;;; (file->paragraphs filename) -> list? of paragraph?
;;; filename : string? that is a valid text file name
;;; Creates a list of paragraphs contained within the given text document
(define file->paragraphs
(lambda (filename)
(string->paragraphs (file->string filename))))
;;; (string->paragraph str) -> paragraph?
;;; str : string?
;;; Converts a string to a paragraph struct.
;;; Assumes str contains only one paragraph.
(define string->paragraph
(lambda (str)
(paragraph (string->paragraph-list str))))
;;; (file->paragraph filename) -> paragraph?
;;; filename : string? that is a valid text file name
;;; Converts the text in a document into a paragraph struct.
;;; Assumes file contains only one paragraph.
(define file->paragraph
(lambda (filename)
(string->paragraph (file->string filename))))
#| WORD ANALYSIS |#
;;; (csv->column-list filename column-num) -> list? of string?
;;; filename : string? that is a valid file name
;;; column-num : integer?
;;; Returns a list of the values in the given column
;;; column-num = 0 gives the first column
(define csv->column-list
(lambda (filename column-num)
(map (lambda (line)
(string-trim (list-ref (string-split line #px"[\t,]" #:trim? #f) column-num)))
(file->lines filename))))
;;; (file->verb-dictioary filename)
;;; filename : string? that is a valid file name
;;; filename should be formatted as follows
;;; base1,present_simple1,past_simple1,past_participle1,present_participle1
;;; base2,present_simple2,past_simple2,past_participle2,present_participle2
;;; ...
;;; Dictionay hash will be formatted as follows
;;; '#hash(
;;; (base . (...list_of_base_verbs...)) ; (base form is infinitive and 1st/2nd present smple)
;;; (present-simple . (...list_of_present_simple_verbs...)) ; (only 3rd person)
;;; (past-simple . (...list_of_past_simple_verbs...))
;;; (past-participle . (...list_of_past_participle_verbs...))
;;; (present-participle . (...list_of_present_participle_verbs...)))
(define file->verb-dictionary
(lambda (filename)
(hash 'base (csv->column-list filename 0)
'present-simple (csv->column-list filename 1)
'past-simple (csv->column-list filename 2)
'past-participle (csv->column-list filename 3)
'present-participle (csv->column-list filename 4))))
(define verb-dictionary (file->verb-dictionary "verbs-dictionary.csv"))
;;; (file->pronouns-dictionary personal-pronouns other-pronouns) -> hash?
;;; personal-pronouns : string? that is a valid file name
;;; other-pronouns : string? that is a valid file name
;;; personal-pronouns should be formatted as follows
;;; i,we,thou,you,ye,he,she,it,they
;;; me,us,thee,you,y'all,him,her,it,them
;;; my,our,thy,your,your,his,her,its,their
;;; mine,ours,thine,yours,yours,his,hers,,theirs
;;; myself,ourselves,thyself,yourself,yourselves,himself,herself,itself,themselves
;;;
;;; other-pronouns should be formatted as follows
;;; indefinite1,indefinite2,...
;;; demonstrative1,demonstrative2,...
;;; interrogative1,interrogative2,...
;;; relative1,relative2,...
;;; Dictioary hash will be formatted as follows
;;; '#hash(
;;; (1S . (nominative objective possessive-adjective possessive reflexive)) ; (1st singular)
;;; (1P . (nominative objective possessive-adjective possessive reflexive)) ; (1st plural)
;;; (2AS . (nominative objective possessive-adjective possessive reflexive)) ; (2nd archaic singular)
;;; (2S . (nominative objective possessive-adjective possessive reflexive)) ; (2nd singular)
;;; (2P . (nominative objective possessive-adjective possessive reflexive)) ; (2nd plural)
;;; (3M . (nominative objective possessive-adjective possessive reflexive)) ; (3rd masculine singular)
;;; (3F . (nominative objective possessive-adjective possessive reflexive)) ; (3rd feminine singular)
;;; (3N . (nominative objective possessive-adjective possessive reflexive)) ; (3rd neuter singular)
;;; (3P . (nominative objective possessive-adjective possessive reflexive)) ; (3rd plural)
;;; (indefinite . (...list_of_indefinite_pronouns...))
;;; (demonstrative . (...list_of_demonstrative_pronouns...))
;;; (interrogative . (...list_of_interrogative_pronouns...))
;;; (relative . (...list_of_relative_pronouns...)))
(define file->pronouns-dictionary
(lambda (personal-pronouns other-pronouns)
(hash '1S (csv->column-list personal-pronouns 0)
'1P (csv->column-list personal-pronouns 1)
'2AS (csv->column-list personal-pronouns 2)
'2S (csv->column-list personal-pronouns 3)
'2P (csv->column-list personal-pronouns 4)
'3M (csv->column-list personal-pronouns 5)
'3F (csv->column-list personal-pronouns 6)
'3N (csv->column-list personal-pronouns 7)
'3P (csv->column-list personal-pronouns 8)
'indefinite (csv->column-list other-pronouns 0)
'demonstrative (csv->column-list other-pronouns 1)
'interrogative (csv->column-list other-pronouns 2)
'relative (csv->column-list other-pronouns 3))))
(define pronoun-dictionary (file->pronouns-dictionary "personal-pronouns.csv" "other-pronouns.csv"))
;;; (file->noun-dictionary filename) -> hash?
;;; filename : string? that is a valid file name
;;; filename should be formatted as follows
;;; word1_singular,word1_plural
;;; word2_singular,word2_plural
;;; ...
;;; (e.g. https://raw.githubusercontent.com/djstrong/nouns-with-plurals/master/noun.csv)
;;; Dictionary hash will be formatted as follows
;;; '#hash(
;;; (singular . (...list_of_singular_nouns...)
;;; (plural . (...list_of_plural_nouns...))))
(define file->noun-dictionary
(lambda (filename)
(hash "singular" (csv->column-list filename 0)
"plural" (csv->column-list filename 1))))
(define noun-dictionary (file->noun-dictionary "noun-dictionary.csv"))
;;; (file->other-dictionary adjectives adverbs prepositions cojuctions interjections)
;;; all parameters : string? that is a valid file name
;;; All files should be formatted as a new-line separated list of words
;;; The articles (the, an, a) have been added to the adjective list file.
;;; Dictionary hash will be formatted as follows
;;; '#hash(
;;; (adjective . (...list_of_adjectives...))
;;; (adverb . (...list_of_adverbs...))
;;; (conjunction . (...list_of_conjunctions...))
;;; (preposition . (...list_of_prepositions...))
;;; (interjection . (...list_of_interjectios...)))
(define file->other-dictionary
(lambda (adjective-filename adverb-filename preposition-filename conjunction-filename interjection-filename)
(hash 'adjective (file->lines adjective-filename)
'adverb (file->lines adverb-filename)
'conjunction (file->lines conjunction-filename)
'interjection (file->lines interjection-filename)
'preposition (file->lines preposition-filename))))
(define other-dictionary
(file->other-dictionary "adjectives.txt"
"adverbs.txt"
"prepositions.txt"
"conjunctions.txt"
"interjections.txt"))
;;; (string->noun str dictionary) -> word? with noun properties
;;; str : string? that is one word
;;; dictionary : hash? formatted as noun dictionary
;;; If the given word is in the noun dictionary, it returns a word
;;; struct with noun properties. Othwerise, it returns #f
(define string->noun
(lambda (str)
(cond [(number? (index-of (hash-ref noun-dictionary "plural") str))
(word str (conjuclention "noun" (declention "plural")))]
[(number? (index-of (hash-ref noun-dictionary "singular") str))
(word str (conjuclention "noun" (declention "singular")))]
[else #f])))
;;; (string->verb str dictionary)
;;; str : string? that is one word
;;; dictionary : hash? formatted as verb dictionary
;;; If the given word is in the verb dictionary, it returns a word
;;; struct with noun properties. Othwerise, it returns #f
(define string->verb
(lambda (str)
(cond [(index-of (hash-ref verb-dictionary 'base) str)
(word str (conjuclention "verb" (conjugation 'base)))]
[(index-of (hash-ref verb-dictionary 'present-simple) str)
(word str (conjuclention "verb" (conjugation 'present-simple)))]
[(index-of (hash-ref verb-dictionary 'past-simple) str)
(word str (conjuclention "verb" (conjugation 'past-simple)))]
[(index-of (hash-ref verb-dictionary 'past-participle) str )
(word str (conjuclention "verb" (conjugation 'past-participle)))]
[(index-of (hash-ref verb-dictionary 'present-participle) str)
(word str (conjuclention "verb" (conjugation 'present-participle)))]
[else
#f])))
;;; (string->pronoun str dictionary)
;;; str : string containing 1 word
;;; dictionary : the dictionary of pronouns
;;; takes a word and determines if it is a pronoun.
(define string->pronoun
(lambda (str)
(cond [(index-of (hash-ref pronoun-dictionary '1S) str)
(word str (conjuclention "pronoun" (declention "singular" null null)))]
[(index-of (hash-ref pronoun-dictionary '1P) str)
(word str (conjuclention "pronoun" (declention "plural" null null)))]
[(index-of (hash-ref pronoun-dictionary '2AS) str)
(word str (conjuclention "pronoun" (declention "singular" null null)))]
[(index-of (hash-ref pronoun-dictionary '2S) str)
(word str (conjuclention "pronoun" (declention "singular" null null)))]
[(index-of (hash-ref pronoun-dictionary '2P) str)
(word str (conjuclention "pronoun" (declention "plural" null null)))]
[(index-of (hash-ref pronoun-dictionary '3M) str)
(word str (conjuclention "pronoun" (declention "singular" "masculine" null)))]
[(index-of (hash-ref pronoun-dictionary '3F) str)
(word str (conjuclention "pronoun" (declention "singular" "feminine" null)))]
[(index-of (hash-ref pronoun-dictionary '3N) str)
(word str (conjuclention "pronoun" (declention "singular" "neuter" null)))]
[(index-of (hash-ref pronoun-dictionary '3P) str)
(word str (conjuclention "pronoun" (declention "plural" null null)))]
[(index-of (hash-ref pronoun-dictionary 'indefinite) str)
(word str (conjuclention "indefinite pronoun" (declention null null null)))]
[(index-of (hash-ref pronoun-dictionary 'demonstrative) str)
(word str (conjuclention "demonstrative pronoun" (declention null null null)))]
[(index-of (hash-ref pronoun-dictionary 'interrogative) str)
(word str (conjuclention "interrogative pronoun" (declention null null null)))]
[(index-of (hash-ref pronoun-dictionary 'relative) str)
(word str (conjuclention "relative pronoun" (declention null null null)))]
[else
#f])))
;;; (string->word str) -> word?
;;; str : string?
;;; Converts a string to a word struct.
;;; Assumes str contains one word
(define string->word
(lambda (str)
(let ([str (string-downcase str)]
[noun? (string->noun str)]
[verb? (string->verb str)]
[pronoun? (string->pronoun str)])
(cond
[noun?
noun?]
[verb?
verb?]
[pronoun?
pronoun?]
[(index-of (hash-ref other-dictionary
'adjective)
str)
(word str (conjuclention "adjective" null))]
[(index-of (hash-ref other-dictionary
'adverb)
str)
(word str (conjuclention "adverb" null))]
[(index-of (hash-ref other-dictionary
'preposition)
str)
(word str (conjuclention "preposition" null))]
[(index-of (hash-ref other-dictionary
'conjunction)
str)
(word str (conjuclention "conjunction" null))]
[else
(word str (conjuclention "unknown" null))]))))