Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
lavedon committed Jun 6, 2021
1 parent 82d31ee commit 058cf5e
Show file tree
Hide file tree
Showing 556 changed files with 4,253 additions and 144 deletions.
29 changes: 19 additions & 10 deletions API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ static void resetHeaders(HttpClient client)
Trace.WriteLine(client.DefaultRequestHeaders);

}

// @TODO refactor this whole insane mess.
public static void APICalls(CurrentQuery query)
{
// Have CurrentQuery - QueryMode - tell
Expand All @@ -205,6 +205,14 @@ public static void APICalls(CurrentQuery query)
Trace.WriteLine("Called callWordsAPI");
// I am removing the limit of 1 definition -- going to return all at once
// Uri requestURL = new Uri(baseURL + "words/?lemma=" + query.UserEnteredWord + "&limit=1");
string queryURL;
if ((! query.IncludeObsolete) || (! query.OptionsMenuIncludeObsolete)) {
queryURL = @"words/?lemma=" + query.UserEnteredWord + @"?obsolete=false";
}
else {
queryURL = @"words/?lemma=" + query.UserEnteredWord;
}

Uri requestURL = new Uri(baseURL + "words/?lemma=" + query.UserEnteredWord);
Trace.WriteLine("Making the request");

Expand All @@ -216,19 +224,11 @@ public static void APICalls(CurrentQuery query)



Action<object> callWordsByIdAPI = (Object obj) =>
{
Trace.WriteLine("Called callWordsByIdAPI");
Uri requestURL = new Uri(baseURL + @"word/orchestra\_nn01?include\_senses=false&include\_quotations=false");
Trace.WriteLine("Making the request");
Trace.WriteLine(client.GetStringAsync(requestURL));
};

Action<object> callSensesAPI = (Object obj) =>
{
Trace.WriteLine("Called callSensesAPI");
string queryURL;
if (! query.IncludeObsolete) {
if ((! query.IncludeObsolete) || (! query.OptionsMenuIncludeObsolete)) {
queryURL = @"word/" + query.Definitions[0].WordID + @"/senses/?obsolete=false";
}
else {
Expand Down Expand Up @@ -359,6 +359,15 @@ public static void APICalls(CurrentQuery query)
Definition tempDefinition = new Definition();
tempDefinition.WordDefinition = data[i].GetProperty("definition").ToString();
tempDefinition.WordID = data[i].GetProperty("id").ToString();
tempDefinition.RecordedFirstUseSource = data[i].GetProperty("first_use").ToString();
tempDefinition.RecordedFirstUseYear = int.Parse(data[i].GetProperty("daterange").GetProperty("start").ToString());
var parts = data[i].GetProperty("parts_of_speech").EnumerateArray();
while (parts.MoveNext())
{
var part = parts.Current;
tempDefinition.PartsOfSpeech.Add(part.GetString());
}

if (data[i].GetProperty("main_entry").ToString().ToLower() == "true")
{
tempDefinition.IsWordMainDefinition = true;
Expand Down
94 changes: 75 additions & 19 deletions ConsoleUI.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Collections.Generic;

namespace OxfordV2
{
Expand All @@ -22,10 +24,79 @@ private static string processInput(CurrentQuery query, string userInput)
if (userInput.Contains("-o")) {
query.IncludeObsolete = false;
}
var inputTokens = userInput.Split(" ");
string[] inputTokens = userInput.Split(" ");

List<string> result = inputTokens.Where(t => t.All(char.IsDigit)).ToList();
// @TODO improve this so queries like "robot - 1900" work
// @TODO improve so queries with no space between dates works.
if (result.Count() == 1) {
query.StartYear = int.Parse(result[0]);
query.OpenStart = true;

}
else if (result.Count() == 2) {
query.StartYear = int.Parse(result[0]);
query.EndYear = int.Parse(result[1]);
query.OpenStart = false;
}

return inputTokens[0];
}

static void showDefinitions(CurrentQuery query)
{

for (int i = 0; i < query.Definitions.Count; i++)
{
int dNum = i + 1;
Console.WriteLine("Definition #{0}:", dNum);
Console.WriteLine();
Console.WriteLine(query.Definitions[i].WordDefinition.ToString());
Console.WriteLine();

if (query.OptionsMenuVerboseMode) {
string outputPartsOfSpeech = "";
string mainDefinition = "";
string firstUseSource = "";
string firstUseYear = "";
string isObsolete = "";

if (query.Definitions[i].PartsOfSpeech.Count != 0)
{

query.Definitions[i].FormatPartsOfSpeech();
foreach (var p in query.Definitions[i].FormattedPartsOfSpeech)
{
outputPartsOfSpeech += p.ToString() + ". ";
}
}
if (query.Definitions[i].IsWordMainDefinition)
{
mainDefinition = "Listed as a main definition.";
} else
{
mainDefinition = "NOT listed as a main definition.";
}

if (query.Definitions[i].IsWordObsolete)
{
isObsolete = "This usage is now obsolete.";
} else {
isObsolete = "";
}

firstUseSource = query.Definitions[i].RecordedFirstUseSource;
firstUseYear = query.Definitions[i].RecordedFirstUseYear.ToString();
Console.WriteLine(outputPartsOfSpeech + isObsolete + " " + mainDefinition +
" The original source of this word is the {0}. This word was first recored in {1}",
firstUseSource, firstUseYear);
Console.WriteLine();
}


}
}

static void MainMenu(CurrentQuery query)
{
Trace.WriteLine("In MainMenu()");
Expand All @@ -38,28 +109,13 @@ static void MainMenu(CurrentQuery query)
Trace.WriteLine(query.UserEnteredWord);
query.QueryMode = Modes.Word;
API.APICalls(query);
for (int i = 0; i < query.Definitions.Count; i++)
{
int dNum = i + 1;
Console.WriteLine("Definition #{0}", dNum);
Console.WriteLine("");
Console.WriteLine(query.Definitions[i].WordDefinition.ToString());
Console.WriteLine("");
if (query.Definitions[i].IsWordMainDefinition)
{
Console.WriteLine("This definition is listed as a main definition.");
} else
{
Console.WriteLine("This definition is NOT listed as a main definition.");
}
Console.WriteLine("");

} }
}
catch (Exception ex)
{
Trace.WriteLine("Exception on automatic word look up");
Trace.WriteLine(ex);
}
showDefinitions(query);
}
Console.WriteLine();
Console.WriteLine("-------------------------");
Expand Down Expand Up @@ -91,7 +147,7 @@ static void MainMenu(CurrentQuery query)
}
else
{
Console.WriteLine(query.Definitions[0].WordDefinition);
showDefinitions(query);
}
break;

Expand Down
4 changes: 4 additions & 0 deletions CurrentQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class CurrentQuery : IDisposable
public Modes QueryMode { get; set; }

public bool HasLookedUpWord { get; set; }
public bool OptionsMenuIncludeObsolete { get; set; }
public bool OptionsMenuVerboseMode { get; set;}
public bool IncludeObsolete { get; set; }
public bool DateRangeSet { get; set; }

Expand All @@ -45,6 +47,8 @@ public CurrentQuery() {
this.HasLookedUpWord = false;
this.DateRangeSet = false;
this.IncludeObsolete = true;
this.OptionsMenuIncludeObsolete = true;
this.OptionsMenuVerboseMode = true;
this.Definitions = new List<Definition>();
this.Quotes = new List<Quote>();
this.Senses = new List<Sense>();
Expand Down
155 changes: 155 additions & 0 deletions Definition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,160 @@ public class Definition
public string WordDefinition { get; set; }
public string WordID { get; set; }
public bool IsWordMainDefinition { get; set; }
public bool IsWordObsolete { get; set; }
public string RecordedFirstUseSource { get; set; }
public int RecordedFirstUseYear { get; set; }
public List<string> PartsOfSpeech { get; set;}
public List<string> FormattedPartsOfSpeech { get; set; }

public Definition() {
this.PartsOfSpeech = new List<string>();
this.FormattedPartsOfSpeech = new List<string>();
}

public void FormatPartsOfSpeech() {
foreach (string p in this.PartsOfSpeech)
switch (p) {
case("VBN"):
FormattedPartsOfSpeech.Add("Verb, past participle");
break;

case("NN"):
FormattedPartsOfSpeech.Add("Noun");
break;

case("NNS"):
FormattedPartsOfSpeech.Add("Plural noun");
break;

case("PRP"):
FormattedPartsOfSpeech.Add("Personal pronoun");
break;

case("PRP$"):
FormattedPartsOfSpeech.Add("Possessive pronoun");
break;

case("WP"):
FormattedPartsOfSpeech.Add("wh-pronoun");
break;

case("WP$"):
FormattedPartsOfSpeech.Add("Possessive wh-pronoun");
break;

case("JJ"):
FormattedPartsOfSpeech.Add("Adjective");
break;

case("JJR"):
FormattedPartsOfSpeech.Add("Comparative adjective");
break;

case("JJS"):
FormattedPartsOfSpeech.Add("Superlative adjective");
break;

case("MD"):
FormattedPartsOfSpeech.Add("Modal");
break;

case("VB"):
FormattedPartsOfSpeech.Add("Verb");
break;

case("VBD"):
FormattedPartsOfSpeech.Add("Verb, past tense");
break;

case("VBG"):
FormattedPartsOfSpeech.Add("Verb, present participle");
break;

case("VBZ"):
FormattedPartsOfSpeech.Add("Verb, 3rd person singular present");
break;

case("RB"):
FormattedPartsOfSpeech.Add("Comparative adverb");
break;

case("RBR"):
FormattedPartsOfSpeech.Add("Comparative adverb");
break;

case("RBS"):
FormattedPartsOfSpeech.Add("Superlative adverb");
break;

case("WRB"):
FormattedPartsOfSpeech.Add("Wh-adverb");
break;

case("IN"):
FormattedPartsOfSpeech.Add("Preposition");
break;

case("CC"):
FormattedPartsOfSpeech.Add("Coordinating conjunction");
break;

case("UH"):
FormattedPartsOfSpeech.Add("Interjection");
break;

case("NNP"):
FormattedPartsOfSpeech.Add("Proper noun");
break;

case("CD"):
FormattedPartsOfSpeech.Add("Cardinal number");
break;

case("DT"):
FormattedPartsOfSpeech.Add("Determiner");
break;

case("EX"):
FormattedPartsOfSpeech.Add("Existential there");
break;

case("PDT"):
FormattedPartsOfSpeech.Add("Predeterminer");
break;

case("WDT"):
FormattedPartsOfSpeech.Add("Wh-determiner");
break;

case("FW"):
FormattedPartsOfSpeech.Add("Foreign word");
break;

case("POS"):
FormattedPartsOfSpeech.Add("Possessive ending");
break;

case("RP"):
FormattedPartsOfSpeech.Add("Particle");
break;

case("SYM"):
FormattedPartsOfSpeech.Add("Symbol");
break;

case("TO"):
FormattedPartsOfSpeech.Add("Infinitive to");
break;

default:
FormattedPartsOfSpeech.Add(p.ToString());
break;


}

}

}
}
Loading

0 comments on commit 058cf5e

Please sign in to comment.