SMW Table, only show results with a set value - mediawiki

When i use a SMW table
{{#ask: [[Category:XY]]
|?Referenzwert
|format=table
|limit=1000
}}
I only want to see the pages in the property "Referenzwert" that have the value 1.
Is that possible or do i need to create various properties that use the "allows value" special property?
I have not found any answers in the SMW documentation, neither the normal Mediawiki documentation.

Related

Semantic Mediawiki: aggregation similar to SQL GROUP BY like #ask query

I've implemented a page with a long list of subojects.
Every object contains one article (title + url) and N tags. I'd like to group by tag and show the count of articles related to that tag.
Something like:
SELECT tag, count(distinct article)
GROUP BY tag
I found an answer but it's very generic and I'd also like to document the solution for other user with the same problem.
As you know from previous answers to this question, you cannot have a "distinct" function from an SMW ask query.
My preferred solution is to use the "arrays" extension, that allows you to access PHP array manipulation functions in wiki code. Further than "distinct" list of value, its an irreplaceable tool for handling semantic data from queries.
You can create an array with the following function :
{{#arraydefine: *identifier* | *data* | *delimiter* | *parameters* }}
Identifier is the variable name you want.
Data is the array content, in SMW context, you load it with a query result content.
Delimiter specify the array delimiter relative to data. This have to be
coherent with the delimiter chosen in the ask query.
Parameters is where the magic appends. You can set a "unique" parameter, reducing the data list to unique values, thus, emulating the "distinct" function.
In tour case, you may do something like :
{{#arraydefine:tags
| {{#ask:[[-Has subobject::{{FULLPAGENAME}}]]
|?Tags#-=
| mainlabel=-
|limit = 1000
}}
|,
|unique
}}
Note that SMW ask query are, by default, limited to 50 results. Adding "limit=" adjusts the maximum result size.
At this point, you defined an array called "tags" containing all distinct values of this property.
You can use arrayprint function for any further data treatment or display.

Passing properties in Semantic MediaWiki

Currently I have 3 categories, Application, Application Instance and Vendor.
Right now Application has a link (via property Made By) to Vendor. Application instances need to link back to Vendor via a property. I have the query I can use to return the application name and vendor is
{{#ask:
[[Category:Program]][[{{{Program}}}]]
|?Made By
}}
however
{{#set:Made By={{#ask:
[[Category:Program]][[{{{Program}}}]]
|?Made By
}}}}
doesn't work to set the property to the value of vendor which is returned by the ask query.
Are there other ways to do this?
Maybe a bit late but you could probably do this using a template to set the property. Something like this?
In the Application Instance template (or manually on each Application Instance page) add the following ask query:
{{#ask:[[Category:Program]][[{{{Program}}}]]
|?Made By
|link=none
|format=template
|template=Set made by
}}
Then create the template "wiki/Template:Set made by" with the following:
includeonly>
{{#set:
Made By={{{2}}}
}}
</includeonly>
Notes
Parameter {{{1}}} is the subject which is the page name and {{{2}}} will be the result for 'Made By'.
Stripping the link from the query results prevents the extra text being passed to the set command which would confuse things.
You can also use the inverse of properties in queries by adding a minus sign in front of them. (e.g. '-Made By')

Wikipedia api fulltext search to return articles with title, snippet and image

I've been looking for a way to query the wikipedia api based on a search string for a list of articles with the following properties:
Title
Snippet/Description
One or more images related to the article.
I also have to make the query using jsonp.
I've tried using the list=search parameter
http://en.wikipedia.org/w/api.php?action=query&list=search&prop=images&format=json&srsearch=test&srnamespace=0&srprop=snippet&srlimit=10&imlimit=1
But it seems to ignore the prop=images, I've also tried variations using the prop=imageinfo and prop=pageimages. But they all give me the same result as just using the list=search.
I've also tried action=opensearch
http://en.wikipedia.org/w/api.php?action=opensearch&search=test&limit=10&format=xml
Which gives me exactly what I want when i set format=xml, but returns a simple array of page titles when using format=json and therefore fails because of the jsonp requirement.
Is there another approach to doing this? I'd really like to solve this in a single request rather than make the first search request and then a second request for the images using titles=x|y|z
As Bergi suggested, using generators is the way to go here. Specifically what I would do:
use list=search as a generator, to get the list of articles
use prop=pageimages to get a representative image for each article
use prop=extracts to get a description for each article
The whole query could look like this:
http://en.wikipedia.org/w/api.php?format=json&action=query&generator=search&gsrnamespace=0&gsrsearch=test&gsrlimit=10&prop=pageimages|extracts&pilimit=max&exintro&explaintext&exsentences=1&exlimit=max
I've tried using the list=search parameter, but it seems to ignore the prop=images
If you want to retrieve any properties, you need to specify a list of pages for which you want to get these; e.g. by using the titles=, pageids=, or revids= parameters. You didn't send any, so you did not get a result for the prop=images.
If you did use api.php?action=query&list=search&srsearch=test&prop=images&titles=test you would have gotten the search results for test and the images of the Test page.
You can however also use the collection that the list query generates for your property query, using the list module as a generator. The query would look like
api.php?action=query&generator=search&gsrsearch=test&gsrnamespace=0&gsrprop=snippet&prop=images. Unfortunately, it does not yield the attributes that the list contained, but only used the pageids for a basic property query.
Using two queries is probably the way to go. Btw, I'd recommend to use the pageimages property, it will likely give you the best results.

