28
28
namespace Simulacra
31
/// Given an ITextItem, WordnetAcion will look up the Text
32
/// contents of the ITextItem using the gnome-dictionary.
34
public class WordnetAction : Act
37
/// Should match those and only those strings that can be
38
/// looked up in a dictionary.
39
/// YES: "war", "peace", "hoi polloi"
40
/// NO: "war9", "2 + 4", "___1337__"
42
const string wordPattern = @"^([^\W0-9_]+([ -][^\W0-9_]+)?)$";
46
public WordnetAction ()
48
wordRegex = new Regex (wordPattern, RegexOptions.Compiled);
51
public override string Name {
52
get { return "Wordnet"; }
55
public override string Description
57
get { return "Get the Wordnet overview for the given word."; }
60
public override string Icon
62
get { return "accessories-dictionary"; }
65
public override IEnumerable<Type> SupportedItemTypes
75
/// Use wordRegex to determine whether item is definable.
77
/// <param name="item">
78
/// A <see cref="IItem"/> to define.
81
/// A <see cref="System.Boolean"/> indicating whether or not IITem
84
public override bool SupportsItem (Item item)
89
if (item is ITextItem) {
90
word = (item as ITextItem).Text;
92
return !string.IsNullOrEmpty (word) && wordRegex.IsMatch (word);
95
public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modifierItems)
98
foreach (Item item in items) {
99
if (item is ITextItem) {
100
word = (item as ITextItem).Text;
104
cmd = string.Format ("wnb \"{0}\"", word);
105
System.Diagnostics.Process.Start (cmd);
31
/// Given an ITextItem, WordnetAcion will look up the Text
32
/// contents of the ITextItem using the gnome-dictionary.
34
public class WordnetAction : Act
37
/// Should match those and only those strings that can be
38
/// looked up in a dictionary.
39
/// YES: "war", "peace", "hoi polloi"
40
/// NO: "war9", "2 + 4", "___1337__"
42
const string wordPattern = @"^([^\W0-9_]+([ -][^\W0-9_]+)?)$";
46
public WordnetAction ()
48
wordRegex = new Regex (wordPattern, RegexOptions.Compiled);
51
public override string Name {
52
get { return "Wordnet"; }
55
public override string Description
57
get { return "Get the Wordnet overview for the given word."; }
60
public override string Icon
62
get { return "accessories-dictionary"; }
65
public override IEnumerable<Type> SupportedItemTypes
67
get { return new Type[] { typeof (ITextItem) }; }
71
/// Use wordRegex to determine whether item is definable.
73
/// <param name="item">
74
/// A <see cref="IItem"/> to define.
77
/// A <see cref="System.Boolean"/> indicating whether or not IITem
80
public override bool SupportsItem (Item item)
85
if (item is ITextItem)
86
word = (item as ITextItem).Text;
88
return !string.IsNullOrEmpty (word) && wordRegex.IsMatch (word);
91
public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modifierItems)
93
foreach (Item item in items) {
94
if (!(item is ITextItem))
97
System.Diagnostics.Process.Start ("wnb", (item as ITextItem).Text);