~c-franke/do/XesamSearch

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
//
// Ontologies.cs : Translate between Xesam and Beagle ontologies
//
// Copyright (C) 2008 Christof Franke <c.franke@muenchen-mail.de> (Adding Ontos)
// Copyright (C) 2007 Arun Raghavan <arunissatan@gmail.com>
//

//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//

using System;
using System.Collections.Generic;

namespace Beagle {
	namespace Xesam {
		class Ontologies {
			private static Dictionary<string, string> fields_mapping;
			private static Dictionary<string, string> sources_mapping;
			private static Dictionary<string, string> contents_mapping;
			private static string[] fields_supported = null;
			private static string[] sources_supported = null;
			private static string[] contents_supported = null;

			static Ontologies ()
			{
				InitializeFieldsMapping ();
				InitializeSourcesMapping ();
				InitializeContentsMapping ();
			}

			private static void InitializeFieldsMapping ()
			{
				fields_mapping = new Dictionary<string, string> ();
				
				/////////////////////////////// Xesam-Standard
				fields_mapping.Add ("xesam:title", "beagle:Filename"); //fixme:title and dc:title mostly empty
				fields_mapping.Add ("xesam:author", "author");
				fields_mapping.Add ("xesam:fileSystemType", "beagle:FileType"); 
				fields_mapping.Add ("xesam:creator", "creator");
				fields_mapping.Add ("xesam:sourceModified", "date"); //modified date of all files, not only source
				fields_mapping.Add ("xesam:width", "fixme:width");	//for video files beagle has extra fields for width and heigt
				fields_mapping.Add ("xesam:height", "fixme:height"); //Xesam only supports on width, height field
				fields_mapping.Add ("xesam:pageCount", "fixme:page-count");
				fields_mapping.Add ("xesam:mimeType", "mimetype");
				fields_mapping.Add ("xesam:url", "uri");
				fields_mapping.Add ("xesam:fileExtension", "beagle:FilenameExtension");
				fields_mapping.Add ("xesam:from", "fixme:from_address"); //Email -Adress
				fields_mapping.Add ("xesam:to", "fixme:to_addr"); //Email-Asress
				fields_mapping.Add ("xesam:subject", "dc:title");
				fields_mapping.Add ("xesam:isRead", "fixme:isSeen");
			//	fields_mapping.Add ("xesam:title", "fixme:title");
				fields_mapping.Add ("xesam:artist", "fixme:artist");
				fields_mapping.Add ("xesam:ExactFilename", "beagle:ExactFilename");
				fields_mapping.Add ("xesam:videoCodec", "fixme:video:codec");
				//fields_mapping.Add ("xesam:creator", "creator");
				//fields_mapping.Add ("xesam:fileExtension", "beagle:FilenameExtension");
				
				////////////////////Beagle Special Ontos
				// !!! TODO: please change if there is xesam support  !!!
				fields_mapping.Add ("dc:title", "dc:title");
				fields_mapping.Add ("snippet", "snippetLine");
				fields_mapping.Add ("beagle:hitType", "beagle:HitType");
				fields_mapping.Add ("emblem", "nautilus:emblem");
				//fields_mapping.Add ("dc:author", "author");
				//fields_mapping.Add ("dc:date", "date");
				//fields_mapping.Add ("mime", "mimetype");
				//fields_mapping.Add ("uri", "uri");
				//fields_mapping.Add ("url", "uri");
				
				
				// Mail Ontologies  
				fields_mapping.Add ("beagle:from_name", "fixme:from_name");
				fields_mapping.Add ("beagle:from_addr", "fixme:from_address");
				fields_mapping.Add ("beagle:to_name", "fixme:to_name");
				fields_mapping.Add ("beagle:to_addr", "fixme:to_address");
				fields_mapping.Add ("beagle:isSent", "fixme:isSent");
				fields_mapping.Add ("beagle:isAnswered", "fixme:isAnswered");
				fields_mapping.Add ("beagle:folder", "fixme:folder");
				fields_mapping.Add ("beagle:client", "fixme:client");  
				fields_mapping.Add ("beagle:stock_mail-replied", "stock_mail-replied");
				fields_mapping.Add ("beagle:stock_mail-open", "stock_mail-open");
				fields_mapping.Add ("beagle:stock_mail", "stock_mail");
				 
				// Mail Attachment 
				fields_mapping.Add ("beagle:hasAttachments", "parent:fixme:hasAttachments");
				fields_mapping.Add ("beagle:attachment_title", "fixme:attachment_title");
				fields_mapping.Add ("beagle:parent:title", "parent:dc:title");
				
						
				// InstantMsgLogs Ontologies  
				//	Ive seen no Xesam support for IM -files  ; 
                //  !!! TODO: please change if there is support	!!!
				fields_mapping.Add ("beagle:speakingto", "fixme:speakingto");
				fields_mapping.Add ("beagle:starttime", "fixme:starttime");
				//fields_mapping.Add ("beagle:client", "fixme:client");
				fields_mapping.Add ("beagle:protocol", "fixme:protocol");
				fields_mapping.Add ("beagle:identity", "fixme:identity");
				fields_mapping.Add ("beagle:speakingto_alias", "fixme:speakingto_alias");
				fields_mapping.Add ("beagle:speakingto_icon", "fixme:speakingto_icon");
						
				// Calendar Ontologies
				//TODO: fixme:summary fixme:starttime fixme:description stock_calendar fixme:endtime fixme:location fixme:attendee
			}

