Skip to content

Commit

Permalink
sense export should work.
Browse files Browse the repository at this point in the history
  • Loading branch information
lavedon committed May 6, 2021
1 parent da4ee8a commit 7ae4bc7
Show file tree
Hide file tree
Showing 85 changed files with 455 additions and 137 deletions.
10 changes: 7 additions & 3 deletions API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,13 @@ public static void APICalls(CurrentQuery query)
query.Senses.Add(currentSense);
Console.WriteLine();

Console.WriteLine("----Enter for more - X to exit----");
Console.WriteLine("---- S to Save - X to exit - Enter for more----");
string input = Console.ReadLine().Trim().ToLower();
if (input == "x")
if (input == "S")
{
SavedQueries.AddMember(currentSense);
}
else if (input == "x")
break;
}
catch (Exception ex)
Expand Down Expand Up @@ -474,7 +478,7 @@ public static void APICalls(CurrentQuery query)
if (input == "s")
{
Console.WriteLine("Quote saved.");
SavedQueries.AddQuote(currentQuote);
SavedQueries.AddMember(currentQuote);
}
else if (input == "x")
break;
Expand Down
2 changes: 1 addition & 1 deletion ConsoleUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static void MainMenu(CurrentQuery query)

case ("e" or "export" or "export results"):
Trace.WriteLine("Export quotations.");
if (SavedQueries.Quotes.Count != 0)
if (SavedQueries.Quotes.Count != 0 || SavedQueries.Senses.Count != 0)
SavedQueries.RenderXML();
else {
Console.WriteLine("You have not yet saved anything for export.");
Expand Down
64 changes: 5 additions & 59 deletions OED-export.xml
Original file line number Diff line number Diff line change
@@ -1,75 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<SuperMemoCollection>
<Count>8</Count>
<Count>2</Count>
<SuperMemoElement>
<ID>1</ID>
<Title>W. R. Dawson - 1450</Title>
<Title>H. Purcell - 1683</Title>
<Type>Topic</Type>
<Content>
<Question>Giff it to a dogge that goþe assaut, and he will forsake the biche, and she will go wode. --W. R. Dawson, 1450</Question>
<Question>The English Practitioner..will find a few terms of Art perhaps unusual to him, the chief of which are..Piano. --H. Purcell, 1683</Question>
<SuperMemoReference>&amp;lt;H5 dir=ltr align=left&amp;gt;&amp;lt;Font size=&amp;quot;1&amp;quot; style=&amp;quot;color: transparent&amp;quot;&amp;gt; SuperMemo Reference:&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;FONT class=reference&amp;gt;Title:&amp;quot;My Test Quote&amp;quot; &amp;lt;br&amp;gt;Source: Oxford English Dictionary</SuperMemoReference>
</Content>
</SuperMemoElement>
<SuperMemoElement>
<ID>2</ID>
<Title>G. Booth - 1700</Title>
<Title> - 1724</Title>
<Type>Topic</Type>
<Content>
<Question>Some..say, that he set the end of the Spear against the Wall, and attempted to run himself upon the point. --G. Booth, 1700</Question>
<SuperMemoReference>&amp;lt;H5 dir=ltr align=left&amp;gt;&amp;lt;Font size=&amp;quot;1&amp;quot; style=&amp;quot;color: transparent&amp;quot;&amp;gt; SuperMemo Reference:&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;FONT class=reference&amp;gt;Title:&amp;quot;My Test Quote&amp;quot; &amp;lt;br&amp;gt;Source: Oxford English Dictionary</SuperMemoReference>
</Content>
</SuperMemoElement>
<SuperMemoElement>
<ID>3</ID>
<Title>J. Shirley - 1703</Title>
<Type>Topic</Type>
<Content>
<Question>The furious Sword ran through his right Side. --J. Shirley, 1703</Question>
<SuperMemoReference>&amp;lt;H5 dir=ltr align=left&amp;gt;&amp;lt;Font size=&amp;quot;1&amp;quot; style=&amp;quot;color: transparent&amp;quot;&amp;gt; SuperMemo Reference:&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;FONT class=reference&amp;gt;Title:&amp;quot;My Test Quote&amp;quot; &amp;lt;br&amp;gt;Source: Oxford English Dictionary</SuperMemoReference>
</Content>
</SuperMemoElement>
<SuperMemoElement>
<ID>4</ID>
<Title>D. Defoe - 1725</Title>
<Type>Topic</Type>
<Content>
<Question>The second Messenger came in and delivered his Part of the Errand. --D. Defoe, 1725</Question>
<SuperMemoReference>&amp;lt;H5 dir=ltr align=left&amp;gt;&amp;lt;Font size=&amp;quot;1&amp;quot; style=&amp;quot;color: transparent&amp;quot;&amp;gt; SuperMemo Reference:&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;FONT class=reference&amp;gt;Title:&amp;quot;My Test Quote&amp;quot; &amp;lt;br&amp;gt;Source: Oxford English Dictionary</SuperMemoReference>
</Content>
</SuperMemoElement>
<SuperMemoElement>
<ID>5</ID>
<Title>J. Thomson - 1727</Title>
<Type>Topic</Type>
<Content>
<Question>Immortal Forms, On heavenly Errands bent. --J. Thomson, 1727</Question>
<SuperMemoReference>&amp;lt;H5 dir=ltr align=left&amp;gt;&amp;lt;Font size=&amp;quot;1&amp;quot; style=&amp;quot;color: transparent&amp;quot;&amp;gt; SuperMemo Reference:&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;FONT class=reference&amp;gt;Title:&amp;quot;My Test Quote&amp;quot; &amp;lt;br&amp;gt;Source: Oxford English Dictionary</SuperMemoReference>
</Content>
</SuperMemoElement>
<SuperMemoElement>
<ID>6</ID>
<Title>T. B. Macaulay - 1833</Title>
<Type>Topic</Type>
<Content>
<Question>The American dependencies of the Castilian crown still extended far to the North of Cancer and far to the South of Capricorn. --T. B. Macaulay, 1833</Question>
<SuperMemoReference>&amp;lt;H5 dir=ltr align=left&amp;gt;&amp;lt;Font size=&amp;quot;1&amp;quot; style=&amp;quot;color: transparent&amp;quot;&amp;gt; SuperMemo Reference:&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;FONT class=reference&amp;gt;Title:&amp;quot;My Test Quote&amp;quot; &amp;lt;br&amp;gt;Source: Oxford English Dictionary</SuperMemoReference>
</Content>
</SuperMemoElement>
<SuperMemoElement>
<ID>7</ID>
<Title>E. B. Denison - 1867</Title>
<Type>Topic</Type>
<Content>
<Question>The tropic of Capricorn, which the sun reaches in our winter and the southern midsummer. --E. B. Denison, 1867</Question>
<SuperMemoReference>&amp;lt;H5 dir=ltr align=left&amp;gt;&amp;lt;Font size=&amp;quot;1&amp;quot; style=&amp;quot;color: transparent&amp;quot;&amp;gt; SuperMemo Reference:&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;FONT class=reference&amp;gt;Title:&amp;quot;My Test Quote&amp;quot; &amp;lt;br&amp;gt;Source: Oxford English Dictionary</SuperMemoReference>
</Content>
</SuperMemoElement>
<SuperMemoElement>
<ID>8</ID>
<Title>‘E. Kirk’ - 1894</Title>
<Type>Topic</Type>
<Content>
<Question>Capricorn people resent all interference, and never meddle with the affairs of others. --‘E. Kirk’, 1894</Question>
<Question>Piano, or the Letter P, signifies Soft or Low. --, 1724</Question>
<SuperMemoReference>&amp;lt;H5 dir=ltr align=left&amp;gt;&amp;lt;Font size=&amp;quot;1&amp;quot; style=&amp;quot;color: transparent&amp;quot;&amp;gt; SuperMemo Reference:&amp;lt;/font&amp;gt;&amp;lt;br&amp;gt;&amp;lt;FONT class=reference&amp;gt;Title:&amp;quot;My Test Quote&amp;quot; &amp;lt;br&amp;gt;Source: Oxford English Dictionary</SuperMemoReference>
</Content>
</SuperMemoElement>
Expand Down
68 changes: 66 additions & 2 deletions SavedQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,29 @@ public static class SavedQueries

public static string WordID { get; set; }
public static List<Quote> Quotes { get; set; }
public static List<Sense> Senses { get; set; }

public static string ExportFileName { get; set; } = "OED-export.xml";

static SavedQueries()
{
Instance=true;
Quotes = new();
Senses = new();
}

public static void AddQuote(Quote quote) {
public static void AddMember(Sense sense) {
Senses.Add(sense);
if (Senses.Count == 1) {
Console.WriteLine($"{Senses.Count} sense saved for export.");
}
else {
Console.WriteLine($"{Senses.Count} senses saved for export.");
}

}

public static void AddMember(Quote quote) {
Quotes.Add(quote);
if (Quotes.Count == 1) {
Console.WriteLine($"{Quotes.Count} quote saved for export.");
Expand All @@ -44,9 +57,11 @@ public static void RenderXML() {

xml.WriteStartDocument();
xml.WriteStartElement("SuperMemoCollection");
int count = Quotes.Count;
int count = Quotes.Count + Senses.Count;
xml.WriteElementString("Count", $"{count}");
// @TODO Add count number and ID number
if (Quotes.Count > 0) {
Console.WriteLine("Exporting Quotes...");
for (int i = 0; i < Quotes.Count; i++) {
try {
xml.WriteStartElement("SuperMemoElement");
Expand Down Expand Up @@ -74,6 +89,55 @@ public static void RenderXML() {
}
}
}
}
if (Senses.Count > 0) {
Console.WriteLine("Exporting Senses...");
string obsoleteText = "";
string mainUsageText = "";
for (int i = 0; i < Senses.Count; i++) {

if (Senses[i].IsObsolete) {
obsoleteText = "This usage is obsolete.";
}
else {
obsoleteText = "This usage is NOT obsolete.";
}

if (Senses[i].IsMainUsage) {
mainUsageText = "This sense is the main sense for this word.";
}
else {
mainUsageText = "This sense is NOT the main sense for this word.";
}


try {
xml.WriteStartElement("SuperMemoElement");
int ID = i + 1;
xml.WriteElementString("ID", $"{ID}");
xml.WriteElementString("Title", $"{Senses[i].Definition}");
xml.WriteElementString("Type", "Topic");
xml.WriteStartElement("Content");
xml.WriteElementString("Question", $"{Senses[i].Definition} --This sense was first used in the year {Senses[i].Start}, {obsoleteText}, {mainUsageText}, {Senses[i].OedReference}");

string encoded = WebUtility.HtmlEncode("<H5 dir=ltr align=left><Font size=\"1\" style=\"color: transparent\"> SuperMemo Reference:</font><br><FONT class=reference>Title:\"My Test Quote\" <br>Source: Oxford English Dictionary");
xml.WriteElementString("SuperMemoReference", encoded);

xml.WriteEndElement();
xml.WriteEndElement();

}
catch (AggregateException ae)
{
var ex = ae.Flatten().InnerExceptions;
Console.WriteLine("Error writing XML document:");
foreach (var exception in ex)
{
Console.WriteLine($"{ex.ToString()}");
}
}
}
}

try {
xml.WriteEndElement();
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.
58 changes: 58 additions & 0 deletions logs/Log_OxfordApplication_20210504-2224.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Leaving Main method.
Starting Main Menu
In MainMenu()
Automatically looking up user entered word:
mountain
Found that QueryMode is set to words.
Looking up the word:
mountain
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.
[{"id": "mountain_nn01", "band": 7, "meta": {"created": 1908, "revised": true, "updated": 2003}, "lemma": "mountain", "oed_url": "https://www.oed.com/view/Entry/122893#eid35744113", "daterange": {"end": null, "start": 1275, "obsolete": false, "rangestring": "c1275\u2014"}, "etymology": {"etymons": [{"word": "montain", "language": "French"}, {"word": "montaine", "language": "French"}, {"word": "mountaine", "language": "French"}, {"word": "muntaine", "language": "French"}, {"word": "muntaigne", "language": "French"}, {"word": "montaigne", "language": "French"}, {"word": "montangne", "language": "French"}], "etymology_type": "borrowing", "etymon_language": [["European languages", "Italic", "Romance", "Italo-Western", "Gallo-Romance", "French"]], "source_language": [["European languages", "Italic", "Latin"]], "etymology_summary": "A borrowing from French."}, "first_use": "Layamon", "frequency": [[1750, 93], [1760, 100], [1770, 110], [1780, 120], [1790, 130], [1800, 140], [1810, 140], [1820, 150], [1830, 150], [1840, 140], [1850, 140], [1860, 140], [1870, 130], [1880, 130], [1890, 120], [1900, 110], [1910, 100], [1920, 96], [1930, 87], [1940, 81], [1950, 74], [1960, 65], [1970, 58], [1980, 53], [1990, 54], [2000, 56], [2010, 57]], "sense_ids": ["mountain_nn01-35744118", "mountain_nn01-35744345", "mountain_nn01-35744405", "mountain_nn01-35744498", "mountain_nn01-35744528", "mountain_nn01-35744574", "mountain_nn01-35744798", "mountain_nn01-35744921", "mountain_nn01-35745061", "mountain_nn01-35745115", "mountain_nn01-35745248", "mountain_nn01-35745273"], "definition": "A large natural elevation of the earth's surface, esp. one high and steep in form (larger and higher than a hill) and with a summit of relatively small area.", "main_entry": true, "inflections": [{"region": "British", "inflections": [{"form": "mountain", "part_of_speech": "NN"}, {"form": "mountains", "part_of_speech": "NNS"}]}, {"region": "US", "inflections": [{"form": "mountain", "part_of_speech": "NN"}, {"form": "mountains", "part_of_speech": "NNS"}]}], "frequency_id": "mountain_nn01-fq", "oed_reference": "mountain, n.", "pronunciations": [{"ipa": ["\u02c8ma\u028ant\u1d7bn"], "region": "British"}, {"ipa": ["\u02c8ma\u028ant(\u0259)n"], "region": "US"}], "parts_of_speech": ["NN"], "primary_sense_id": "mountain_nn01-35744118"}]
Extracted definition.
Set definition to query object.
Now to get and set the word ID.
The wordID was grabbed as:
mountain_nn01The user's input was read as:
s
Get senses selected.
API.cs is starting senses mode.
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

Called callSensesAPI
Making the request
System.Net.Http.HttpConnection+ContentLengthReadStream
Got senses responses.
Set JSONResponse to the response.
Ran senses using start.
In MainMenu()
The user's input was read as:
x
Exit selected.
58 changes: 58 additions & 0 deletions logs/Log_OxfordApplication_20210505-2150.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Leaving Main method.
Starting Main Menu
In MainMenu()
Automatically looking up user entered word:
computer
Found that QueryMode is set to words.
Looking up the word:
computer
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.
[{"id": "computer_nn01", "band": 9, "meta": {"created": 1891, "revised": true, "updated": 2008}, "lemma": "computer", "oed_url": "https://www.oed.com/view/Entry/37975#eid8618136", "daterange": {"end": null, "start": 1613, "obsolete": false, "rangestring": "1613\u2014"}, "etymology": {"etymons": [{"word": "compute", "language": "English", "target_id": "compute_vb01", "part_of_speech": "VB"}, {"word": "-er", "language": "English", "target_id": "er_su01", "part_of_speech": "SUFFIX"}], "etymology_type": "derivative", "etymon_language": [["English"]], "source_language": [["European languages", "Italic", "Latin"]], "etymology_summary": "Formed within English, by derivation."}, "first_use": "\u2018R. B.\u2019", "frequency": [[1750, 0.21], [1760, 0.18], [1770, 0.17], [1780, 0.16], [1790, 0.15], [1800, 0.14], [1810, 0.083], [1820, 0.077], [1830, 0.086], [1840, 0.086], [1850, 0.093], [1860, 0.11], [1870, 0.13], [1880, 0.16], [1890, 0.18], [1900, 0.21], [1910, 0.24], [1920, 0.45], [1930, 2.1], [1940, 10], [1950, 17], [1960, 40], [1970, 77], [1980, 110], [1990, 120], [2000, 120], [2010, 120]], "sense_ids": ["computer_nn01-8618138", "computer_nn01-8618177", "computer_nn01-130514973", "computer_nn01-130514976"], "definition": "An electronic device (or system of devices) which is used to store, manipulate, and communicate information, perform complex calculations, or control or regulate other devices or machines, and is capable of receiving information (data) and of processing it in accordance with variable procedural instructions (programs or software); esp. a small, self-contained one for individual use in the home or workplace, used esp. for handling text, images, music, and video, accessing and using the internet\u2026", "main_entry": true, "inflections": [{"region": "British", "inflections": [{"form": "computer", "part_of_speech": "NN"}, {"form": "computers", "part_of_speech": "NNS"}]}, {"region": "US", "inflections": [{"form": "computer", "part_of_speech": "NN"}, {"form": "computers", "part_of_speech": "NNS"}]}], "frequency_id": "computer_nn01-fq", "oed_reference": "computer, n.", "pronunciations": [{"ipa": ["k\u0259m\u02c8pju\u02d0t\u0259"], "region": "British"}, {"ipa": ["k\u0259m\u02c8pjud\u0259r"], "region": "US"}], "parts_of_speech": ["NN"], "primary_sense_id": "computer_nn01-130514973"}]
Extracted definition.
Set definition to query object.
Now to get and set the word ID.
The wordID was grabbed as:
computer_nn01The user's input was read as:
s
Get senses selected.
API.cs is starting senses mode.
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

Called callSensesAPI
Making the request
System.Net.Http.HttpConnection+ContentLengthReadStream
Got senses responses.
Set JSONResponse to the response.
Ran senses using start.
In MainMenu()
The user's input was read as:
x
Exit selected.
Loading

0 comments on commit 7ae4bc7

Please sign in to comment.