beagle r4587 - in branches/beagle-rdf/Util: . SemWeb



Author: dbera
Date: Fri Mar  7 03:37:19 2008
New Revision: 4587
URL: http://svn.gnome.org/viewvc/beagle?rev=4587&view=rev

Log:
Upgrade to SemWeb 1.3.0


Modified:
   branches/beagle-rdf/Util/Makefile.am
   branches/beagle-rdf/Util/SemWeb/AssemblyInfo.cs
   branches/beagle-rdf/Util/SemWeb/GraphMatch.cs
   branches/beagle-rdf/Util/SemWeb/LiteralFilters.cs
   branches/beagle-rdf/Util/SemWeb/N3Reader.cs
   branches/beagle-rdf/Util/SemWeb/N3Writer.cs
   branches/beagle-rdf/Util/SemWeb/RdfWriter.cs
   branches/beagle-rdf/Util/SemWeb/Resource.cs
   branches/beagle-rdf/Util/SemWeb/SQLStore.cs
   branches/beagle-rdf/Util/SemWeb/Store.cs

Modified: branches/beagle-rdf/Util/Makefile.am
==============================================================================
--- branches/beagle-rdf/Util/Makefile.am	(original)
+++ branches/beagle-rdf/Util/Makefile.am	Fri Mar  7 03:37:19 2008
@@ -122,7 +122,6 @@
 	$(srcdir)/Hal/SystemPowerManagement.cs	\
 	$(srcdir)/Hal/Volume.cs			\
 	$(srcdir)/Hal/VolumeCrypto.cs		\
-	$(srcdir)/SemWeb/AssemblyInfo.cs        \
 	$(srcdir)/SemWeb/NamespaceManager.cs    \
 	$(srcdir)/SemWeb/Util.cs                \
 	$(srcdir)/SemWeb/UriMap.cs              \

Modified: branches/beagle-rdf/Util/SemWeb/AssemblyInfo.cs
==============================================================================
--- branches/beagle-rdf/Util/SemWeb/AssemblyInfo.cs	(original)
+++ branches/beagle-rdf/Util/SemWeb/AssemblyInfo.cs	Fri Mar  7 03:37:19 2008
@@ -6,11 +6,11 @@
 [assembly: AssemblyConfiguration("")]
 [assembly: AssemblyCompany("")]
 [assembly: AssemblyProduct("")]
-[assembly: AssemblyCopyright("Copyright (c) 2007 Joshua Tauberer <http://razor.occams.info>")]
+[assembly: AssemblyCopyright("Copyright (c) 2008 Joshua Tauberer <http://razor.occams.info>")]
 [assembly: AssemblyTrademark("")]
 [assembly: AssemblyCulture("")]		
 
-[assembly: AssemblyVersion("1.0.2.1")]
+[assembly: AssemblyVersion("1.0.3.0")]
 [assembly: AssemblyDelaySign(false)]
 [assembly: AssemblyKeyFile("")]
 [assembly: AssemblyKeyName("")]

Modified: branches/beagle-rdf/Util/SemWeb/GraphMatch.cs
==============================================================================
--- branches/beagle-rdf/Util/SemWeb/GraphMatch.cs	(original)
+++ branches/beagle-rdf/Util/SemWeb/GraphMatch.cs	Fri Mar  7 03:37:19 2008
@@ -407,7 +407,7 @@
 					foreach (Statement s in part.Graph)
 						qs += "\n\t" + s;
 
-					result.AddComments("QUERY: " + qs + "  => " + matches.Count);
+					result.AddComments("QUERY: " + qs + (returnLimit > 0 ? " [limit " + returnLimit + "/" + localLimit + "]" : "") + "  => " + matches.Count);
 					
 					// If we got back at least as many rows as our local (adaptive) limit,
 					// then we know that the limiting (possibly) had an effect and we may
@@ -417,26 +417,59 @@
 				}
 				
 				// Intersect the existing bindings with the new matches.
-				
-				// get a list of variables the old and new have in common
+				// This involves creating binding rows that:
+				//    Match on the intersection of variables from the two sets
+				//    But include only interestingVariables variables, which
+				//    are distinguished variables plus any variables we will
+				//    encounter in later parts of the query
+				
+				// Get a list of variables the old and new have in common, and
+				// a list for the common variables of their indexes in the old
+				// and new sets
 				int nCommonVars;
 				int[,] commonVars = IntersectVariables(bindings.Variables, vars, out nCommonVars);
 				
