Re: Using RDF queries with beagle



> >  @dBera: I would suggest to modify the RDFQuery so that it only takes
> >  subject, predicate and object, where the predicate is the one dumped by
> >  beagle-dump-index --fields. The property type can then be derived from
> >  the property name. I know that this exposes the internal property name
> >  like
> >   prop:k:beagle:MimeType
> >  but since users of the RDFQuery have to specify Text, Keyword or
> >  Internal anyways, they can take the long property name in the first
> >  place. This makes things easier.
> 
> Go for it.
attached you find a patch that removes the predicate type from the
RDFQuery.

>  This might need some change in the LuceneQueryingDriver
> code; if you get lost there, let me know.
I guess you mean to get
  prop:k:beagle:MimeType
instead of
  beagle:MimeType
out of the RDF query, since I put the long form in the query. Well,
maybe the Property class gets an 'fullKey' attribute, which is set by
the respective backend to the internal / long value. The LuceneBackend
would set this using the PropertyToFieldName method. But other backends
would need to do it differently. Well, the RDFQuery already does
LuceneBackend magic (removing prop:k:), so I don't know what is right
here.

Enrico M.
Index: BeagleClient/Query.cs
===================================================================
--- BeagleClient/Query.cs	(Revision 4490)
+++ BeagleClient/Query.cs	(Arbeitskopie)
@@ -283,13 +283,29 @@
 			Keepalive = false;
 		}
 
-		public RDFQuery (Uri subject, string predicate, PropertyType predicate_type, string _object) : this ()
+		public RDFQuery (Uri subject, string predicate, string _object) : this ()
 		{
+			// extract the property type from the property, and remove the prop:?: prefix
+			// e.g. from prop:k:beagle:MimeType
+			PropertyType ptype = PropertyType.Internal;
+			
+			if (predicate != null) {
+				if ((predicate.Length > 7) && predicate.StartsWith ("prop:")) {
+					switch (predicate [5]) {
+						case 't': ptype = PropertyType.Text; break;
+						case 'k': ptype = PropertyType.Keyword; break;
+						case 'd': ptype = PropertyType.Date; break;
+					}
+					// remove the prop:?:, which will be added by beagle later
+					predicate = predicate.Substring (7);
+				}
+			}
+
 			this.Subject = subject;
 			this.Predicate = (predicate == null ? String.Empty : predicate);
-			this.PredicateType = predicate_type;
+			this.PredicateType = ptype;
 			this.Object = (_object == null ? String.Empty : _object);
-
+						
 			// FIXME: the query contains a dummy part that will make the query
 			// pass even if it is empty. Empty queries are not handled by default.
 			//
Index: RDFAdapter/BeagleSource.cs
===================================================================
--- RDFAdapter/BeagleSource.cs	(Revision 4490)
+++ RDFAdapter/BeagleSource.cs	(Arbeitskopie)
@@ -76,23 +76,7 @@
 			}
 		}
 
-		// extract the property type from the property
-		// e.g. from prop:k:beagle:MimeType
-		PropertyType ptype = PropertyType.Internal;
-
-		if (p != null) {
-			if ((p.Length > 7) && p.StartsWith ("prop:")) {
-				switch (p [5]) {
-					case 't': ptype = PropertyType.Text; break;
-					case 'k': ptype = PropertyType.Keyword; break;
-					case 'd': ptype = PropertyType.Date; break;
-				}
-				// remove the prop:?:, which will be added by beagle later
-				p = p.Substring (7);
-			}
-		}
-
-		RDFQuery query = new RDFQuery (s, p, ptype, o);
+		RDFQuery query = new RDFQuery (s, p, o);
 		RDFQueryResult result = (RDFQueryResult) query.Send ();
 		
 		foreach (Hit hit in result.Hits) {
Index: tools/RdfQueryTool.cs
===================================================================
--- tools/RdfQueryTool.cs	(Revision 4490)
+++ tools/RdfQueryTool.cs	(Arbeitskopie)
@@ -8,11 +8,10 @@
 	public static void Main (string[] args)
 	{
 
-		if (args.Length != 4) {
+		if (args.Length != 3) {
 			Console.WriteLine ("Usage: program-name <subject> <predicate> <predicate-type> <object>");
 			Console.WriteLine ("      <subject>         : URI or path");
 			Console.WriteLine ("      <predicate>       : property name (string)");
-			Console.WriteLine ("      <predicate-type>  : property type (Internal,Text,Keyword,Date)");
 			Console.WriteLine ("      <object>          : object (string)");
 			Console.WriteLine ("      Use \"\" (empty string) for unspecified subject, predicate, type or object");
 			return;
@@ -20,17 +19,13 @@
 
 		RDFQueryResult result;
 
-		Console.WriteLine ("subject:'{0}' predicate:'{1}'({3}) object:'{2}'", args [0], args [1], args [3], args [2]);
+		Console.WriteLine ("subject:'{0}' predicate:'{1}' object:'{2}'", args [0], args [1], args [2]);
 
 		Uri subject = null;
 		if (args [0] != String.Empty)
 			subject = new Uri (args [0]);
 
-		PropertyType type = PropertyType.Text;
-		if (args [2] != String.Empty)
-			type = (PropertyType) Enum.Parse (typeof (PropertyType), args [2], true);
-
-		RDFQuery query = new RDFQuery (subject, args [1], type, args [3]);
+		RDFQuery query = new RDFQuery (subject, args [1], args [2]);
 		result = (RDFQueryResult) query.Send ();
 
 		if (result == null) {


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