			private static void InitializeSourcesMapping ()
			{
				sources_mapping = new Dictionary<string, string> ();

				sources_mapping.Add ("xesam:ArchivedFile", "filetype:archive");
				sources_mapping.Add ("xesam:File", "type:File");
				sources_mapping.Add ("xesam:MessageboxMessage","type:MailMessage");
			}

			private static void InitializeContentsMapping ()
			{
				contents_mapping = new Dictionary<string, string> ();

				contents_mapping.Add ("xesam:Archive", "filetype:archive");
				contents_mapping.Add ("xesam:Audio", "filetype:audio");
				contents_mapping.Add ("xesam:Bookmark", "type:Bookmark");
				contents_mapping.Add ("xesam:Contact", "type:Contact");
				contents_mapping.Add ("xesam:Document", "( filetype:document or filetype:documentation )");
				contents_mapping.Add ("xesam:Documentation", "filetype:documentation");
				contents_mapping.Add ("xesam:Email", "type:MailMessage");
				contents_mapping.Add ("xesam:IMMessage", "type:IMLog");
				contents_mapping.Add ("xesam:Image", "filetype:image");
				contents_mapping.Add ("xesam:Media", "( filetype:audio or filetype:video )");
				contents_mapping.Add ("xesam:Message", "( type:MailMessage or type:IMLog )");
				contents_mapping.Add ("xesam:RSSMessage", "type:FeedItem");
				contents_mapping.Add ("xesam:SourceCode", "filetype:source");
				contents_mapping.Add ("xesam:TextDocument", "filetype:document");
				contents_mapping.Add ("xesam:Video", "filetype:video");
				contents_mapping.Add ("xesam:Visual", "( filetype:image or filetype:video )");
				contents_mapping.Add ("xesam:Alarm", "type:Calendar");
				contents_mapping.Add ("xesam:Event", "type:Calendar");
				contents_mapping.Add ("xesam:FreeBusy", "type:Calendar");
				contents_mapping.Add ("xesam:Task", "type:Task");
			}

			public static string[] GetSupportedXesamFields ()
			{
				if (fields_supported == null) {
					List<string> ret = new List<string> ();

					foreach (string field in fields_mapping.Keys)
						ret.Add (field);

					fields_supported = ret.ToArray ();
				}

				return fields_supported;
			}

			public static string XesamToBeagleField (string xesamField) {
				if (fields_mapping.ContainsKey (xesamField))
					return fields_mapping [xesamField];
				else {
					Console.Error.WriteLine ("Unsupported field: {0}", xesamField);
					return xesamField.Replace (':', '-');
				}
			}

			public static string[] GetSupportedXesamSources ()
			{
				if (sources_supported == null) {
					List<string> ret = new List<string> ();

					foreach (string field in sources_mapping.Keys)
						ret.Add (field);

					sources_supported = ret.ToArray ();
				}

				return sources_supported;
			}

			public static string XesamToBeagleSource (string xesamSource)
			{
				if (sources_mapping.ContainsKey (xesamSource))
					return sources_mapping [xesamSource];
				else {
					Console.Error.WriteLine ("Unsupported source: {0}", xesamSource);
					return String.Empty;
				}
			}


			public static string[] GetSupportedXesamContents ()
			{
				if (contents_supported == null) {
					List<string> ret = new List<string> ();

					foreach (string field in contents_mapping.Keys)
						ret.Add (field);

					contents_supported = ret.ToArray ();
				}

				return contents_supported;
			}

			public static string XesamToBeagleContent (string xesamContent)
			{
				if (contents_mapping.ContainsKey (xesamContent))
					return contents_mapping [xesamContent];
				else {
					Console.Error.WriteLine ("Unsupported content type: {0}", xesamContent);
					return String.Empty;
				}
			}
		}
	}
}