Skip to content

Commit

Permalink
senses done.
Browse files Browse the repository at this point in the history
  • Loading branch information
lavedon committed Apr 22, 2021
1 parent 18ff3da commit 7bb46f2
Show file tree
Hide file tree
Showing 20 changed files with 77 additions and 50 deletions.
64 changes: 21 additions & 43 deletions API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class API

public static JsonDocument JSONResponse { get; set; }


static void resetHeaders(HttpClient client)
{
try {
Expand Down Expand Up @@ -85,7 +86,7 @@ public static void APICalls(CurrentQuery query)
client.Timeout = TimeSpan.FromMinutes(10);

var response = client.GetStreamAsync(requestURL).Result;
Console.WriteLine(response);
Trace.WriteLine(response);
}
catch (AggregateException ae)
{
Expand Down Expand Up @@ -295,7 +296,7 @@ public static void APICalls(CurrentQuery query)
getSenses.RunSynchronously();


Trace.WriteLine("Ran senses using start.");
Trace.WriteLine("Ran senses using start.");

JsonElement senseData = JSONResponse.RootElement.GetProperty("data");

Expand All @@ -309,55 +310,32 @@ public static void APICalls(CurrentQuery query)
currentSense.Start = item.GetProperty("daterange").GetProperty("start").GetInt16();
currentSense.IsObsolete = item.GetProperty("daterange")
.GetProperty("obsolete").GetBoolean();
currentSense.IsMainUsage = item.GetProperty("main_current_sense").GetBoolean();
currentSense.OedReference = item.GetPropertyExt("oed_reference")?.ToString();
// currentSense.Usage = item.GetProperty("")
Console.WriteLine("Word first used: {0}", currentSense.Start);
var etyArray = item.GetProperty("etymology").GetProperty("etymons");
currentSense.PrimarySenseID = item.GetProperty("primary_sense_id").ToString();
currentSense.EtymologySummary = item.GetProperty("etymology").
GetProperty("etymology_summary").ToString();
Console.WriteLine();
Console.WriteLine("Sense Etymology:");
foreach (var i in etyArray.EnumerateArray())
Console.WriteLine(currentSense.Definition);
Console.WriteLine("Sense first used: {0}", currentSense.Start);
if (currentSense.IsObsolete)
{

currentSense.Etymons.TryAdd(i.GetProperty("word").ToString(),
i.GetProperty("part_of_speech").ToString());
Console.WriteLine();
Console.WriteLine(i.GetProperty("word"));
Console.WriteLine("Part of Speech:");
if (i.GetProperty("part_of_speech").ToString() == "VB")
{
Console.WriteLine("Verb");
}
else
{
Console.WriteLine(i.GetProperty("part_of_speech"));
}
Console.WriteLine("This usage is obsolete.");
}


// Get Inflections
foreach (JsonElement i in item.GetProperty("inflections").EnumerateArray())
else
{
string region = i.GetProperty("region").ToString();
Console.WriteLine();
Console.WriteLine("Region: {0}", region);
Console.WriteLine("Inflections:");

var forms = new System.Text.StringBuilder();
foreach (JsonElement inflections in i.GetProperty("inflections").EnumerateArray())
{
var form = inflections.GetProperty("form").ToString();
Console.Write(form + " ");
forms.Append(form);
forms.Append(" ");
}
currentSense.Inflections.TryAdd(region, forms.ToString());
Console.WriteLine("This sense is not obsolete.");
}

if (currentSense.IsMainUsage)
{
Console.WriteLine("This sense is the main sense for the word.");
}
else
{
Console.WriteLine("Not the main sense for the word.");
}
Console.WriteLine(currentSense.OedReference);

query.Senses.Add(currentSense);
Console.WriteLine();

Console.WriteLine("----Enter for more - X to exit----");
string input = Console.ReadLine().Trim().ToLower();
if (input == "x")
Expand Down
1 change: 1 addition & 0 deletions CurrentQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class CurrentQuery : IDisposable
public CurrentQuery() {
this.HasLookedUpWord = false;
this.Quotes = new List<Quote>();
this.Senses = new List<Sense>();
}
public string Source { get; set; }

Expand Down
16 changes: 16 additions & 0 deletions JsonElementExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Text.Json;
public static class JsonElementExtension
{
public static JsonElement? GetPropertyExt(this JsonElement jsonElement, string propertyName)
{
if (jsonElement.TryGetProperty(propertyName, out JsonElement returnElement))
{
return returnElement;
}
else
{
return null;
}
}

}
8 changes: 2 additions & 6 deletions Sense.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ public class Sense
public string Definition { get; set; }
public int Start { get; set; }
public bool IsObsolete { get; set; }
public bool IsMainUsage { get; set; }
public string PrimarySenseID { get; set; }
public string EtymologySummary { get; set; }

public Dictionary<string, string> Etymons { get; set; }
public Dictionary<string, string> Inflections { get; set; }
public string OedReference { get; set; }

public Sense() {
this.IsObsolete = false;
this.Etymons = new Dictionary<string, string>();
this.Inflections = new Dictionary<string, string>();
}

}
Expand Down
Binary file modified bin/Debug/net5.0/OxfordV2.dll
Binary file not shown.
Binary file modified bin/Debug/net5.0/OxfordV2.pdb
Binary file not shown.
Binary file modified bin/Debug/net5.0/ref/OxfordV2.dll
Binary file not shown.
Empty file.
Empty file.
36 changes: 36 additions & 0 deletions logs/Log_OxfordApplication_20210421-1951.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Leaving Main method.
Starting Main Menu
In MainMenu()
Automatically looking up user entered word:
coputer
Found that QueryMode is set to words.
Looking up the word:
coputer
Now to call the words endpoint.
Getting request keys
resetHeaders called.
App Id is:
4ebc819b
Key is:
b6b1ca0e4e766b222d56c20f43c2396f
Here are the request Headers...
Accept: application/json
app_id: 4ebc819b
app_key: b6b1ca0e4e766b222d56c20f43c2396f

Calling the API
Called callWordsAPI
Making the request
Got responses.
Set JSONResponse to the response.
Left getWords task with the JSONResponse.
Parsing JSON
We now have the data as a string.
[]
Extracted definition.
Set definition to query object.
Now to get and set the word ID.
The wordID was grabbed as:
The user's input was read as:
x
Exit selected.
Empty file.
Empty file.
Empty file.
Empty file.
Binary file modified obj/Debug/net5.0/OxfordV2.assets.cache
Binary file not shown.
2 changes: 1 addition & 1 deletion obj/Debug/net5.0/OxfordV2.csproj.CoreCompileInputs.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dcef1070ebd692bec2967bc0e06c8795a1f10ff9
8cd677e6c6a9f31363765b5823023fe7a43d0a9b
Binary file modified obj/Debug/net5.0/OxfordV2.csprojAssemblyReference.cache
Binary file not shown.
Binary file modified obj/Debug/net5.0/OxfordV2.dll
Binary file not shown.
Binary file modified obj/Debug/net5.0/OxfordV2.pdb
Binary file not shown.
Binary file modified obj/Debug/net5.0/ref/OxfordV2.dll
Binary file not shown.

0 comments on commit 7bb46f2

Please sign in to comment.