[SMW-devel] [PATCH] Support LIKE in queries

2007-12-20 Thread Thomas Bleher
Yesterday I needed LIKE queries for properties, so I added it to SMW
(patch attached). It was surprisingly simple.

This patch adds a new comparator, %, to the already existing <, > and !.
So you can say [[has capital::%A%]] and it will return all pages that
have a property "has capital", with a value starting with "A".

Notes:
* The first % tells SMW that the following is to be interpreted as a
  parameter to LIKE. So if you want to get all pages with capitals that
  have an A in them, you'd have to say [[has capital::%%A%]]
* NOT LIKE would be trivial to add, I just didn't need it and couldn't
  decide on the character to use (maybe § or &?)
* Probably it should be possible to disable LIKE queries, as they could
  be quite expensive.
* I saw that there is some (planned?) support for LIKE queries already,
  but it looked like it was not applicable to {{#ask}}, so I didn't
  reuse it.

Thomas
--- a/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
+++ b/extensions/SemanticMediaWiki/includes/SMW_QueryProcessor.php
@@ -739,7 +739,7 @@ class SMWQueryParser {
 		if ($value == '*') { // printout statement
 			return;
 		}
-		$list = preg_split('/^(<|>|!)/',$value, 2, PREG_SPLIT_DELIM_CAPTURE);
+		$list = preg_split('/^(<|>|!|%)/',$value, 2, PREG_SPLIT_DELIM_CAPTURE);
 		$comparator = SMW_CMP_EQ;
 		if (count($list) == 3) { // initial comparator found ($list[1] should be empty)
 			switch ($list[1]) {
@@ -755,6 +755,10 @@ class SMWQueryParser {
 	$comparator = SMW_CMP_NEQ;
 	$value = $list[2];
 break;
+case '%':
+	$comparator = SMW_CMP_LIKE;
+	$value = $list[2];
+break;
 //default: not possible
 			}
 		}
--- a/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php
+++ b/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php
@@ -11,6 +11,7 @@ define('SMW_CMP_EQ',1); // matches only datavalues that are equal to the given v
 define('SMW_CMP_LEQ',2); // matches only datavalues that are less or equal than the given value
 define('SMW_CMP_GEQ',3); // matches only datavalues that are greater or equal to the given value
 define('SMW_CMP_NEQ',4); // matches only datavalues that are unequal to the given value
+define('SMW_CMP_LIKE',5); // matches only datavalues that are LIKE the given value
 
 // print request
 define('SMW_PRINT_CATS', 0);  // print all direct cateories of the current element
@@ -392,6 +393,9 @@ class SMWValueDescription extends SMWDescription {
 case SMW_CMP_NEQ: 
 	$comparator = '!'; // not supported yet?
 break;
+case SMW_CMP_LIKE: 
+	$comparator = '%'; // not supported yet?
+break;
 default: case SMW_CMP_EQ: 
 	$comparator = '';
 break;
--- a/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php
+++ b/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php
@@ -1668,6 +1668,7 @@ class SMWSQLStore extends SMWStore {
 			case SMW_CMP_LEQ: $op = '<='; break;
 			case SMW_CMP_GEQ: $op = '>='; break;
 			case SMW_CMP_NEQ: $op = '!='; break;
+			case SMW_CMP_LIKE: $op = ' LIKE '; break;
 			case SMW_CMP_EQ: default: $op = '='; break;
 		}
 		if ($description->getDatavalue()->isNumeric()) {


signature.asc
Description: Digital signature
-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___
Semediawiki-devel mailing list
Semediawiki-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/semediawiki-devel


Re: [SMW-devel] Minor issues with inline errors

2007-12-20 Thread Thomas Bleher
* Markus Krötzsch <[EMAIL PROTECTED]> [2007-12-18 16:32]:
> On Freitag, 14. Dezember 2007, Thomas Bleher wrote:
> > * Markus Krötzsch <[EMAIL PROTECTED]> [2007-12-12 21:07]:
> > > On Sonntag, 2. Dezember 2007, Thomas Bleher wrote:
> > > >  67 foreach($properties as $singleprop) {
> > > >  68 $dv =
> > > > SMWFactbox::addProperty($singleprop,$value,$valueCaption); 69 }
> > > >
> > > > $dv is overwritten here on each iteration of the loop. This looks
> > > > fishy.
> > >
> > > Yes, but normally there is only one iteration anyway. What would you
> > > suggest instead?
> >
> > Hmm, should nested properties be allowed here?
> >
> > FWIW, the regexp is
> > $semanticLinkPattern = '/\[\[   # Beginning of the link
> > (([^:][^]]*):[=:])+ # Property name (can be
> > nested?) (   # After that:
> >   (?:[^|\[\]]   #   either normal text (without
> > |, [ or ])
> >
> >   |\[\[[^]]*\]\]#   or a [[link]]
> >   |\[[^]]*\]#   or an [external link]
> >
> > )*) # all this zero or more times
> > (\|([^]]*))?# Display text (like "text" in
> > [[link|text]]), optional \]\]# End of link
> > /x';
> >
> > (I took the liberty of modifying it to make it more readable)
> >
> >
> >
> > If nested properties should not be supported, all is fine, as $property
> > is just ([^:][^]]*), ie without the trailing :: or :=. Then the
> > preg_split and the for loop can be removed (OK, maybe the regexp could
> > be made more strict, but that's another issue).
> >
> > If nested properties should be supported, this code is buggy, but I do
> > not know what the correct semantics would be anyway.
> 
> There are no "nested properties", and indeed I do not see what this should be 
> either. What there is are (a) multiple properties per value, and (b) nested 
> links in values. So you can write
> 
> [[property1::property2::Some [[strange]] text]]
> 
> and it will have the same semantic effect as 
> 
> [[property1::Some [[strange]] text]]
> [[property2::Some [[strange]] text]]
> 
> while relieving you from repeating the value. Many use cases for that can now 
> be addressed with property hierarchies as well, but sometimes it may still be 
> useful (e.g. when annotating an email address as both URL and string).
> 
> The above works, so there should be no bug here.

Ah, OK :)

