-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWords.cs
87 lines (77 loc) · 2.8 KB
/
Words.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace LearningApp
{
public class Phonetic
{
public string? Text { get; set; }
public string? Audio { get; set; }
}
public class Definition
{
[JsonProperty("definition")]
public string? DefinitionText { get; set; }
public string? Example { get; set; }
}
public class Meaning
{
public string? PartOfSpeech { get; set; }
public List<Definition>? Definitions { get; set; }
}
public class Words
{
public string? Word { get; set; }
public List<Phonetic>? Phonetics { get; set; }
public List<Meaning>? Meanings { get; set; }
public Words(string? word, List<Phonetic>? phonetics, List<Meaning>? meanings)
{
Word = word;
Phonetics = phonetics;
Meanings = meanings;
}
public void ExtractPartsOfSpeech()
{
string nounDefinition = "Not available";
string verbDefinition = "Not available";
string adjectiveDefinition = "Not available";
string adverbDefinition = "Not available";
if (Meanings != null)
{
foreach (var meaning in Meanings)
{
if (meaning.Definitions != null && meaning.Definitions.Count > 0)
{
var firstDefinition = meaning.Definitions[0].DefinitionText;
switch (meaning.PartOfSpeech)
{
case "noun" when nounDefinition == "Not available":
nounDefinition = firstDefinition;
break;
case "verb" when verbDefinition == "Not available":
verbDefinition = firstDefinition;
break;
case "adjective" when adjectiveDefinition == "Not available":
adjectiveDefinition = firstDefinition;
break;
case "adverb" when adverbDefinition == "Not available":
adverbDefinition = firstDefinition;
break;
}
}
}
}
Console.WriteLine($"Noun: {nounDefinition}");
Console.WriteLine($"Verb: {verbDefinition}");
Console.WriteLine($"Adjective: {adjectiveDefinition}");
Console.WriteLine($"Adverb: {adverbDefinition}");
}
}
}