beagle r4584 - trunk/beagle-xesam/src



Author: arunsr
Date: Thu Mar  6 18:23:10 2008
New Revision: 4584
URL: http://svn.gnome.org/viewvc/beagle?rev=4584&view=rev

Log:
Add support for 1:many mapping in ontologies (1 Xesam field : many Beagle fields). Major extension to list of supported fields included.


Modified:
   trunk/beagle-xesam/src/Ontologies.cs
   trunk/beagle-xesam/src/Parser.cs
   trunk/beagle-xesam/src/Search.cs

Modified: trunk/beagle-xesam/src/Ontologies.cs
==============================================================================
--- trunk/beagle-xesam/src/Ontologies.cs	(original)
+++ trunk/beagle-xesam/src/Ontologies.cs	Thu Mar  6 18:23:10 2008
@@ -30,7 +30,7 @@
 namespace Beagle {
 	namespace Xesam {
 		class Ontologies {
-			private static Dictionary<string, string> fields_mapping;
+			private static Dictionary<string, List<string>> fields_mapping;
 			private static Dictionary<string, string> sources_mapping;
 			private static Dictionary<string, string> contents_mapping;
 			private static string[] fields_supported = null;
@@ -44,37 +44,100 @@
 				InitializeContentsMapping ();
 			}
 
-			private static void InitializeFieldsMapping ()
+			static void AddField (string xesam_field, string beagle_field)
 			{
-				fields_mapping = new Dictionary<string, string> ();
-
-				fields_mapping.Add ("dc:title", "dc:title");
-				fields_mapping.Add ("xesam:title", "dc:title");
-
-				fields_mapping.Add ("dc:author", "dc:author");
-				fields_mapping.Add ("xesam:author", "dc:author");
-
-				fields_mapping.Add ("dc:creator", "dc:creator");
-				fields_mapping.Add ("xesam:creator", "dc:creator");
-
-				fields_mapping.Add ("dc:date", "date");
+				if (!fields_mapping.ContainsKey (xesam_field))
+					fields_mapping.Add (xesam_field, new List<string> ());
 
-				fields_mapping.Add ("xesam:width", "fixme:width");
-				fields_mapping.Add ("xesam:height", "fixme:height");
-
-				fields_mapping.Add ("xesam:pageCount", "fixme:page-count");
+				// This is O(n), but probably worth it since 'n' is small
+				if (!fields_mapping [xesam_field].Contains (beagle_field))
+					fields_mapping [xesam_field].Add (beagle_field);
+			}
 
-				fields_mapping.Add ("mime", "mimetype");
-				fields_mapping.Add ("xesam:mimeType", "mimetype");
+			private static void InitializeFieldsMapping ()
+			{
+				fields_mapping = new Dictionary<string, List<string>> ();
 
-				fields_mapping.Add ("uri", "uri");
-				fields_mapping.Add ("url", "uri");
-				fields_mapping.Add ("xesam:url", "uri");
+				// General fields
+				AddField ("dc:title", "dc:title");
+				AddField ("xesam:title", "dc:title");
+
+				// FIXME: "dc:author" is not valid Dublin Core
+				AddField ("dc:author", "dc:author");
+				AddField ("xesam:author", "dc:author");
+				AddField ("xesam:author", "dc:creator");
+
+				AddField ("dc:creator", "dc:creator");
+				AddField ("xesam:creator", "dc:creator");
+
+				AddField ("dc:date", "date");
+				AddField ("xesam:sourceModified", "date");
+
+				AddField ("mime", "mimetype");
+				AddField ("xesam:mimeType", "mimetype");
+
+				AddField ("uri", "uri");
+				AddField ("url", "uri");
+				AddField ("xesam:url", "uri");
+
+				// File fields
+				AddField ("xesam:name", "beagle:ExactFilename");
+				AddField ("xesam:fileExtension", "beagle:FilenameExtension");
+				AddField ("xesam:storageSize", "fixme:filesize");
+
+				// Document fields
+				AddField ("xesam:wordCount", "fixme:word-count");
+				AddField ("xesam:pageCount", "fixme:page-count");
+
+				// EMail fields
+				AddField ("xesam:subject", "dc:title");
+				AddField ("xesam:author", "fixme:from");
+				AddField ("xesam:to", "fixme:to");
+				AddField ("xesam:cc", "fixme:cc");
+				AddField ("xesam:id", "fixme:msgid");
+				AddField ("xesam:mailingList", "fixme:mlist");
+				// FIXME: BCC fields seem to be ignored by the filters
+				//AddField ("xesam:bcc", "fixme:bcc");
+
+				// Image fields
+				AddField ("xesam:width", "fixme:width");
+				AddField ("xesam:height", "fixme:height");
+				AddField ("xesam:pixelDataBitDepth", "fixme:depth");
+
+				// Audio (and Video) fields
+				AddField ("xesam:album", "fixme:album");
+				AddField ("xesam:artist", "fixme:artist");
+				AddField ("xesam:composer", "fixme:composer");
+				AddField ("xesam:performer", "fixme:performer");
+				AddField ("xesam:genre", "fixme:genre");
+				AddField ("xesam:trackNumber", "fixme:tracknumber");
+				AddField ("xesam:trackCount", "fixme:trackcount");
+				AddField ("xesam:discNumber", "fixme:discnumber");
+				// xesam doesn't have this yet
+				//AddField ("xesam:discCount", "fixme:disccount");
+				AddField ("xesam:audioBitrate", "fixme:bitrate");
+				AddField ("xesam:audioChannels", "fixme:channels");
+				AddField ("xesam:audioSampleRate", "fixme:samplerate");
+				AddField ("xesam:mediaDuration", "fixme:duration");
+				AddField ("xesam:comment", "fixme:comment");
+
+				// Video feilds
+				AddField ("xesam:audioCodec", "fixme:audio:codec");
+				AddField ("xesam:audioBitrate", "fixme:audio:bitrate");
+				AddField ("xesam:audioSampleRate", "fixme:audio:samplerate");
+				AddField ("xesam:videoCodec", "fixme:video:codec");
+				AddField ("xesam:frameRate", "fixme:fps");
+				AddField ("xesam:height", "fixme:video:height");
+				AddField ("xesam:width", "fixme:video:width");
+
+				// HTML fields
+				// FIXME: This only works with HTML with <meta> tags. What about other sources?
+				AddField ("xesam:generator", "meta:generator");
+				AddField ("xesam:description", "meta:description");
 
-				fields_mapping.Add ("xesam:fileExtension", "beagle:FilenameExtension");
-				fields_mapping.Add ("fileExtension", "beagle:FilenameExtension");
+				AddField ("xesam:remoteServer", "fixme:host");
 
-				fields_mapping.Add ("snippet", "snippet");
+				AddField ("snippet", "snippet");
 			}
 
 			private static void InitializeSourcesMapping ()
@@ -83,6 +146,7 @@
 
 				sources_mapping.Add ("xesam:ArchivedFile", "filetype:archive");
 				sources_mapping.Add ("xesam:File", "type:File");
+				sources_mapping.Add ("xesam:Filelike", "type:File");
 				sources_mapping.Add ("xesam:MessageboxMessage","type:MailMessage");
 			}
 
@@ -126,12 +190,12 @@
 				return fields_supported;
 			}
 
