How to calculate number of authors in EPrints (repository like DSpace)? - perl

EPrints is a perl-based repository, see EPrints in WP
My librarian asked me to setup EPrins in the following way (only for the "monograph" type of documents):
If there are 3 or less authors then print 'authors' before title of the monograph;
If there more than 3 authors then print '$title / $authors'.
For example, 7 authors in first publication and 2 authors in second publication:
Analysis of the quotation corpus of the Russian Wiktionary / Smirnov A., Levashova T., Karpov A., Kipyatkova I., Ronzhin A., Krizhanovsky A., Krizhanovsky N. Research in Computing Science. 2012
Meyer C. M., Gurevych I. Worth its Weight in Gold or Yet Another Resource - A Comparative Study of Wiktionary, OpenThesaurus and GermaNet. 2010.

After several ours of try-and-fail attempts... The big problem is that EPrints is not pure Perl, and there are not too much documentation...
We need to edit the citations file /eprints/cfg/citations/eprint/default.xml). There is the following solution:
<!-- Monograph: if < 4 authors then print 'authors' before title -->
<when test="type = 'monograph'">
<if test="is_set(creators_name)">
<set name='authors' expr="creators_name">
(Debug information) Number of authors:
<print expr="$authors.length()"/>.
<set name='authors_len' expr="$authors.length()">
<if test="$authors_len lt 4">
<print expr="creators_name"/>
</if>
</set>
</set>
</if>
</when>
<!-- Title -->
<cite:linkhere><xhtml:em><print expr="title"/>:</xhtml:em></cite:linkhere>
<!-- "/ authors" after Title for monography if len(authors)>3 -->
<choose>
<when test="type = 'monograph'">
<if test="is_set(creators_name)">
<set name='authors' expr="creators_name">
<set name='authors_len' expr="$authors.length()">
<if test="$authors_len gt 3">
/ <print expr="creators_name"/>
</if>
</set>
</set>
</if>
</when>
<otherwise>
</otherwise>
</choose>
It works, but... I calculated twice the same variable "authors_len". And I don't know how to reuse this variable and calculate it only once.
I tried the EPrints function "is_set(authors_len)" and I tried "is_set($authors_len)", but EPrints throws different error messages o_O

