1
00:00:01,680 --> 00:00:06,689
And this video, you learn how to perform grammar checking with Python.

2
00:00:07,680 --> 00:00:15,810
And we're going to do this using an API called Language Tool API, so we're going to be sending requests

3
00:00:15,810 --> 00:00:19,670
to Vets Rest API in the request.

4
00:00:19,680 --> 00:00:26,340
We will send the text we want to check for grammar and we will return the corrected text back.

5
00:00:26,970 --> 00:00:32,340
This will work through a post through requests, not a gets requests, as we have done so far.

6
00:00:32,940 --> 00:00:34,310
So we've get requests.

7
00:00:34,320 --> 00:00:43,440
You just get some ready made dots on there, but with post requests, you send some data.

8
00:00:43,620 --> 00:00:48,460
In this case, we're going to send some text there and the server will process that.

9
00:00:49,140 --> 00:00:57,480
So this time in this post request scenario, the server has to process our data and do calculations

10
00:00:57,480 --> 00:01:02,010
and then return those data to our clients to our program.

11
00:01:03,030 --> 00:01:13,200
The tool will be using, though again, requests so important quests and then create a response object

12
00:01:13,230 --> 00:01:16,530
requests that post this time not gets.

13
00:01:16,650 --> 00:01:21,930
Previously, we used gets no use post and the URL is the first argument.

14
00:01:21,930 --> 00:01:27,300
So you URL is this will be the URL of this API.

15
00:01:27,600 --> 00:01:37,890
So if you go to a language tool dot org slash HTP Dash API and then you go to default in here, so you're

16
00:01:37,890 --> 00:01:40,080
going to see these.

17
00:01:41,930 --> 00:01:43,970
If you press here, check a text.

18
00:01:53,050 --> 00:01:56,890
You're going to see the parameters I'll return in just a while.

19
00:01:57,820 --> 00:02:04,300
What these parameters mean, but the routes you earl is.

20
00:02:07,350 --> 00:02:08,520
HTP as.

21
00:02:10,340 --> 00:02:15,110
Colin Slash slash API dot language tool.

22
00:02:15,410 --> 00:02:16,580
Dot org.

23
00:02:21,430 --> 00:02:26,530
That's a v two slash v to slash check.

24
00:02:27,640 --> 00:02:33,820
So that's where L is going to go in here, but then we have to pass parameters here.

25
00:02:34,210 --> 00:02:38,740
Unlike in the gets requests here, you have to parse dots all you want to process.

26
00:02:39,100 --> 00:02:41,530
So see here what data we can pass.

27
00:02:41,800 --> 00:02:44,620
We can pass text, for example.

28
00:02:45,400 --> 00:02:48,820
This is the text that we need to send for grammar checking.

29
00:02:49,900 --> 00:02:54,280
All you can pass it as Jason, not as a string.

30
00:02:54,280 --> 00:02:59,500
So in that case, you would pass a delta arguments and then you have language, which is a required

31
00:02:59,500 --> 00:03:02,830
argument and all of the parameters as well.

32
00:03:03,080 --> 00:03:10,000
What language is the only required arguments and also texts if you want to check some actual text?

33
00:03:10,930 --> 00:03:13,280
So how do we give these parameters?

34
00:03:13,300 --> 00:03:16,840
Well, we give them through a dictionary.

35
00:03:17,650 --> 00:03:24,760
So first we creates a dictionary, let's say delta, or use just any valuable you like that would be

36
00:03:25,450 --> 00:03:26,590
equal to this dictionary.

37
00:03:26,860 --> 00:03:28,510
And then here you pass keys.

38
00:03:28,840 --> 00:03:34,150
So text, for example, of this key as to reflects one of the parameters in here.

39
00:03:34,360 --> 00:03:38,410
So text and then you parse the text you want to check.

40
00:03:39,850 --> 00:03:43,600
Let's write something grammatically wrong by purpose.

41
00:03:44,470 --> 00:03:50,540
So let's say this is a nice day.

42
00:03:51,040 --> 00:03:57,250
So I wanted to say this is a nice date, but I did want typo in here and one typo in here.

43
00:03:57,860 --> 00:03:58,340
Mm.

44
00:03:58,360 --> 00:04:03,100
So that's the text key and then a comma, and then you pass more parameters.

45
00:04:03,700 --> 00:04:08,290
Language is a required arguments and it will be equal to.

46
00:04:09,310 --> 00:04:15,430
Well, you can press and but you can also say Alter so that you can get the checking, even if this

47
00:04:15,430 --> 00:04:19,209
is another language for any language that this API supports.

48
00:04:19,779 --> 00:04:25,240
And then once you have defined your dictionary there, then in here you provide data.

49
00:04:25,960 --> 00:04:31,630
That's how it's a parameter of the post requests and that is equal to this variable delta.

50
00:04:31,960 --> 00:04:40,210
So data is equal to delta and then print responds the text and run.

51
00:04:42,530 --> 00:04:43,940
And that's the output.

52
00:04:45,320 --> 00:04:49,550
Let's check the type of this output using a type function.

53
00:04:50,900 --> 00:04:58,610
So wrap that expression inside the type and run and you'll see this is a string.

54
00:05:00,320 --> 00:05:04,400
So first of all, we want to convert this into a dictionary.

55
00:05:05,360 --> 00:05:07,460
Therefore, I'm going to import Jason.

56
00:05:08,590 --> 00:05:19,760
And then what I'll do here is, I'll say results is equal to response dot text, but that will go inside

57
00:05:19,760 --> 00:05:20,420
Jason.

58
00:05:20,420 --> 00:05:21,350
That loads.

59
00:05:23,000 --> 00:05:30,800
So JSON that loads converts a string into a dictionary so that we are able to parse that dictionary

60
00:05:30,800 --> 00:05:31,190
we can.

61
00:05:33,100 --> 00:05:40,090
Extracted items of the dictionary, and we cannot do that if the format is a string because a string

62
00:05:40,090 --> 00:05:48,010
is made of characters and the dictionary is recognized by Python as a more compound, other type which

63
00:05:48,010 --> 00:05:52,180
has items and which are made of keys and values.

64
00:05:52,390 --> 00:05:56,680
So Ron, this oh, let me print out results.

65
00:06:00,630 --> 00:06:09,900
So we've got the same outputs as before, but now this will be a dictionary if I check the type of that.

66
00:06:12,850 --> 00:06:13,750
So it's addiction it.

67
00:06:16,380 --> 00:06:17,700
And I'd like to stop here.

68
00:06:18,090 --> 00:06:20,610
So that is a final output for this video.

69
00:06:20,700 --> 00:06:25,800
No, you know how to parse dictionaries, so how to extract Delta from a dictionary?

70
00:06:26,010 --> 00:06:28,050
Using the dictionary keys.

71
00:06:28,440 --> 00:06:34,530
So depending on the application that you want to make, which contains grammar correction functionality,

72
00:06:34,830 --> 00:06:42,270
you might want to extract different values from the dictionary, so you may extract the suggestion of

73
00:06:42,270 --> 00:06:43,530
the correct word.

74
00:06:43,800 --> 00:06:50,040
And in this dictionary, you also have the information where that word is located in the text.

75
00:06:50,460 --> 00:06:55,110
So you can extract the index of the word that is wrong.

76
00:06:55,410 --> 00:07:01,080
Maybe you create a web and then you show this information as popups on the app.

77
00:07:01,410 --> 00:07:06,030
So I'd like to close this video here and to leave you with this dictionary.

78
00:07:06,180 --> 00:07:09,330
So I'll thank you for following this and I'll see you later.