-				BindingSet newbindings = new BindingSet();
+				ResSet retainedVariables = null;
+				if (interestingVariables != null) {
+					retainedVariables = new ResSet();
+					foreach (Variable v in bindings.Variables)
+						if (interestingVariables.Contains(v))
+							retainedVariables.Add(v);
+					foreach (Variable v in vars)
+						if (interestingVariables.Contains(v))
+							retainedVariables.Add(v);
+				}
 				
-				newbindings.Variables = new Variable[bindings.Variables.Length + vars.Length - nCommonVars];
-				bindings.Variables.CopyTo(newbindings.Variables, 0);
-				int ctr = bindings.Variables.Length;
-				int[] newindexes = new int[vars.Length];
-				for (int i = 0; i < vars.Length; i++) {
-					if (Array.IndexOf(newbindings.Variables, vars[i]) == -1) {
-						newbindings.Variables[ctr] = vars[i];
-						newindexes[i] = ctr;
-						ctr++;
+				BindingSet newbindings = new BindingSet();
+				if (retainedVariables == null)
+					newbindings.Variables = new Variable[bindings.Variables.Length + vars.Length - nCommonVars];
+				else
+					newbindings.Variables = new Variable[retainedVariables.Count];
+				
+				// Make a list of the variables in the final set, and a mapping
+				// from indexes in the old/new set to indexes in the final set.
+				int ctr = 0;
+				int[] variableMapLeft = new int[bindings.Variables.Length];
+				for (int i = 0; i < variableMapLeft.Length; i++) {
+					if (retainedVariables == null || retainedVariables.Contains(bindings.Variables[i])) {
+						variableMapLeft[i] = ctr;
+						newbindings.Variables[ctr++] = bindings.Variables[i];
+					} else {
+						variableMapLeft[i] = -1;
+					}
+				}
+
+				int[] variableMapRight = new int[vars.Length];
+				for (int i = 0; i < variableMapRight.Length; i++) {
+					if ((retainedVariables == null || retainedVariables.Contains(vars[i]))
+						&& Array.IndexOf(newbindings.Variables, vars[i]) == -1) {
+						variableMapRight[i] = ctr;
+						newbindings.Variables[ctr++] = vars[i];
 					} else {
-						newindexes[i] = -1;
+						variableMapRight[i] = -1;
 					}
 				}
+				
 				newbindings.Rows = new BindingList();
 				
 				int nMatches = 0;
@@ -448,12 +481,10 @@
 							VariableBindings right = (VariableBindings)matches[i];
 							
 							Resource[] newValues = new Resource[newbindings.Variables.Length];
-							if (left != null) // null on first intersection
-								left.Values.CopyTo(newValues, 0);
-							right.Values.CopyTo(newValues, bindings.Variables.Length);
+							CopyValues(left == null ? null : left.Values, right.Values, newValues, variableMapLeft, variableMapRight);
 							
 							nMatches++;
-							if (!quickDupCheckIsDup(newbindings, newValues, nMatches, interestingVariables))
+							if (!quickDupCheckIsDup(newbindings, newValues, nMatches))
 								newbindings.Rows.Add(new VariableBindings(newbindings.Variables, newValues));
 						}
 					}
@@ -504,13 +535,10 @@
 							VariableBindings right = (VariableBindings)list[i];
 							
 							Resource[] newValues = new Resource[newbindings.Variables.Length];
-							left.Values.CopyTo(newValues, 0);
-							for (int j = 0; j < newindexes.Length; j++)
-								if (newindexes[j] != -1)
-									newValues[newindexes[j]] = right.Values[j];
+							CopyValues(left.Values, right.Values, newValues, variableMapLeft, variableMapRight);
 
 							nMatches++;
-							if (!quickDupCheckIsDup(newbindings, newValues, nMatches, interestingVariables))
+							if (!quickDupCheckIsDup(newbindings, newValues, nMatches))
 								newbindings.Rows.Add(new VariableBindings(newbindings.Variables, newValues));
 						}
 					}
@@ -540,7 +568,7 @@
 			if (!adaptiveLimitDidLimit) break;
 			
 			// Increase the adaptive limit multiplier for next time.
