Basic support for word subgroups

This commit is contained in:
~lucidiot 2022-07-14 17:57:13 +02:00
parent bea2191404
commit 083a2da17d
5 changed files with 75 additions and 3 deletions

View File

@ -88,7 +88,14 @@ namespace ToeCracker {
if (this.tabControl.SelectedTab.Controls.Count == 0)
return null;
return (string)((ListBox)this.tabControl.SelectedTab.Controls[0]).SelectedItem;
string word = (string)((ListBox)this.tabControl.SelectedTab.Controls[0]).SelectedItem;
word = word.Trim();
// Ignore empty lines and subgroups. Subgroups are represented as "-- ANTONYMS --"
if (word == String.Empty || word.StartsWith("-- "))
return null;
return word;
}
}

View File

@ -78,6 +78,15 @@ namespace ToeCracker.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to antonyms.
/// </summary>
internal static string Antonyms {
get {
return ResourceManager.GetString("Antonyms", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to noun.
/// </summary>
@ -105,6 +114,15 @@ namespace ToeCracker.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to related terms.
/// </summary>
internal static string RelatedTerms {
get {
return ResourceManager.GetString("RelatedTerms", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to An error occurred while fetching data from the thesaurus:.
/// </summary>
@ -132,6 +150,15 @@ namespace ToeCracker.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to similar terms.
/// </summary>
internal static string SimilarTerms {
get {
return ResourceManager.GetString("SimilarTerms", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to sounds kind of like.
/// </summary>

View File

@ -125,6 +125,10 @@
<value>adverbe</value>
<comment>Word group for synonyms of an adverb.</comment>
</data>
<data name="Antonyms" xml:space="preserve">
<value>antonymes</value>
<comment>Word subgroup for antonyms of a word with the same grammatical function.</comment>
</data>
<data name="Noun" xml:space="preserve">
<value>nom</value>
<comment>Word group for synonyms of a noun.</comment>
@ -137,6 +141,10 @@
<value>Erreur de lecture XML</value>
<comment>Title of the dialog box where the parsing error is shown.</comment>
</data>
<data name="RelatedTerms" xml:space="preserve">
<value>termes liés</value>
<comment>Word subgroup for terms related to a word with the same grammatical function.</comment>
</data>
<data name="RequestError" xml:space="preserve">
<value>Une erreur s'est produite lors de la requête au thésaurus :</value>
<comment>Error message shown when an HTTP request fails. Further details are given below this message.</comment>
@ -149,6 +157,10 @@
<value>rime avec</value>
<comment>Word group for words that rhyme with this word.</comment>
</data>
<data name="SimilarTerms" xml:space="preserve">
<value>termes similaires</value>
<comment>Word subgroup for terms similar to a word with the same grammatical function.</comment>
</data>
<data name="SoundsLike" xml:space="preserve">
<value>sonne comme</value>
<comment>Word group for words that "sound kind of like" this word.</comment>

View File

@ -125,6 +125,10 @@
<value>adverb</value>
<comment>Word group for synonyms of an adverb.</comment>
</data>
<data name="Antonyms" xml:space="preserve">
<value>antonyms</value>
<comment>Word subgroup for antonyms of a word with the same grammatical function.</comment>
</data>
<data name="Noun" xml:space="preserve">
<value>noun</value>
<comment>Word group for synonyms of a noun.</comment>
@ -137,6 +141,10 @@
<value>XML parsing error</value>
<comment>Title of the dialog box where the parsing error is shown.</comment>
</data>
<data name="RelatedTerms" xml:space="preserve">
<value>related terms</value>
<comment>Word subgroup for terms related to a word with the same grammatical function.</comment>
</data>
<data name="RequestError" xml:space="preserve">
<value>An error occurred while fetching data from the thesaurus:</value>
<comment>Error message shown when an HTTP request fails. Further details are given below this message.</comment>
@ -149,6 +157,10 @@
<value>rhymes with</value>
<comment>Word group for words that rhyme with this word.</comment>
</data>
<data name="SimilarTerms" xml:space="preserve">
<value>similar terms</value>
<comment>Word subgroup for terms similar to a word with the same grammatical function.</comment>
</data>
<data name="SoundsLike" xml:space="preserve">
<value>sounds kind of like</value>
<comment>Word group for words that "sound kind of like" this word.</comment>

View File

@ -24,9 +24,12 @@ namespace ToeCracker {
Dictionary<string, string> tr = new Dictionary<string, string>();
tr["adjective"] = Properties.Resources.Adjective;
tr["adverb"] = Properties.Resources.Verb;
tr["antonyms"] = Properties.Resources.Antonyms;
tr["noun"] = Properties.Resources.Noun;
tr["sounds kind of like"] = Properties.Resources.SoundsLike;
tr["related terms"] = Properties.Resources.RelatedTerms;
tr["rhymes with"] = Properties.Resources.RhymesWith;
tr["similar terms"] = Properties.Resources.SimilarTerms;
tr["sounds kind of like"] = Properties.Resources.SoundsLike;
tr["verb"] = Properties.Resources.Verb;
return tr;
}
@ -82,9 +85,10 @@ namespace ToeCracker {
}
/*
* We can now iterate on the nodes inside of the <div>. We can expect three types of tags:
* We can now iterate on the nodes inside of the <div>. We can expect four types of tags:
* - <h2>, which contains the word we just searched and that we can ignore
* - <h3>, the beginning of a new word group
* - <h4>, a subgroup within the word group
* - <ul>, listing words inside a new group.
* We will ignore any other tags to stay flexible.
*/
@ -110,6 +114,16 @@ namespace ToeCracker {
words.Clear();
}
groupName = node.InnerText;
} else if (node.Name.ToLowerInvariant() == "h4") {
// We will represent subgroups by adding an empty word (an empty line in the display),
// and format the group name in uppercase with dashes: "-- ANTONYMS --"
if (groupName == null)
throw new XmlException("Unexpected subgroup name with no group name.");
words.Add("");
string title = node.InnerText.ToLowerInvariant();
if (Translations.ContainsKey(title))
title = Translations[title];
words.Add(String.Format("-- {0} --", title.ToUpperInvariant()));
} else if (node.Name.ToLowerInvariant() == "ul") {
if (groupName == null)
throw new XmlException("Unexpected word list with no group name.");