3
* GNOME Do is the legal property of its developers. Please refer to the
4
* COPYRIGHT file distributed with this source distribution.
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
* WordnetAction is just a slight modification of DefineWordAction, to use
20
* Wordnet instead of the default dictionary.
24
using System.Collections.Generic;
25
using System.Text.RegularExpressions;
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);