What got me confused was that $dv is overwritten, and I had somehow
thought that it was some value for the factbox. But as it is only the
text that is displayed inline, everything works fine.

Regards,
Thomas



signature.asc
Description: Digital signature
-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___
Semediawiki-devel mailing list
Semediawiki-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/semediawiki-devel


Re: [SMW-devel] [PATCH] Support LIKE in queries

2007-12-20 Thread Asheesh Laroia
On Thu, 20 Dec 2007, Thomas Bleher wrote:

> Yesterday I needed LIKE queries for properties, so I added it to SMW
> (patch attached). It was surprisingly simple.

This would be LIKE TOTALLY AWESOME to get in to Semantic MediaWiki.

It would be great if later SMW could have Valgol support 
.

-- Asheesh.

P.S. In all total like seriousness, queries with LIKE support are a good 
idea

--
The star of riches is shining upon you.

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Semediawiki-devel mailing list
Semediawiki-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/semediawiki-devel


[SMW-devel] Patch - displaying thumbnails for image results in inline queries

2007-12-20 Thread Yaron Koren
Hi,

On a project I'm working on, a table generated by an #ask function lists
image pages in one of the columns, and I wanted to display thumbnails,
instead of image file names, in that column. Then I had the thought that
inline queries should *always* display thumbnails for images (assuming
linking is set to true) - after all, why would someone just want to see a
list of image names?

Anyway, below is the two-line addition to accomplish that. Feel free to add
it in to the code - I think it would definitely be an improvement.

-Yaron


Index: includes/SMW_DV_WikiPage.php
===
--- includes/SMW_DV_WikiPage.php(revision 28671)
+++ includes/SMW_DV_WikiPage.php(working copy)
@@ -88,6 +88,8 @@
}
if ( ($linked === NULL) || ($linked === false) ) {
return $this->m_prefixedtext;
+   } elseif ($this->m_namespace == NS_IMAGE) { // display
thumbnail for images
+   return '[[' . str_replace("'", ''',
$this->m_prefixedtext) . '|' . $this->m_textform . '|thumb]]';
} else {
return '[[:' . str_replace("'", ''',
$this->m_prefixedtext) . '|' . $this->m_textform . ']]';
}
-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___
Semediawiki-devel mailing list
Semediawiki-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/semediawiki-devel