[gbrainy] Better structure of verbal analogies classes
- From: Jordi Mas <jmas src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gbrainy] Better structure of verbal analogies classes
- Date: Sat, 5 Sep 2009 21:13:34 +0000 (UTC)
commit d39b86ad178899491a13997a00bb76d3467af5e4
Author: Jordi Mas <jmas softcatala org>
Date: Sat Sep 5 23:13:22 2009 +0200
Better structure of verbal analogies classes
data/verbal_analogies.xml | 73 +++++-
po/POTFILES.in | 7 +-
src/GameManager.cs | 7 +-
src/Makefile.am | 9 +-
src/VerbalAnalogies.cs | 275 --------------------
src/VerbalAnalogies/Analogies.cs | 179 +++++++++++++
src/VerbalAnalogies/AnalogiesFactory.cs | 150 +++++++++++
src/VerbalAnalogies/AnalogiesMultipleOptions.cs | 115 ++++++++
src/VerbalAnalogies/AnalogiesPairOfWordsCompare.cs | 106 ++++++++
src/VerbalAnalogies/AnalogiesPairOfWordsOptions.cs | 115 ++++++++
src/VerbalAnalogies/AnalogiesQuestionAnswer.cs | 69 +++++
src/VerbalAnalogies/Analogy.cs | 72 +++++
src/gbrainy.cs | 7 +-
13 files changed, 894 insertions(+), 290 deletions(-)
---
diff --git a/data/verbal_analogies.xml b/data/verbal_analogies.xml
index 4fb7116..6351e9b 100644
--- a/data/verbal_analogies.xml
+++ b/data/verbal_analogies.xml
@@ -1,6 +1,18 @@
<analogies>
+ <!---
+ This is a collection of verbal analogies. This work is licensed under GPL 2.0 or higher license.
+ This the same license that gbrainy package.
+
+ Authors:
+ Carlos Navarro <navarro37 at gmail dot com>
+ Jordi Mas <jmas at softcatala dot org>
+
+ See: http://live.gnome.org/gbrainy/Analogies for more details about how to use this file and its format.
+
+ You can look at VerbalAnalogies.cs source code file as reference.
+ -->
<analogy>
- <_question>Which of the following sports is the odd one?</_question>
+ <_question type = "MultipleOptions">Which of the following sports is the odd one?</_question>
<_tip>Think of the items used in the game.</_tip>
<_answer>Water polo</_answer>
<_answer>Basketball</_answer>
@@ -9,22 +21,69 @@
<_rationale>It is the only one that does not use a ball in the game.</_rationale>
</analogy>
<analogy>
- <_question>A terrier is to a dog like a?</_question>
+ <_question type = "MultipleOptions">A terrier is to a dog like a?</_question>
<_answer correct ="yes">chicken / bird</_answer>
<_answer>horse / pony</_answer>
<_answer>ant / insect</_answer>
- <_answer>dog / cat </_answer>
+ <_answer>dog / cat</_answer>
</analogy>
<analogy>
<_question>A restaurant is to a dinner like a park is to?</_question>
<_answer correct ="yes">picnic</_answer>
</analogy>
<analogy>
- <_question type = "PairOfWords">moratorium / payment</_question>
- <_answer correct ="yes">reprieve / punishment </_answer>
+ <_question type = "PairOfWordsOptions">moratorium / payment</_question>
+ <_answer correct ="yes">reprieve / punishment</_answer>
<_answer>amnesty / prisoner</_answer>
<_answer>date / meeting</_answer>
- <_answer>sentence / prison </_answer>
+ <_answer>sentence / prison</_answer>
+ </analogy>
+ <analogy>
+ <_question type = "PairOfWordsCompare">hungry / eat | tired</_question>
+ <_answer correct ="yes">sleep | rest</_answer>
+ </analogy>
+ <analogy>
+ <_question type = "PairOfWordsCompare">hunter / rifle | photographer</_question>
+ <_answer correct ="yes">camera</_answer>
+ </analogy>
+ <analogy>
+ <_question type = "PairOfWordsCompare">box / open | banana</_question>
+ <_answer correct ="yes">peel</_answer>
+ </analogy>
+ <analogy>
+ <_question type = "PairOfWordsCompare">shovel / dig | axe</_question>
+ <_answer correct ="yes">chop</_answer>
+ </analogy>
+ <analogy>
+ <_question type = "PairOfWordsCompare">glass / break | paper</_question>
+ <_answer correct ="yes">tear | rips</_answer>
+ </analogy>
+ <analogy>
+ <_question type = "PairOfWordsCompare">feet / two | toe</_question>
+ <_answer correct ="yes">ten</_answer>
+ </analogy>
+ <analogy>
+ <_question type = "PairOfWordsCompare">fish / aquarium | monkey</_question>
+ <_answer correct ="yes">zoo</_answer>
+ </analogy>
+ <analogy>
+ <_question type = "PairOfWordsCompare">ring / finger | bracelet</_question>
+ <_answer correct ="yes">wrist</_answer>
+ </analogy>
+ <analogy>
+ <_question type = "PairOfWordsCompare">seals / flippers | bird</_question>
+ <_answer correct ="yes">wings</_answer>
+ </analogy>
+ <analogy>
+ <_question type = "PairOfWordsCompare">stick / float | stone</_question>
+ <_answer correct ="yes">sink</_answer>
+ </analogy>
+ <analogy>
+ <_question type = "PairOfWordsCompare">leopard / spots | tiger</_question>
+ <_answer correct ="yes">stripes</_answer>
+ </analogy>
+ <analogy>
+ <_question type = "PairOfWordsCompare">toy / play | tool</_question>
+ <_answer correct ="yes">work</_answer>
</analogy>
</analogies>
-
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 0ae8b0a..6e86faf 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -66,4 +66,9 @@ src/PuzzleGames/PuzzleSquareSheets.cs
src/PuzzleGames/PuzzleTetris.cs
src/PuzzleGames/PuzzleTriangles.cs
src/PuzzleGames/PuzzleTrianglesWithNumbers.cs
-src/VerbalAnalogies.cs
+src/VerbalAnalogies/Analogies.cs
+src/VerbalAnalogies/AnalogiesFactory.cs
+src/VerbalAnalogies/AnalogiesMultipleOptions.cs
+src/VerbalAnalogies/AnalogiesPairOfWordsCompare.cs
+src/VerbalAnalogies/AnalogiesPairOfWordsOptions.cs
+data/verbal_analogies.xml
diff --git a/src/GameManager.cs b/src/GameManager.cs
index d49f874..3f47081 100644
--- a/src/GameManager.cs
+++ b/src/GameManager.cs
@@ -99,7 +99,10 @@ public class GameManager
static Type[] VerbalAnalogiesInternal = new Type[]
{
- typeof (VerbalAnalogies),
+ typeof (AnalogiesQuestionAnswer),
+ typeof (AnalogiesMultipleOptions),
+ typeof (AnalogiesPairOfWordsOptions),
+ typeof (AnalogiesPairOfWordsCompare),
};
bool once;
@@ -126,7 +129,7 @@ public class GameManager
if (once == false) {
once = true;
- Console.WriteLine (Catalog.GetString ("Games registered: {0}: {1} logic puzzles, {2} math trainers, {3} memory trainers, {4} verbal analogies"),
+ Console.WriteLine (Catalog.GetString ("Games registered: {0}: {1} logic puzzles, {2} calculation trainers, {3} memory trainers, {4} verbal analogies"),
LogicPuzzles.Count + CalculationTrainers.Count + MemoryTrainers.Count + VerbalAnalogies.Count,
LogicPuzzles.Count, CalculationTrainers.Count, MemoryTrainers.Count, VerbalAnalogies.Count);
}
diff --git a/src/Makefile.am b/src/Makefile.am
index 702a9b6..2230f77 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -74,10 +74,17 @@ GBRAINY_CSDISTFILES = \
$(srcdir)/CalculationGames/CalculationPrimes.cs \
$(srcdir)/MemoryGames/MemoryFacts.cs \
$(srcdir)/PuzzleGames/PuzzleCounting.cs \
- $(srcdir)/VerbalAnalogies.cs \
+ $(srcdir)/VerbalAnalogies/Analogy.cs \
+ $(srcdir)/VerbalAnalogies/AnalogiesFactory.cs \
+ $(srcdir)/VerbalAnalogies/Analogies.cs \
+ $(srcdir)/VerbalAnalogies/AnalogiesQuestionAnswer.cs \
+ $(srcdir)/VerbalAnalogies/AnalogiesMultipleOptions.cs \
+ $(srcdir)/VerbalAnalogies/AnalogiesPairOfWordsOptions.cs \
+ $(srcdir)/VerbalAnalogies/AnalogiesPairOfWordsCompare.cs \
$(srcdir)/SimpleLabel.cs \
$(srcdir)/gbrainy.cs
+
ASSEMBLIES = \
$(GBRAINY_LIBS) \
$(MONO_ADDINS_LIBS) \
diff --git a/src/VerbalAnalogies/Analogies.cs b/src/VerbalAnalogies/Analogies.cs
new file mode 100644
index 0000000..80d0a6d
--- /dev/null
+++ b/src/VerbalAnalogies/Analogies.cs
@@ -0,0 +1,179 @@
+/*
+ * Copyright (C) 2009 Jordi Mas i Hernà ndez <jmas softcatala org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+using System;
+using System.Collections.Generic;
+
+using Mono.Unix;
+
+public abstract class Analogies : Game
+{
+ protected Analogy current;
+
+ public override string Name {
+ get { return Catalog.GetString ("Verbal analogies"); }
+ }
+
+ public override string Question {
+ get {
+ return current.question;
+ }
+ }
+
+ public override string Tip {
+ get {
+ if (current == null)
+ return null;
+ else
+ return current.tip;
+ }
+ }
+
+ public override string Answer {
+ get {
+ if (current == null)
+ return string.Empty;
+
+ if (current.MultipleAnswers == true)
+ {
+ string [] items;
+ string str = string.Empty;
+
+ items = right_answer.Split ('|');
+
+ for (int i = 0 ; i < items.Length; i++)
+ {
+ str += items [i].Trim ();
+ if (i + 1 < items.Length) {
+ // Translators: this the separator used when concatenating multiple possible answers for verbal analogies
+ // For example: "Possible correct answers are: sleep, rest."
+ str += Catalog.GetString (", ");
+ }
+
+ }
+ str = String.Format (Catalog.GetString ("Possible correct answers are: {0}."), str);
+ return str;
+ }
+
+ if (String.IsNullOrEmpty (current.rationale) == false)
+ return base.Answer + " " + current.rationale;
+
+ return base.Answer;
+ }
+ }
+
+ public override Types Type {
+ get { return Game.Types.VerbalAnalogy;}
+ }
+
+ public abstract ArrayListIndicesRandom Indices {
+ get;
+ set;
+ }
+
+ public abstract int CurrentIndex {
+ get;
+ set;
+ }
+
+ public abstract Dictionary <int, Analogy> List {
+ get;
+ }
+
+ public override void Initialize ()
+ {
+ current = GetNext ();
+
+ if (current == null)
+ return;
+ }
+
+ public Analogy GetNext ()
+ {
+ int idx;
+ Analogy analogy;
+
+ if (Indices == null || CurrentIndex + 1 >= List.Count) {
+ Indices = new ArrayListIndicesRandom (List.Count);
+ Indices.Initialize ();
+ }
+ else
+ CurrentIndex++;
+
+ idx = Indices [CurrentIndex];
+
+ try
+ {
+ List.TryGetValue (idx, out analogy);
+ }
+
+ catch (KeyNotFoundException)
+ {
+ analogy = null;
+ }
+
+ if (analogy != null && analogy.answers != null) { // Randomize answers order
+
+ ArrayListIndicesRandom indices;
+ string [] answers;
+ int new_right = 0;
+
+ indices = new ArrayListIndicesRandom (analogy.answers.Length);
+ answers = new string [analogy.answers.Length];
+
+ indices.Initialize ();
+
+ for (int i = 0; i < indices.Count; i++)
+ {
+ answers [i] = Catalog.GetString (analogy.answers [indices[i]]);
+ if (indices[i] == analogy.right)
+ new_right = i;
+ }
+ analogy.right = new_right;
+ analogy.answers = answers;
+ }
+
+ analogy.question = Catalog.GetString (analogy.question);
+
+ if (String.IsNullOrEmpty (analogy.tip) == false)
+ analogy.tip = Catalog.GetString (analogy.tip);
+
+ if (String.IsNullOrEmpty (analogy.rationale) == false)
+ analogy.rationale = Catalog.GetString (analogy.rationale);
+
+ return analogy;
+ }
+
+ public override bool CheckAnswer (string answer)
+ {
+ string [] items = right_answer.Split ('|');
+ Console.WriteLine ("answer is null {0}", answer == null);
+
+ foreach (string ans in items)
+ {
+ string str = ans.Trim ();
+
+ if (String.Compare (str, answer, true) == 0)
+ return true;
+ }
+
+ return base.CheckAnswer (answer);
+ }
+
+}
diff --git a/src/VerbalAnalogies/AnalogiesFactory.cs b/src/VerbalAnalogies/AnalogiesFactory.cs
new file mode 100644
index 0000000..1015ad1
--- /dev/null
+++ b/src/VerbalAnalogies/AnalogiesFactory.cs
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2009 Jordi Mas i Hernà ndez <jmas softcatala org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+using System;
+using System.Xml;
+using System.IO;
+using System.Collections.Generic;
+
+using Cairo;
+using Mono.Unix;
+using Gtk;
+
+static public class AnalogiesFactory
+{
+ static Dictionary <int, Analogy> [] analogies_arrays;
+ static bool read = false;
+
+ static AnalogiesFactory ()
+ {
+ analogies_arrays = new Dictionary <int, Analogy> [(int) Analogy.Type.Last];
+
+ for (int i = 0; i < (int) Analogy.Type.Last; i++)
+ analogies_arrays[i] = new Dictionary <int, Analogy> ();
+ }
+
+ static public Dictionary <int, Analogy> Get (Analogy.Type type)
+ {
+ if (read == false)
+ Read ();
+
+ return analogies_arrays [(int) type];
+ }
+
+ static public void Read ()
+ {
+ Analogy analogy;
+ string name;
+ List <string> answers;
+
+ try
+ {
+ StreamReader myStream = new StreamReader (Defines.DATA_DIR + Defines.VERBAL_ANALOGIES);
+ XmlTextReader reader = new XmlTextReader (myStream);
+ answers = new List <string> ();
+
+ analogy = new Analogy ();
+ while (reader.Read ())
+ {
+ name = reader.Name.ToLower ();
+ switch (name) {
+ case "analogy":
+ if (reader.NodeType == XmlNodeType.Element) {
+ analogy = new Analogy ();
+ answers.Clear ();
+ }
+ else {
+ if (reader.NodeType == XmlNodeType.EndElement) {
+ analogy.answers = answers.ToArray ();
+ analogies_arrays [(int) analogy.type].Add (analogies_arrays [(int) analogy.type].Count, analogy);
+ }
+ }
+ break;
+ case "_question":
+ if (reader.NodeType != XmlNodeType.Element)
+ return;
+
+ string type;
+
+ type = reader.GetAttribute ("type");
+
+ if (String.IsNullOrEmpty (type) == false) {
+ switch (type.ToLower ()) {
+ case "multipleoptions":
+ analogy.type = Analogy.Type.MultipleOptions;
+ break;
+ case "pairofwordsoptions":
+ analogy.type = Analogy.Type.PairOfWordsOptions;
+ break;
+ case "pairofwordscompare":
+ analogy.type = Analogy.Type.PairOfWordsCompare;
+ break;
+ default:
+ analogy.type = Analogy.Type.QuestionAnswer;
+ break;
+ }
+ }
+ analogy.question = reader.ReadElementString ();
+ break;
+ case "_tip":
+ if (reader.NodeType == XmlNodeType.Element)
+ analogy.tip = reader.ReadElementString ();
+
+ break;
+ case "_rationale":
+ if (reader.NodeType == XmlNodeType.Element)
+ analogy.rationale = reader.ReadElementString ();
+
+ break;
+ case "_answer":
+ if (reader.NodeType != XmlNodeType.Element)
+ break;
+
+ string right;
+
+ right = reader.GetAttribute ("correct");
+
+ if (String.IsNullOrEmpty (right) == false)
+ if (right.ToLower () == "yes")
+ analogy.right = answers.Count;
+
+ answers.Add (reader.ReadElementString ());
+ break;
+ }
+ }
+
+ read = true;
+
+ int cnt = 0;
+ for (int i = 0; i < (int) Analogy.Type.Last; i++)
+ {
+ cnt += analogies_arrays[i].Count;
+ Console.WriteLine (Catalog.GetString ("Read {0} verbal analogies of type {1}"), analogies_arrays[i].Count,
+ analogies_arrays[i].Count > 0 ? analogies_arrays[i][0].type : Analogy.Type.Last);
+ }
+
+ Console.WriteLine (Catalog.GetString ("Read a total of {0} verbal analogies"), cnt);
+ }
+
+ catch (Exception)
+ {
+ Console.WriteLine ("Error loading {0}", Defines.DATA_DIR + Defines.VERBAL_ANALOGIES);
+ }
+ }
+}
diff --git a/src/VerbalAnalogies/AnalogiesMultipleOptions.cs b/src/VerbalAnalogies/AnalogiesMultipleOptions.cs
new file mode 100644
index 0000000..86adb9b
--- /dev/null
+++ b/src/VerbalAnalogies/AnalogiesMultipleOptions.cs
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2009 Jordi Mas i Hernà ndez <jmas softcatala org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+using System;
+using System.IO;
+using System.Collections.Generic;
+
+using Cairo;
+using Mono.Unix;
+using Gtk;
+
+public class AnalogiesMultipleOptions : Analogies
+{
+ static protected Dictionary <int, Analogy> analogies;
+ static protected ArrayListIndicesRandom analogies_indices;
+ static protected int analogies_index = 0;
+
+ public AnalogiesMultipleOptions ()
+ {
+
+ }
+
+ public override string Name {
+ get { return "AnalogiesMultipleOptions";}
+ }
+
+ public override string Question {
+ get {
+ string str = string.Empty;
+ for (int n = 0; n < current.answers.Length; n++)
+ {
+ str+= GetPossibleAnswer (n);
+
+ if (n +1 < current.answers.Length) {
+ // Translators: this the separator used when concatenating possible options for answering verbal analogies
+ // For example: "Possible correct answers are: a, b, c, d."
+ str += Catalog.GetString (", ");
+ }
+ }
+
+ return String.Format (Catalog.GetString ("{0} Answer {1}."),
+ current.question,
+ str);
+ }
+ }
+
+ public override ArrayListIndicesRandom Indices {
+ get { return analogies_indices; }
+ set { analogies_indices = value; }
+ }
+
+ public override int CurrentIndex {
+ get { return analogies_index; }
+ set { analogies_index = value; }
+ }
+
+ public override Dictionary <int, Analogy> List {
+ get { return analogies; }
+ }
+
+ public override void Initialize ()
+ {
+ if (analogies == null) {
+ analogies = AnalogiesFactory. Get (Analogy.Type.MultipleOptions);
+ }
+
+ current = GetNext ();
+
+ if (current == null)
+ return;
+
+ right_answer = GetPossibleAnswer (current.right);
+ Console.WriteLine ("Name:" + Name + " " + current.ToString ());
+ }
+
+ public override void Draw (CairoContextEx gr, int area_width, int area_height)
+ {
+ double x = DrawAreaX, y = DrawAreaY + 0.1;
+
+ base.Draw (gr, area_width, area_height);
+
+ if (current == null || current.answers == null)
+ return;
+
+ gr.SetPangoLargeFontSize ();
+ gr.MoveTo (0.1, y);
+ gr.ShowPangoText (Catalog.GetString ("Possible answers are:"));
+
+ y += 0.12;
+ x += 0.1;
+ for (int n = 0; n < current.answers.Length; n++)
+ {
+ gr.MoveTo (x, y);
+ gr.ShowPangoText (String.Format ("{0}) {1}", GetPossibleAnswer (n), current.answers[n].ToString ()));
+ gr.Stroke ();
+ y += 0.15;
+ }
+ }
+}
diff --git a/src/VerbalAnalogies/AnalogiesPairOfWordsCompare.cs b/src/VerbalAnalogies/AnalogiesPairOfWordsCompare.cs
new file mode 100644
index 0000000..3f84793
--- /dev/null
+++ b/src/VerbalAnalogies/AnalogiesPairOfWordsCompare.cs
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2009 Jordi Mas i Hernà ndez <jmas softcatala org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+using System;
+using System.IO;
+using System.Collections.Generic;
+
+using Cairo;
+using Mono.Unix;
+using Gtk;
+
+public class AnalogiesPairOfWordsCompare : Analogies
+{
+ static protected Dictionary <int, Analogy> analogies;
+ static protected ArrayListIndicesRandom analogies_indices;
+ static protected int analogies_index = 0;
+
+ string samples, sample, question;
+
+ public AnalogiesPairOfWordsCompare ()
+ {
+
+ }
+
+ public override string Name {
+ get { return "AnalogiesPairOfWordsCompare";}
+ }
+
+ public override ArrayListIndicesRandom Indices {
+ get { return analogies_indices; }
+ set { analogies_indices = value; }
+ }
+
+ public override int CurrentIndex {
+ get { return analogies_index; }
+ set { analogies_index = value; }
+ }
+
+ public override Dictionary <int, Analogy> List {
+ get { return analogies; }
+ }
+
+ public override string Question {
+ get {
+ return String.Format (Catalog.GetString (
+ "Given the pair of words below, which word has the closest relationship to '{0}'?"),
+ sample);
+ }
+ }
+
+ public override void Initialize ()
+ {
+ if (analogies == null) {
+ analogies = AnalogiesFactory. Get (Analogy.Type.PairOfWordsCompare);
+ }
+
+ current = GetNext ();
+
+ if (current == null)
+ return;
+
+ string [] items;
+
+ items = current.question.Split ('|');
+
+ if (items.Length == 2)
+ sample = items [1].Trim ();
+ else
+ sample = string.Empty;
+
+ samples = items [0].Trim ();
+
+ right_answer = current.answers [current.right];
+ Console.WriteLine ("Name:" + Name + " " + current.ToString ());
+ }
+
+ public override void Draw (CairoContextEx gr, int area_width, int area_height)
+ {
+ double x = DrawAreaX, y = DrawAreaY + 0.1;
+
+ base.Draw (gr, area_width, area_height);
+
+ if (current == null || current.answers == null)
+ return;
+
+ gr.SetPangoLargeFontSize ();
+ gr.MoveTo (0.2, y + 0.25);
+ gr.ShowPangoText (String.Format (Catalog.GetString ("Pair of words: {0}"), samples));
+ }
+}
diff --git a/src/VerbalAnalogies/AnalogiesPairOfWordsOptions.cs b/src/VerbalAnalogies/AnalogiesPairOfWordsOptions.cs
new file mode 100644
index 0000000..338204d
--- /dev/null
+++ b/src/VerbalAnalogies/AnalogiesPairOfWordsOptions.cs
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2009 Jordi Mas i Hernà ndez <jmas softcatala org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+using System;
+using System.IO;
+using System.Collections.Generic;
+
+using Cairo;
+using Mono.Unix;
+using Gtk;
+
+public class AnalogiesPairOfWordsOptions : Analogies
+{
+ static protected Dictionary <int, Analogy> analogies;
+ static protected ArrayListIndicesRandom analogies_indices;
+ static protected int analogies_index = 0;
+
+ public AnalogiesPairOfWordsOptions ()
+ {
+
+ }
+
+ public override string Name {
+ get { return "AnalogiesPairOfWordsOptions";}
+ }
+
+ public override ArrayListIndicesRandom Indices {
+ get { return analogies_indices; }
+ set { analogies_indices = value; }
+ }
+
+ public override int CurrentIndex {
+ get { return analogies_index; }
+ set { analogies_index = value; }
+ }
+
+ public override Dictionary <int, Analogy> List {
+ get { return analogies; }
+ }
+
+ public override string Question {
+ get {
+ string str = string.Empty;
+ for (int n = 0; n < current.answers.Length; n++)
+ {
+ str+= GetPossibleAnswer (n);
+
+ if (n +1 < current.answers.Length) {
+ // Translators: this the separator used when concatenating possible options for answering verbal analogies
+ // For example: "Possible correct answers are: a, b, c, d."
+ str += Catalog.GetString (", ");
+ }
+ }
+
+ return String.Format (Catalog.GetString (
+ "Given the pair of words '{0}', which of the possible answers has the closest in relationship to the given pair? Answer {1}."),
+ current.question,
+ str);
+ }
+ }
+
+ public override void Initialize ()
+ {
+ if (analogies == null) {
+ analogies = AnalogiesFactory. Get (Analogy.Type.PairOfWordsOptions);
+ }
+
+ current = GetNext ();
+
+ if (current == null)
+ return;
+
+ right_answer = GetPossibleAnswer (current.right);
+ Console.WriteLine ("Name:" + Name + " " + current.ToString ());
+ }
+
+ public override void Draw (CairoContextEx gr, int area_width, int area_height)
+ {
+ double x = DrawAreaX, y = DrawAreaY + 0.1;
+
+ base.Draw (gr, area_width, area_height);
+
+ if (current == null || current.answers == null || current.answers.Length <= 1)
+ return;
+
+ gr.SetPangoLargeFontSize ();
+ gr.MoveTo (0.1, y);
+ gr.ShowPangoText (Catalog.GetString ("Possible answers are:"));
+ y += 0.12;
+ x += 0.1;
+ for (int n = 0; n < current.answers.Length; n++)
+ {
+ gr.MoveTo (x, y);
+ gr.ShowPangoText (String.Format ("{0}) {1}", GetPossibleAnswer (n), current.answers[n].ToString ()));
+ gr.Stroke ();
+ y += 0.15;
+ }
+ }
+}
diff --git a/src/VerbalAnalogies/AnalogiesQuestionAnswer.cs b/src/VerbalAnalogies/AnalogiesQuestionAnswer.cs
new file mode 100644
index 0000000..632dbee
--- /dev/null
+++ b/src/VerbalAnalogies/AnalogiesQuestionAnswer.cs
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2009 Jordi Mas i Hernà ndez <jmas softcatala org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+using System;
+using System.IO;
+using System.Collections.Generic;
+
+using Cairo;
+
+public class AnalogiesQuestionAnswer : Analogies
+{
+ static protected Dictionary <int, Analogy> analogies;
+ static protected ArrayListIndicesRandom analogies_indices;
+ static protected int analogies_index = 0;
+
+ public AnalogiesQuestionAnswer ()
+ {
+
+ }
+
+ public override string Name {
+ get { return "AnalogiesQuestionAnswer";}
+ }
+
+ public override ArrayListIndicesRandom Indices {
+ get { return analogies_indices; }
+ set { analogies_indices = value; }
+ }
+
+ public override int CurrentIndex {
+ get { return analogies_index; }
+ set { analogies_index = value; }
+ }
+
+ public override Dictionary <int, Analogy> List {
+ get { return analogies; }
+ }
+
+ public override void Initialize ()
+ {
+ if (analogies == null) {
+ analogies = AnalogiesFactory. Get (Analogy.Type.QuestionAnswer);
+ }
+
+ current = GetNext ();
+
+ if (current == null)
+ return;
+
+ right_answer = current.answers [current.right];
+ Console.WriteLine ("Name:" + Name + " " + current.ToString ());
+ }
+}
diff --git a/src/VerbalAnalogies/Analogy.cs b/src/VerbalAnalogies/Analogy.cs
new file mode 100644
index 0000000..217edb4
--- /dev/null
+++ b/src/VerbalAnalogies/Analogy.cs
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2009 Jordi Mas i Hernà ndez <jmas softcatala org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+using System;
+using System.Xml;
+using System.IO;
+using System.Collections.Generic;
+
+using Cairo;
+using Mono.Unix;
+using Gtk;
+
+public class Analogy
+{
+ public enum Type
+ {
+ QuestionAnswer = 0,
+ MultipleOptions,
+ PairOfWordsOptions,
+ PairOfWordsCompare,
+ Last
+ }
+
+ public string question;
+ public string [] answers;
+ public Type type;
+ public string tip;
+ public string rationale;
+ public int right;
+
+ public bool MultipleAnswers {
+ get {
+ string [] items = answers[right].Split ('|');
+
+ return items.Length > 1;
+ }
+ }
+
+ public override string ToString ()
+ {
+ string str = string.Empty;
+
+ str += String.Format ("Question: {0}\n", question);
+ str += String.Format ("Type: {0}\n", type);
+ str += String.Format ("Tip: {0}\n", tip);
+ str += String.Format ("Rational: {0}\n", rationale);
+ return str;
+ }
+
+ public Analogy ()
+ {
+
+ }
+}
+
+
diff --git a/src/gbrainy.cs b/src/gbrainy.cs
index 6ba15a3..c974b47 100644
--- a/src/gbrainy.cs
+++ b/src/gbrainy.cs
@@ -163,12 +163,11 @@ public class gbrainy: Program
Gtk.MenuItem item = new Gtk.MenuItem (Catalog.GetString ("Extensions"));
settings_menu.Append (item);
item.Activated += delegate (object sender, EventArgs ar) { Mono.Addins.Gui.AddinManagerWindow.Run (app_window);};
+ #endif
- item = new Gtk.MenuItem (Catalog.GetString ("Develop your own puzzles"));
+ item = new Gtk.MenuItem (Catalog.GetString ("How to Extend gbrainy's Functionality"));
help_menu.Prepend (item);
- item.Activated += delegate (object sender, EventArgs ar) { Process.Start ("http://live.gnome.org/gbrainy/Extensions");};
-
- #endif
+ item.Activated += delegate (object sender, EventArgs ar) { Process.Start ("http://live.gnome.org/gbrainy/Extending");};
drawing_vbox.Add (drawing_area);
app_window.IconName = "gbrainy";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]