ITagProvider



Hey, I was chatting with DBera last night at we got off on a random
little tangent, anyways, I remembered that I still hadn't shared any
of the code or my thoughts that had started to evolve as far as
supporting the idea of 'desktop tagging'.

I figured I would attach a copy of the patch that allows you to see
the current ITagProvider (unfortunety this is the majorly dumbed down
interface as I tried to get it integrated, once we have this worked
into the query system, I'll flesh out the API, and make my simple
sample threadsafe etc.)sketchup, I need to abstract or make an
interface for the Tag class, but I got far too tired last night after
my battle with Lucene.

DBera mentioned that the best place to implement this was probably
inside LuceneQueryDriver, since we are already merging 2 result sets
(the primary and secondary indexies) adding a third datasource
shouldn't be too hard, should it?

Either way, I tried a couple of things, and I've got a fair idea of
how the process works, I'm just still getting hung up on the different
BitArrays. It seems that as they are the ones holding all the results
sets, to merge results from the tagging backend at the lower level, I
need to figure those out. The other option is always to just build
hits from the tagged Uri's and drop any duplicates, but I'm not sure
thats how the response works.

Anyways, I'd love some feedback/help. This is just the core/super
simple implementation, once I figure out the results merging I'll add
back in the child tags, descriptions, etc.
-- 
Cheers,
Kevin Kubasik
http://kubasik.net/blog
=== added file 'Util/TagProvider.cs'
--- Util/TagProvider.cs	1970-01-01 00:00:00 +0000
+++ Util/TagProvider.cs	2007-09-28 07:29:55 +0000
@@ -0,0 +1,176 @@
+// TagProvider.cs - An interface used to pull tags from a variety of 
+//						sources.
+//
+// Copyright (C) 2007 Kevin Kubasik <kevin kubasik net>
+//
+// 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.IO;
+using System.Collections;
+using System.Collections.Generic;
+
+using Mono.Data.SqliteClient;
+//using ICSharpCode.SharpZipLib.GZip;
+
+
+namespace Beagle.Util
+{
+	
+	public interface ITagProvider{
+		Tag MakeNewTag(string s);
+		Tag GetTag(string s);
+		Tag[] SearchTags(string s);
+		Tag[] GetTagsForUri(string s);
+	}
+	public class Tag {
+		string name;
+		SqliteConnection connection = null;
+		public Tag (){
+			name = "";
+		}
+		public Tag(SqliteConnection conn){
+			connection = conn;
+			name= "";
+		}
+		public Tag(SqliteConnection conn, string argname){
+			connection = conn;
+			name = argname;
+		}
+		public String GetFirstUri(){
+			SqliteCommand scomm = new SqliteCommand(String.Format("select * from tags where tag='{0}' order by uri limit 1;",name),connection);
+			
+			SqliteDataReader sdr = scomm.ExecuteReader();
+			if(sdr.Read())
+				return sdr.GetString(0);
+			return null;
+		}
+		public String[] GetAllUri(){
+			List<string> l = new List<string>();
+			SqliteCommand scomm = new SqliteCommand(String.Format("select * from tags where tag='{0}' order by uri;",name),connection);
+			SqliteDataReader sdr =  scomm.ExecuteReader();
+			
+			while(sdr.Read()){
+				l.Add(sdr.GetString(0));
+			}
+			return l.ToArray();
+		}
+		public void AddUri(string s){
+			SqliteCommand scomm = new SqliteCommand(String.Format("insert into tags values ('{0}','{1}') ;",s,name),connection);
+			int i = scomm.ExecuteNonQuery();
+			
+		}
+		public void DeleteUri(string s){
+			SqliteCommand scomm = new SqliteCommand(String.Format(" delete from tags where tag='{1}' and uri='{0}' ;",s,name),connection);
+			int i = scomm.ExecuteNonQuery();
+		}
+		
+	}
+	
+	public class BeagleTagProvider : ITagProvider
+	{
+		string tag_file = null;
+		SqliteConnection connection = null;
+		
+		public BeagleTagProvider()
+		{
+			Init();
+		}
+		public virtual Beagle.Util.Tag GetTag (string s)
+		{
+			return new Tag(connection,s);
+		}
+
+		public virtual Beagle.Util.Tag[] GetTagsForUri (string s)
+		{
+			List<Tag> l = new List<Tag>();
+			SqliteCommand scomm = new SqliteCommand(String.Format("select * from tags where uri='{0}' order by tag;",s),connection);
+			SqliteDataReader sdr =  scomm.ExecuteReader();
+			
+			while(sdr.Read()){
+				l.Add(new Tag(connection,sdr.GetString(1)));
+			}
+			return l.ToArray();
+			//return new Tag[10];
+		}
+
+		public virtual Beagle.Util.Tag MakeNewTag (string s)
+		{
+			
+			return new Tag(connection,s);
+		}
+
+		public virtual Beagle.Util.Tag[] SearchTags (string s)
+		{
+			List<Tag> l = new List<Tag>();
+			SqliteCommand scomm = new SqliteCommand(String.Format("select * from tags where tag LIKE '%{0}%' order by tag;",s),connection);
+			SqliteDataReader sdr =  scomm.ExecuteReader();
+			
+			while(sdr.Read()){
+				l.Add(new Tag(connection,sdr.GetString(1)));
+			}
+			return l.ToArray();
+			//return new Tag[10];
+		}
+		
+		
+		private void Init(){
+			tag_file = Path.Combine(PathFinder.StorageDir, "beagletags.db");
+			if(!File.Exists(tag_file)){
+				File.Create(tag_file);
+				MakeTables();
+			}else {
+				try {
+					connection =  Open (tag_file);
+				} catch (Exception e) {
+					Log.Debug (e, "Exception opening tags {0}", tag_file);
+				}
+			}
+			
+		}
+		
+		private SqliteConnection Open (string db_filename)
+		{
+			SqliteConnection connection = new SqliteConnection ();
+			connection.ConnectionString = "version=" + ExternalStringsHack.SqliteVersion
+				+ ",encoding=UTF-8,URI=file:" + db_filename;
+			connection.Open ();
+			return connection;
+		}
+		private void MakeTables(){
+			try {
+					connection = Open (tag_file);
+				} catch (Exception e) {
+					Log.Debug (e, "Exception opening tags {0}", tag_file);
+				}
+			SqliteCommand scomm = new SqliteCommand("CREATE TABLE tags ( uri STRING NOT NULL, tag STRING NOT NULL);",connection);
+			scomm.ExecuteNonQuery();
+		}
+		
+		public static void Main(string[] args){
+			BeagleTagProvider btp = new BeagleTagProvider();
+			Tag t = btp.MakeNewTag("Tag");
+			t.AddUri("testmoreuri");
+			Console.WriteLine(t.GetFirstUri());
+			Console.WriteLine("Ran");
+		}
+	}
+}

=== modified file 'Util/Makefile.am'
--- Util/Makefile.am	2007-08-09 15:24:30 +0000
+++ Util/Makefile.am	2007-09-28 02:16:30 +0000
@@ -77,6 +77,7 @@
 	$(srcdir)/StringMatcher.cs		\
 	$(srcdir)/SystemInformation.cs		\
 	$(srcdir)/SystemPriorities.cs		\
+	$(srcdir)/TagProvider.cs	\
 	$(srcdir)/TeeTextWriter.cs		\
 	$(srcdir)/ThreadPond.cs			\
 	$(srcdir)/Timeline.cs			\

=== modified file 'beagled/PropertyKeywordFu.cs'
--- beagled/PropertyKeywordFu.cs	2007-02-18 22:23:47 +0000
+++ beagled/PropertyKeywordFu.cs	2007-09-28 07:21:19 +0000
@@ -124,6 +124,7 @@
 
 			property_table.Add ("filetype",
 					    new PropertyDetail (PropertyType.Keyword, "beagle:FileType", "Type of content for HitType File"));
+			property_table.Add("tag",new PropertyDetail(PropertyType.Text, "beagle:tag", "Tag of file"));
 		}
 
 		public static void RegisterMapping (PropertyKeywordMapping mapping)



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