How to change the memberof overlay's objectClass to groupOfUniqueNames

I am running OpenLDAP 2.4.31. Based on Reverse Group Membership Maintenance:
The memberof overlay updates an attribute (by default memberOf) whenever changes occur to the membership attribute (by default member) of entries of the objectclass (by default groupOfNames) configured to trigger updates.
I would like to change these defaults, so the overlay is based on the objectClass groupOfUniqueNames and the attribute uniqueMember. I did not find any mention on how to do this in the documentation, and also I did not find any default setting for this in cn=config; what are the settings that I have to add here to make the desired changes?
I have already added the memberof and referential integrity configuration to cn=config based on this article.
Use the following to change the memberof behaviour. I'm showing the solution here for a traditional slapd.conf configuration.
memberof-group-oc groupOfUniqueNames
memberof-member-ad uniqueMember
As for the referential integrity, you can use the memberof overlay's own setting to do this, which is much easier:
memberof-refint true
For cn=config, you probably therefore want the following:
olcMemberOfRefInt: TRUE
olcMemberOfGroupOC: groupOfUniqueNames
olcMemberOfMemberAD: UniqueMember
The example provided on www.schenkels.nl (your link) almost gets you there. You can append the following to the block dn: olcOverlay={0}memberof,olcDatabase={1}hdb,cn=config:
olcMemberOfGroupOC: groupOfNames
olcMemberOfMemberAD: member
olcMemberOfMemberOfAD: memberOf
Above shows the defaults that you already mentioned. It should be possible to change those to the attributes you want to use. Check out the member-of man page for a description of the configuration options.

Categories and Keywords access via Razor Template in Tridion

I am attempting to access values in the Categories and Keywords information for a Tridion Publication via a Razor TBB in Tridion 2011. The Razor documentation lists the following example code:
<ul>
#foreach (var keyword in Publication.MetaData.SomeKeywordFields) {
<li>#keyword.Title (#keyword.Id)</li>
}
</ul>
I have a Keyword inside of a Category though... in fact, that's the only way I am myself aware that you can even have a Keyword in Tridion, but correct me if I am wrong. Extrapolating from the example's syntax, I tried the following where "myCategory" is a Category in the publication, and "myKeyword" is a Keyword inside of the myCategory Category:
#foreach (var keyword in Publication.MetaData.myCategory) {
if(#keyword.Title == "myKeyword") {
#keyword.Title
}
When I run this template, I get an error stating that DynamicItemsFields: Key 'testcategory' Not Found In ItemFields (Object reference not set to an instance of an object)
Can anyone help with identifying if it is even possible to do what I am attempting here (as it seems like it is based on the documentation but still not sure) and if so, provide an example of the correct syntax?
You're almost there with your code except that you're using the actual CategoryName. As Puf commented, you have to use the "fieldname" of you Publication Metadata not the actual CategoryName. You should just change the "myCategory" to the actual fieldname
#foreach (var keyword in Publication.MetaData.*<<FIELDNAME>>*) {
if(#keyword.Title == "myKeyword") {
#keyword.Title
}
}
[FIELDNAME] --> is the XMLName of publication metadata schema.
Keywords are indeed always within a Category or another Keyword. But they are used within items like Components and (as in the example) metadata on Publications, Folders, etc.
The example from the documentation is outputting each value of a multi-valued metadata Keyword field on the Publication (i.e. "Allow Multiple Values", "Values selected from a list" and "Category" all checked in the Metadata Schema).
If you are trying to do something similar, you can indeed modify the name of the field and it will work. From your question, however, it seems like you are trying to loop over all Keywords within a certain Category - which requires a different approach.
For that, you would need the equivalent of a GetList call within your TBB. I'm not familiar enough with the Razor mediator to provide sample code for that, sorry.
Thanks to Ram G in chat:
The Publication itself, typically your 010, 020... 050 etc. levels, can have a metadata schema attached to them as well. The XMLName of the field being targeted by the Razor logic block above is actually the field name of this metadata schema item, not the name of the Category itself. In the metadata schema for the publication, if you select the Design tab, Make your XML field for the item a "Text" type, select "Options will be selected from a list", by default, another Checkbox will appear called "Category" which, if checked, automatically pulls in the full list of Category items present in that publication. So, when that Field is targeted by the Razor logic now, it is in multiple steps targeting the Category value as well.
Thanks again Ram G