I have the result of a semantic query. For one of the properties, a comma separated list, I want to separate each item and pass it as a parameter to a template. However, I am struggling to find a way to do this.
For example;
Query:
{{#ask: [[Category:Something]] [[Has title::Somethingelse]]
| mainlabel=-
| ?Has property
| link=none
| format=template
| template=plainText
}}
The plainText template will have the result, which is a comma separated list. Now, from the plainText template I would like to separate the comma separated list and put each value as a parameter into another template.
I have tried using {{#arraydefine:key|values|delimiter|options}} but when I pass {{#arrayindex:key|0}} to the template, the value is not passed. The whole array is passed separated by 0. I have also tried using {{#vardefine: etc but this also does not pass the variable.
My question boils down to, how to pass a variable to a template?
Thanks,
The separation needs to be done in the template.
If you use anonymous args like in
http://semantic-mediawiki.org/wiki/Template:Query_output_demo
Your params can be fetched with defaults like this:
{{{1|param1default}}} {{{2|param2default}}} ...
Now one of your params is a comma separated list. You might want to use the
#explode
parser function to get to the different parts of the CSV. Lets assume the second
parameter has your csv then:
{{#explode:{{{2}}}|;|0}}
{{#explode:{{{2}}}|;|1}}
...
will provide the fields.
For this to work you need the extension
https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions##explode
and to enable it according to the instructions there.
Related
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.
I want to make the custom filter dynamic. So, for writing future code I could pass in a list of references to each field object in the table.
That way I do not have to hardcode data.(field name here). Instead, it would work off the list of properties of the column object.
I know there ways to get the field normally but they are always returned as strings not object references. This obviously will not work with the dot operator.
I have some success with using JSON.parse followed by looping through the entries. But like before it returns the field as a string instead of a reference.
So is there a way to retrieve the column fields as objects and if so how?
I tried using the getColumns but I am still getting undefined when grabbing the fields. There is something wrong with my code.
function customFilter(data, filterParams) {
//data - the data for the row being filtered
//filterParams - params object passed to the filter
for (column of table.getColumns()){
field = column.getField();
console.log(data.field);
}
}
You speak about references in your question, but references to what? the field names themselves arent references to anything, they simply show Tabulator how to access the underlying row data, without a specific row data object to reference, there isn't anything to build any references from
You can only have a reference if it points to something, but there is nothing for the field definitions to point to without the row data.
If you are looking to have objects that you can manipulate the the getColumns function returns an array of Column Components with each component having a range of functions that can be called to manipulate that column. including the getField function that returns the field for that column.
Given that the Tabulator filter functions will accept the filed names with dot notation that shouldnt be an issue at all, but you can also pass the column component directly into the filter, so it shouldnt be a problem their either
In my current project, users can create spreadsheets with fields, then each field inherits a unique ID based on the column it is attached to in the spreadsheet, so when fields are updated, my template looks like this:
<input type="text" name="{{field.unique_id}}" id="{{field.unique_id}}" value="{{field.data}}">
But in my views, when I attempt to grab the value from the field:
request.POST.get('field.unique_id')
It sees nothing because it's looking for literally 'field.unique_id' and not the variable that field.unique_id would produce.
Is there a way to tell it to replace field.unique_id with the variable or do I have to define the id of the POST get manually?
You can use a variable in request.POST.get() instead of a string, for example.
request.POST.get(my_var)
However in your case, request.POST.get(field.unique_id) does not work, since the keys in request.POST are strings, and field.unique_id is an integer.
The answer is to use str() to convert it to a string.
request.POST.get(str(field.unique_id))
I have a a field which accepts value as "Patient_1077,ELLA(161st Pharmacy address)" i.e: Patient ID, name and Address, that I want to parameterize, CSV is not helpful in this case as value contains comma itself, is there any alternative way where I can inject these kind of values from file and parameterize the same?
Delimiter is configurable. See this for an example:
http://ivetetecedor.com/how-to-use-a-csv-file-with-jmeter/
You can also quote the data, which is another solution in your case.
You can make values in csv like:
Patient_0154, ELLA(102st The Cave)
Patient_0155, ELLA(101st The
Wall)
Then read it:
Patient_0154 -> user
ELLA(102st The Cave) -> adress
And when you need the value you do the simple trick — ${user},${adress}.
At least this is my approach when I don't want to code a lot for a simple task.
I am using RapidMiner 5 GUI and i want to store all the value of an attribute in different text file. But if i am using any write utility like write or write document it is either overwriting the data or giving an error.
I want to store all the value in different files with a sequence or something attached to it.
Is there any way?
With the Loop Attributes operator you can loop with the attributes and with the Generate Macro operator you can create from the macro as attribute name a file name you prefer.