-			adaptiveLimitMultiplier *= 3;
+			adaptiveLimitMultiplier *= 5;
 			
 			} // end of adaptive limiting
 			
@@ -610,8 +638,21 @@
 			nCommonVars = commonVars.Count;
 			return ret;
 		}
+
+		#if !DOTNET2
+		static void CopyValues(Resource[] left, Resource[] right, Resource[] newValues, int[] variableMapLeft, int[] variableMapRight) {
+		#else
+		static void CopyValues(IList<Resource> left, IList<Resource> right, Resource[] newValues, int[] variableMapLeft, int[] variableMapRight) {
+		#endif
+			for (int i = 0; i < variableMapLeft.Length; i++)
+				if (variableMapLeft[i] != -1)
+					newValues[variableMapLeft[i]] = left[i];
+			for (int i = 0; i < variableMapRight.Length; i++)
+				if (variableMapRight[i] != -1)
+					newValues[variableMapRight[i]] = right[i];
+		}
 		
-		static bool quickDupCheckIsDup(BindingSet newbindings, Resource[] newValues, int nMatches, ResSet interestingVariables) {
+		static bool quickDupCheckIsDup(BindingSet newbindings, Resource[] newValues, int nMatches) {
 			// If there is a more than 10-to-1 ratio of rejected duplicates
 			// to unique rows, then we check all rows.  Otherwise we check the first 100.
 
@@ -620,7 +661,6 @@
 				if (i > 100 && !isHighRejectRatio) break;
 				bool dup = true;
 				for (int j = 0; j < newValues.Length; j++) {
-					if (interestingVariables != null && !interestingVariables.Contains(newbindings.Variables[j])) continue;
 					Resource left = ((VariableBindings)newbindings.Rows[i]).Values[j];
 					Resource right = newValues[j];
 					if ((object)left == null || (object)right == null) {

Modified: branches/beagle-rdf/Util/SemWeb/LiteralFilters.cs
==============================================================================
--- branches/beagle-rdf/Util/SemWeb/LiteralFilters.cs	(original)
+++ branches/beagle-rdf/Util/SemWeb/LiteralFilters.cs	Fri Mar  7 03:37:19 2008
@@ -110,6 +110,17 @@
 		}
 	}
 
+	public class StringEndsWithFilter : LiteralFilter {
+		public readonly string Pattern;
+		public StringEndsWithFilter(string pattern) {
+			Pattern = pattern;
+		}
+		public override bool Filter(Literal resource, SelectableSource targetModel) {
+			string v = resource.Value;
+			return v.EndsWith(Pattern);
+		}
+	}
+
 	public class NumericCompareFilter : LiteralFilter {
 		public readonly Decimal Number;
 		public readonly CompType Type;

Modified: branches/beagle-rdf/Util/SemWeb/N3Reader.cs
==============================================================================
--- branches/beagle-rdf/Util/SemWeb/N3Reader.cs	(original)
+++ branches/beagle-rdf/Util/SemWeb/N3Reader.cs	Fri Mar  7 03:37:19 2008
@@ -65,8 +65,8 @@
 		private bool ReadStatement(ParseContext context) {
 			Location loc = context.Location;
 			
-			bool reverse;
-			Resource subject = ReadResource(context, true, out reverse);
+			bool reverse, forgetBNode;
+			Resource subject = ReadResource(context, true, out reverse, out forgetBNode);
 			if (subject == null) return false;
 			if (reverse) OnError("is...of not allowed on a subject", loc);
 			
@@ -76,7 +76,8 @@
 				if (qname == null || !qname.EndsWith(":")) OnError("When using @prefix, the prefix identifier must end with a colon", loc);
 				
 				loc = context.Location;
-				Resource uri = ReadResource(context, false, out reverse);
+				bool fb2;
+				Resource uri = ReadResource(context, false, out reverse, out fb2);
 				if (uri == null) OnError("Expecting a URI", loc);
 				if (reverse) OnError("is...of not allowed here", loc);
 				namespaces.AddNamespace(uri.Uri, qname.Substring(0, qname.Length-1));
@@ -110,7 +111,8 @@
 			
 			if ((object)subject == (object)BaseResource) {
 				loc = context.Location;
-				Resource uri = ReadResource(context, false, out reverse);
+				bool fb2;
+				Resource uri = ReadResource(context, false, out reverse, out fb2);
 				if (uri == null || uri.Uri == null) OnError("Expecting a URI", loc);
 				if (reverse) OnError("is...of not allowed here", loc);
 				BaseUri = uri.Uri;
@@ -127,10 +129,12 @@
 			// a reified context.
 			if (NextPunc(context.source) == '.') {
 				context.source.Read();
+				if (forgetBNode) DoForget(subject, context);
 				return true;
 			}
 			if (NextPunc(context.source) == '}') {
 				context.source.Read();
+				if (forgetBNode) DoForget(subject, context);
 				return false; // end of block
 			}
 			
@@ -140,6 +144,7 @@
 			if (period != '.' && period != '}')
 				OnError("Expected a period but found '" + period + "'", loc);
 			if (period == '}') return false;
+			if (forgetBNode) DoForget(subject, context);
 			return true;
 		}
 		
@@ -161,9 +166,9 @@
 		}
 		
 		private char ReadPredicate(Resource subject, ParseContext context) {
-			bool reverse;
+			bool reverse, forgetBNode;
 			Location loc = context.Location;
-			Resource predicate = ReadResource(context, false, out reverse);
+			Resource predicate = ReadResource(context, false, out reverse, out forgetBNode);
 			if (predicate == null) OnError("Expecting a predicate", loc);
 			if (predicate is Literal) OnError("Predicates cannot be literals", loc);
 			
@@ -182,13 +187,15 @@
 			if (punctuation != '.' && punctuation != ';' && punctuation != ']' && punctuation != '}')
 				OnError("Expecting a period, semicolon, comma, close-bracket, or close-brace but found '" + punctuation + "'", loc);
 			
+			if (forgetBNode) DoForget(predicate, context);
+			
 			return punctuation;
 		}
 		
 		private void ReadObject(Resource subject, Entity predicate, ParseContext context, bool reverse) {
-			bool reverse2;
+			bool reverse2, forgetBNode;
 			Location loc = context.Location;
-			Resource value = ReadResource(context, false, out reverse2);
+			Resource value = ReadResource(context, false, out reverse2, out forgetBNode);
 			if (value == null) OnError("Expecting a resource or literal object", loc);
 			if (reverse2) OnError("is...of not allowed on objects", loc);
 			
@@ -202,6 +209,8 @@
 				if (value is Literal) OnError("A literal cannot be the object of a reverse-predicate statement", loc);
 				Add(context.store, new Statement((Entity)value, predicate, subject, context.meta), loc);
 			}
+
+			if (forgetBNode) DoForget(value, context);
 		}
 		
 		private void ReadWhitespace(MyReader source) {
@@ -379,7 +388,7 @@
 				// A variable: \?[a-zA-Z_][a-zA-Z0-9_]*
 				while (true) {
 					int c = source.Peek();
-					if (c == -1 || (!char.IsLetterOrDigit((char)c) && c != '-' && c != '_' && c != ':')) break;					
+					if (c == -1 || (!Entity.ValidateUriIsIUnreserved((char)c) && c != ':') || c == '.') break;
 					b.Append((char)source.Read());
 				}
 			
@@ -433,18 +442,18 @@
 			return b.ToString();
 		}
 		
-		private Resource ReadResource(ParseContext context, bool allowDirective, out bool reverse) {
+		private Resource ReadResource(ParseContext context, bool allowDirective, out bool reverse, out bool forgetBNode) {
 			Location loc = context.Location;
 			
-			Resource res = ReadResource2(context, allowDirective, out reverse);
+			Resource res = ReadResource2(context, allowDirective, out reverse, out forgetBNode);
 			
 			ReadWhitespace(context.source);
 			while (context.source.Peek() == '!' || context.source.Peek() == '^' || (context.source.Peek() == '.' && context.source.Peek2() != -1 && char.IsLetter((char)context.source.Peek2())) ) {
 				int pathType = context.source.Read();
 				
-				bool reverse2;
+				bool reverse2, forgetBNode2;
 				loc = context.Location;
-				Resource path = ReadResource2(context, false, out reverse2);
+				Resource path = ReadResource2(context, false, out reverse2, out forgetBNode2);
 				if (reverse || reverse2) OnError("is...of is not allowed in path expressions", loc);
 				if (!(path is Entity)) OnError("A path expression cannot be a literal", loc);
 				
@@ -460,7 +469,11 @@
 				
 				Add(context.store, s, loc);
 				
+				if (forgetBNode) DoForget(res, context);
+				if (forgetBNode2) DoForget(path, context);
+				
 				res = anon;
+				forgetBNode = true;
 
 				ReadWhitespace(context.source);
 			}
@@ -501,8 +514,9 @@
 			}
 		}
 			
-		private Resource ReadResource2(ParseContext context, bool allowDirective, out bool reverse) {
+		private Resource ReadResource2(ParseContext context, bool allowDirective, out bool reverse, out bool forgetBNode) {
 			reverse = false;
+			forgetBNode = false;
 			
 			Location loc = context.Location;
 			
@@ -563,12 +577,12 @@
 				return entGRAPHCONTAINS;
 
 			if (str == "@has") // ignore this token
-				return ReadResource2(context, false, out reverse);
+				return ReadResource2(context, false, out reverse, out forgetBNode);
 			
 			if (str == "@is") {
 				// Reverse predicate
 				bool reversetemp;
-				Resource pred = ReadResource2(context, false, out reversetemp);
+				Resource pred = ReadResource2(context, false, out reversetemp, out forgetBNode);
 				reverse = true;
 				
 				string of = ReadToken(context.source, context) as string;
@@ -626,6 +640,7 @@
 				} else {
 					context.source.Read();
 				}
+				forgetBNode = true;
 				return ret;
 			}
 			
@@ -635,15 +650,14 @@
 				// A list
 				Entity head = null, ent = null;
 				while (true) {
-					bool rev2;
-					Resource res = ReadResource(context, false, out rev2);
+					bool rev2, fb2;
+					Resource res = ReadResource(context, false, out rev2, out fb2);
 					if (res == null)
 						break;
 					
 					if (ent == null) {
 						ent = new BNode();
-						if (head == null)
-							head = ent;
+						head = ent;
 					} else {
 						Entity sub = new BNode();
 						Add(context.store, new Statement(ent, entRDFREST, sub, context.meta), loc);
@@ -651,9 +665,10 @@
 					}
 					
 					Add(context.store, new Statement(ent, entRDFFIRST, res, context.meta), loc);
+					if (fb2) DoForget(res, context);
 				}
-				if (ent == null) // No list items.
-					ent = entRDFNIL; // according to Turtle spec
+				if (head == null) // No list items.
+					head = entRDFNIL; // according to Turtle spec
 				else
 					Add(context.store, new Statement(ent, entRDFREST, entRDFNIL, context.meta), loc);
 				
@@ -699,6 +714,12 @@
 					return new Literal(numval.ToString(), null, NS.XMLSCHEMA + "double");
 			}
 			
+			//BOOLEAN LITERAL
+			
+			if (str == "true" || str == "false") {
+			  return new Literal(str,null,NS.XMLSCHEMA+"boolean");
+			}
+			
 			// If @keywords is used, alphanumerics that aren't keywords
 			// are local names in the default namespace.
 			if (context.UsingKeywords && char.IsLetter(str[0])) {
@@ -730,7 +751,11 @@
 			OnWarning(message + ", line " + position.Line + " col " + position.Col);
 		}*/
 		
-	
+		void DoForget(Resource ent, ParseContext context) {
+			CanForgetBNodes x = context.store as CanForgetBNodes;
+			if (x == null) return;
+			x.ForgetBNode((BNode)ent);
+		}
 	}
 
 	internal class MyReader {
@@ -778,6 +803,7 @@
 			
 			return c;
 		}
+		
 	}
 
 	internal struct Location {

Modified: branches/beagle-rdf/Util/SemWeb/N3Writer.cs
==============================================================================
--- branches/beagle-rdf/Util/SemWeb/N3Writer.cs	(original)
+++ branches/beagle-rdf/Util/SemWeb/N3Writer.cs	Fri Mar  7 03:37:19 2008
@@ -6,7 +6,7 @@
 using SemWeb;
 
 namespace SemWeb {
-	public class N3Writer : RdfWriter {
+	public class N3Writer : RdfWriter, CanForgetBNodes {
 		TextWriter writer;
 		NamespaceManager2 ns = new NamespaceManager2();
 		bool hasWritten = false;
@@ -233,5 +233,10 @@
 				addedPrefixes.Add(prefix);
 			}
 		}
+		
+		void CanForgetBNodes.ForgetBNode(BNode bnode) {
+			anonNames.Remove(bnode);
+			anonNameMap.Remove(bnode);
+		}
 	}
 }

Modified: branches/beagle-rdf/Util/SemWeb/RdfWriter.cs
==============================================================================
--- branches/beagle-rdf/Util/SemWeb/RdfWriter.cs	(original)
+++ branches/beagle-rdf/Util/SemWeb/RdfWriter.cs	Fri Mar  7 03:37:19 2008
@@ -82,4 +82,8 @@
 			}
 		}
 	}