I would use the following, checking for the creators_name being set, and how many creators there are:
<when test="type = 'monograph'">
<choose>
<when test="is_set(creators_name) and length(creators_name) lt 4">
<print expr="creators_name" />
/
<print expr="title" />
</when>
<when test="is_set(creators_name) and length(creators_name) gt 3">
<print expr="title" />
/
<print expr="creators_name" />
</when>
<otherwise>
<print expr="title" />
</otherwise>
</choose>
</when>
When using XML comments in an EPrints citation file, they will appear in the HTML source of the page. To make comments in the citation file that do not appear in the html source, you can use:
<comment>This will not appear in the html source</comment>
The language used for EPrints citations is documented on the EPrints Wiki:
https://wiki.eprints.org/w/EPScript
https://wiki.eprints.org/w/EPrints_Control_Format
Some XML configuration files use different default namespaces - so you may see the elements prefixed with a namespace e.g.
<cite:citation xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://eprints.org/ep3/control" xmlns:cite="http://eprints.org/ep3/citation" >
...
<epc:comment>This is a comment</epc:comment>
...
</cite:citation>
The best place for assistance with EPrints is their Mailing list - search the wiki (linked above) for details (I don't have enough reputation to post another link!).

Related

Can a single cite within a citation reference more than one url/accessed date pairs?

Let's say that I have a reference such as:
title "Hello World"
urls
- http://example.com/foo (accessed 20/03/2018)
- http://example.com/bar (accessed 10/05/2015)
(And let's say that the above reference is processed into a form that a CSL processor can understand; citeproc-js in this case)
Does the CSL specification allow to produce a citation (from this only reference) that looks like this?
Hello World! http://example.com/foo (accessed 20/03/2018); http://example.com/bar (accessed 10/05/2015)
I know I could support one pair with this: (simplified style for the example)
<citation>
<layout>
<text variable="title" suffix=" "/>
<group>
<text variable="URL" suffix=" "/>
<date variable="accessed" prefix="(" suffix=")">
<date-part name="day" suffix="/"/>
<date-part name="month" suffix="/"/>
<date-part name="year"/>
</date>
</group>
</layout>
</citation>
But how do I "iterate" over multiple pairs?
It doesn't seem that the CSL specification nor the schema for CSL data support this. Am I wrong?
You can do this with two citations, e.g.:
- type: webpage
URL: http://example.com/foo (accessed 20/03/2018)
- type: webpage
URL: http://example.com/bar (accessed 10/05/2015)
Style snippet
<citation>
<layout delimiter="; ">
<group>
<text variable="URL" suffix=" "/>
<date variable="accessed" prefix="(" suffix=")">
<date-part name="day" suffix="/"/>
<date-part name="month" suffix="/"/>
<date-part name="year"/>
</date>
</group>
</layout>
</citation>
And then simply include "Hello World!" in the text. Note the delimiter in layout that determines how the two elements are separated.

IzPack: Require at least one of multiple packs

I've got a software that consists of different plugins that can be selected during installation in IzPack. These plugins provide different features to the software: input, processing, output. The software needs at least one input and output plugin to work.
How do I specify that at least one plugin providing a certain feature is selected in the PackPanel?
I believe that this was implemented in izpack v5.0.0-rc5 and newer. PacksPanel does not allow you to continue if you have deselected all the options.
Based on your comment I would solve this by using conditionvalidator:
Basically add condition for each of your packs:
<condition type="packselection" id="pack1inputselected">
<name>Pack 1 input</name>
</condition>
Then make OR conditions with groups of your packs (input, processing, output), e.g. like this:
<condition type="or" id="inputgroup">
<condition type="ref" refid="pack1inputselected" />
<condition type="ref" refid="pack2inputselected" />
</condition>
Then add a final AND validation condition (id is crucial as it has to always start by conditionvalidator word! The conditionvalidator class gets to validate all the conditions starting with conditionvalidator.):
<condition type="and" id="conditionvalidator.packsselected">
<condition type="ref" refid="inputgroup" />
<condition type="ref" refid="processinggroup" />
<condition type="ref" refid="outputgroup" />
</condition>
Add conditionvalidator to PacksPanel in panels element:
<panel classname="PacksPanel" id="panel.packs">
<validator classname="com.izforge.izpack.installer.validator.ConditionValidator" />
</panel>
There. Everytime the condition that is validated (when clicking on next) by conditionvalidator will not be true (that is if you will not have the correct packs selected), it will throw a message and will not allow you to continue. You can change the message by adding string to CustomLangPack with .error.message (e.g. in this example conditionvalidator.packsselected.error.message).

How can I reuse an SQL fragment with parameters?

I'm intending to make a fragment for reusing with parameters.
<insert ...>
<selectKey keyProperty="id" resultType="_long" order="BEFORE">
<choose>
<when test="_databaseId == 'derby'">
VALUES NEXT VALUE FOR SOME_ID_SEQ
</when>
<otherwise>
SELECT SOME_ID_SEQ.NEXTVAL FROM DUAL
</otherwise>
</choose>
</selectKey>
INSERT INTO ...
</insert>
Can I make an SQL fragment using parameters?
<sql id="selectKeyFromSequence">
<selectKey keyProperty="id" resultType="_long" order="BEFORE">
<choose>
<when test="_databaseId == 'derby'">
VALUES NEXT VALUE FOR #{sequenceName}
</when>
<otherwise>
SELECT #{sequenceName}.NEXTVAL FROM DUAL
</otherwise>
</choose>
</selectKey>
</sql>
So that I can reuse them like this?
<insert ...>
<include refid="...selectKeyFromSequence"/> <!-- How can I pass a parameter? -->
INSERT INTO ...
</insert>
Is this possible?
As of version 3.3.0 you can do it like this:
<sql id="myinclude">
from ${myproperty}
</sql>
<include refid="myinclude">
<property name="myproperty" value="tablename"/>
</include>
See section SQL in http://www.mybatis.org/mybatis-3/sqlmap-xml.html
You cannot pass parameter to tags. There is a similar SO question, iBatis issue and a MyBatis issue.
Includes are in-lined when the xmls are parsed so the do not exist as
their own once the startup process finishes (from MyBatis issue).
However, you can use variables inside tags. You do not pass it as a parameter but you can give it as a parameter to the function that has the include tag. You need to use the same variable name in all functions, i.e. #{sequenceName}.

Wikipedia API: how to retrieve multiple titles AND resolve redirects in 1 call?

It appears from the MediaWiki API:Query page that you can only resolve a redirect one at a time.
The document even says "The example below isn't really useful because it doesn't use any query modules, but shows how the redirects parameter works."
But how can you get the redirect information -- using a query module that does return multiple results?
If you have any result that returns pages, then you can just append redirects to the query and it resolves the redirects. If you don't have results that returns pages, you can usually convert it to that by using a generator.
For example, the query
http://en.wikipedia.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Redirects_from_gender&redirects
returns something like (shortened)
<api>
<query>
<categorymembers>
<cm pageid="648" ns="0" title="Actress" />
<cm pageid="19887132" ns="0" title="Administratrix" />
</categorymembers>
</query>
</api>
If you convert that into a generator
http://en.wikipedia.org/w/api.php?action=query&generator=categorymembers&gcmtitle=Category:Redirects_from_gender
you get
<api>
<query>
<pages>
<page pageid="648" ns="0" title="Actress" />
<page pageid="19887132" ns="0" title="Administratrix" />
</pages>
</query>
</api>
And if you now add redirects
http://en.wikipedia.org/w/api.php?action=query&generator=categorymembers&gcmtitle=Category:Redirects_from_gender&redirects
you get
<api>
<query>
<redirects>
<r from="Actress" to="Actor" />
<r from="Administratrix" to="Administrator (law)" />
</redirects>
<pages>
<page pageid="21504235" ns="0" title="Actor" />
<page pageid="6676496" ns="0" title="Administrator (law)" />
</pages>
</query>
</api>
You can also use prop=redirects with any generator, e.g. generator=allpages. This is a new feature since MW-1.23, fixing bug T59057.
When using generator=allpages with max limits (gaplimit=max and rdlimit=max) and apihighlimits right is available, all redirects on ArchWiki are resolved in a single query ;)
https://wiki.archlinux.org/api.php?action=query&generator=allpages&gapfilterredir=nonredirects&gaplimit=max&prop=redirects&rdprop=pageid|title|fragment&rdlimit=max

phing nested if conditions

I am having trouble understanding the Phing documentation regarding multiple conditions for a given <if> tag. It implies you cannot have multiple conditions unless you use the <and> tag, but there are no examples of how to use it. Consequently I nested two <if> tags, however I feel silly doing this when I know there is a better way. Does anyone know how I can use the <and> tag to accomplish the following:
<if><equals arg1="${deployment.host.type}" arg2="unrestricted" /><then>
<if><equals arg1="${db.adapter}" arg2="PDO_MYSQL"/><then>
<!-- Code Here -->
</then></if>
</then></if>
I find it very surprising that no one has had any experience with this. Phing is an implementation of the 'ANT' build tool in PHP instead of Java. It is very useful for PHP developers who feel a lack of a simple and powerful deployment tool. Java's ability to package self contained web projects into a single file or package multiple web project files into a yet bigger file is an amazing capability. ANT or Phing does not get PHP to that point, but its a definite step in the right direction and leaps and bounds easier to understand and use than GNU Make ever was or will be.
According to the Phing documentation:
The <or> element doesn't have any attributes and accepts an arbitrary number of conditions as nested elements. This condition is true if at least one of its contained conditions is, conditions will be evaluated in the order they have been specified in the build file.
It may sound confusing at first, especially with no handy examples available, but the keywords to note are, "accepts an arbitrary number of conditions as nested elements." If you try the following build snippet out, you should easily realize how to use <or> and <and> conditions:
<if>
<or>
<equals arg1="foo" arg2="bar" />
<equals arg1="baz" arg2="baz" />
</or>
<then>
<echo message="Foo equals bar, OR baz equals baz!" />
</then>
</if>
<if>
<or>
<equals arg1="foo" arg2="bar" />
<equals arg1="baz" arg2="bam" />
</or>
<then>
<echo message="Foo equals bar, OR baz equals baz!" />
</then>
<else>
<echo message="No match to OR found." />
</else>
</if>
<fail />