-			public static string XesamToBeagleField (string xesamField) {
+			public static string[] XesamToBeagleField (string xesamField) {
 				if (fields_mapping.ContainsKey (xesamField))
-					return fields_mapping [xesamField];
+					return fields_mapping [xesamField].ToArray();
 				else {
 					Console.Error.WriteLine ("Unsupported field: {0}", xesamField);
-					return xesamField.Replace (':', '-');
+					return new string[] { "property:" + xesamField };
 				}
 			}
 

Modified: trunk/beagle-xesam/src/Parser.cs
==============================================================================
--- trunk/beagle-xesam/src/Parser.cs	(original)
+++ trunk/beagle-xesam/src/Parser.cs	Thu Mar  6 18:23:10 2008
@@ -86,7 +86,8 @@
 			private static string ParseXesamField (XPathNavigator nav)
 			{
 				string field = nav.GetAttribute ("name", String.Empty);
-				field = Ontologies.XesamToBeagleField (field);
+				// FIXME: Using just the first field is NOT correct
+				field = Ontologies.XesamToBeagleField (field)[0];
 
 				if (field.Contains (":")) {
 					field = "property:" + field;

Modified: trunk/beagle-xesam/src/Search.cs
==============================================================================
--- trunk/beagle-xesam/src/Search.cs	(original)
+++ trunk/beagle-xesam/src/Search.cs	Thu Mar  6 18:23:10 2008
@@ -65,7 +65,9 @@
 				foreach (string field in fields) {
 					// We add String.Empty to attributes because they may be null and we cannot
 					// return null objects over DBus
-					switch (Ontologies.XesamToBeagleField (field)) {
+					string[] bfields = Ontologies.XesamToBeagleField (field);
+
+					switch (bfields [0]) {
 					case "uri":
 						hitValue [i++] = hit.Uri.ToString ();
 						break;
@@ -88,15 +90,25 @@
 						// FIXME: This *will* break since we don't know what the expected
 						// type here is, and we're always using strings
 						
-						string[] prop = hit.GetProperties (Ontologies.XesamToBeagleField (field));
-						if (prop != null) {
-							if (prop.Length == 1)
-								hitValue [i++] = prop [0];
-							else
-								hitValue [i++] = prop;
-						} else {
-							hitValue [i++] = String.Empty;
+						List<string> values = new List<string> ();
+
+						foreach (string bfield in bfields) {
+							string[] prop = hit.GetProperties (bfield);
+
+							if (prop != null)
+								values.AddRange (prop);
 						}
+
+						if (values.Count == 0)
+							// No values found
+							hitValue [i++] = String.Empty;
+						else if (values.Count == 1)
+							// Only one value -- return as string
+							hitValue [i++] = values [0];
+						else
+							// Multiple values -- returns as string[]
+							hitValue [i++] = values.ToArray ();
+
 						break;
 					}
 				}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]