+	
+	public interface CanForgetBNodes {
+		void ForgetBNode(BNode bnode);
+	}
 }

Modified: branches/beagle-rdf/Util/SemWeb/Resource.cs
==============================================================================
--- branches/beagle-rdf/Util/SemWeb/Resource.cs	(original)
+++ branches/beagle-rdf/Util/SemWeb/Resource.cs	Fri Mar  7 03:37:19 2008
@@ -343,7 +343,7 @@
 		private static bool ValidateUriIsDigit(char c) {
 			return c >= 0x30 && c <= 0x39;
 		}
-		private static bool ValidateUriIsIUnreserved(char c) {
+		internal static bool ValidateUriIsIUnreserved(char c) {
 			return ValidateUriIsAlpha(c) || ValidateUriIsDigit(c) || c == '-' || c == '.' || c == '_' || c == '~'
 				|| (c >= 0xA0 && c <= 0xD7FF) || (c >= 0xF900 && c <= 0xFDCF) || (c >= 0xFDF0 && c <= 0xFFEF); // ucschar
 		}

Modified: branches/beagle-rdf/Util/SemWeb/SQLStore.cs
==============================================================================
--- branches/beagle-rdf/Util/SemWeb/SQLStore.cs	(original)
+++ branches/beagle-rdf/Util/SemWeb/SQLStore.cs	Fri Mar  7 03:37:19 2008
@@ -188,6 +188,7 @@
 		
 		protected abstract void CreateNullTest(string column, System.Text.StringBuilder command);
 		protected abstract void CreateLikeTest(string column, string prefix, int method, System.Text.StringBuilder command);
+			// method: 0 == startswith, 1 == contains, 2 == ends with
 		
 		protected virtual bool CreateEntityPrefixTest(string column, string prefix, System.Text.StringBuilder command) {
 			command.Append('(');
@@ -911,6 +912,7 @@
 				
 				int id = GetResourceId(r, false);
 				if (id == 0) return false;
+				if (Debug) Console.Error.WriteLine("(" + id + " " + r + ")");
 				cmd.Append('(');
 				cmd.Append(col);
 				cmd.Append('=');
@@ -1135,11 +1137,16 @@
 		}
 		
 		void PrefetchResourceIds(IList resources) {
+			Hashtable seen_e = new Hashtable();
+			Hashtable seen_l = new Hashtable();
+			
+			int resStart = 0;
+			while (resStart < resources.Count) {
+
 			StringBuilder cmd_e = new StringBuilder();
 			cmd_e.Append("SELECT id, value FROM ");
 			cmd_e.Append(table);
 			cmd_e.Append("_entities WHERE value IN (");
-			Hashtable seen_e = new Hashtable();
 			bool hasEnts = false;
 
 			StringBuilder cmd_l = new StringBuilder();
@@ -1147,11 +1154,15 @@
 			cmd_l.Append(table);
 			cmd_l.Append("_literals WHERE hash IN (");
 			bool hasLiterals = false;
-			Hashtable seen_l = new Hashtable();
 
-			foreach (Resource r in resources) {
+			int ctr = 0;
+			while (resStart < resources.Count && ctr < 1000) {
+				Resource r = (Resource)resources[resStart++];
+				
 				if ((object)r == (object)Statement.DefaultMeta || GetResourceKey(r) != null) // no need to prefetch
 					continue;
+					
+				ctr++;
 			
 				if (r.Uri != null) {
 					if (seen_e.ContainsKey(r.Uri)) continue;
@@ -1198,6 +1209,8 @@
 					}
 				}
 			}
+			
+			}
 		}
 		
 		public void Select(Statement template, StatementSink result) {
@@ -1514,7 +1527,12 @@
 							int vIndex = varRef_Inner.Count;
 							varRef2[v] = vIndex;
 							
-							if (distinguishedVars.Contains(v)) {
+							#if !DOTNET2
+							bool hasLitFilter = (options.VariableLiteralFilters != null && options.VariableLiteralFilters[v] != null);
+							#else
+							bool hasLitFilter = (options.VariableLiteralFilters != null && options.VariableLiteralFilters.ContainsKey(v));
+							#endif
+							if (distinguishedVars.Contains(v) || hasLitFilter) {
 								StringBuilder joinTarget = fromClause;
 								if (useView) joinTarget = outerSelectJoins;
 								
@@ -1589,6 +1607,7 @@
 			// Add literal filters to the WHERE clause
 
 			foreach (Variable v in varOrder) {
+				// Is there a literal value filter?
 				if (options.VariableLiteralFilters == null) continue;
 				#if !DOTNET2
 				if (options.VariableLiteralFilters[v] == null) continue;
@@ -1596,6 +1615,10 @@
 				if (!options.VariableLiteralFilters.ContainsKey(v)) continue;
 				#endif
 				
+				// If this variable was not used in a literal column, then
+				// we cannot filter its value. Really, it will never be a literal.
+				if (!(bool)varSelectedLiteral[v]) continue;
+
 				foreach (LiteralFilter filter in (ICollection)options.VariableLiteralFilters[v]) {
 					string s = FilterToSQL(filter, "vlit" + (int)varRef2[v] + ".value");
 					if (s == null) continue;
@@ -1615,7 +1638,9 @@
 			
 			string viewname = "queryview" + Math.Abs(GetHashCode());
 			if (useView) {
-				cmd.Append("CREATE VIEW ");
+				cmd.Append("DROP VIEW IF EXISTS ");
+				cmd.Append(viewname);
+				cmd.Append("; CREATE VIEW ");
 				cmd.Append(viewname);
 				cmd.Append(" AS ");
 				
@@ -1773,6 +1798,10 @@
 				SemWeb.Filters.StringStartsWithFilter f = (SemWeb.Filters.StringStartsWithFilter)filter;
 				return CreateLikeTest(col, f.Pattern, 0); // 0=starts-with
 			}
+			if (filter is SemWeb.Filters.StringEndsWithFilter) {
+				SemWeb.Filters.StringEndsWithFilter f = (SemWeb.Filters.StringEndsWithFilter)filter;
+				return CreateLikeTest(col, f.Pattern, 2); // 2==ends-with
+			}
 			if (filter is SemWeb.Filters.NumericCompareFilter) {
 				SemWeb.Filters.NumericCompareFilter f = (SemWeb.Filters.NumericCompareFilter)filter;
 				return col + FilterOpToSQL(f.Type) + f.Number;
@@ -1972,7 +2001,7 @@
 				try {
 					RunCommand(cmd);
 				} catch (Exception e) {
-					if (Debug) Console.Error.WriteLine(e);
+					if (Debug && e.Message.IndexOf("already exists") == -1) Console.Error.WriteLine(e);
 				}
 			}
 		}
@@ -2011,6 +2040,7 @@
 				"CREATE INDEX meta_index ON " + table + "_statements(meta);",
 			
 				"CREATE UNIQUE INDEX literal_index ON " + table + "_literals(hash);",
+				"CREATE INDEX literal_value_index ON " + table + "_literals(value(20));",
 				"CREATE UNIQUE INDEX entity_index ON " + table + "_entities(value(255));"
 				};
 		}

Modified: branches/beagle-rdf/Util/SemWeb/Store.cs
==============================================================================
--- branches/beagle-rdf/Util/SemWeb/Store.cs	(original)
+++ branches/beagle-rdf/Util/SemWeb/Store.cs	Fri Mar  7 03:37:19 2008
@@ -53,7 +53,7 @@
 			if (rdfs)
 				ret.AddReasoner(new RDFS(ret));
 			if (euler)
-				throw new Exception ("Euler spec is not shipped with beagle");
+				ret.AddReasoner(new Euler(ret)); // loads it all into memory!
 			
 			return ret;
 		}



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