EPrints Technical Mailing List Archive

See the EPrints wiki for instructions on how to join this mailing list and related information.

Message: #07988


< Previous (by date) | Next (by date) > | < Previous (in thread) | Next (in thread) > | Messages - Most Recent First | Threads - Most Recent First

Re: [EP-tech] Building citations based on condition with Regular Expression


Yes, make a function called regexp which takes a regexp string and a haystack string and returns a BOOLEAN

I'm writing this without testing but...

sub run_regex
{   

    my( $self, $state, $pattern, $haystack ) = @_;

    my $regex = $pattern->[0];
    return [ $haystack->[0] =~ m/$regex/, "BOOLEAN" ];
}


should give you a function where you can in the XML go 

               <when test="regex( 'International', event_title )">


On 02/10/2019 14:49, John Salter via Eprints-tech wrote:

Hi Stefan,

You're right - it doesn't.

 

I don't think there is a simple way to achieve what you are trying to do with the EPScript methods available:

https://wiki.eprints.org/w/EPScript

 

If you look in EPrints::Script::Compiler::tokenise you'll see the different characters that EPScript expects - it doesn't include RegExps.

 

You could inject a method to EPrints::Script::Compiled that returns a boolean for use in a test, or even rendered xhtml.

I used this approach here:

https://github.com/eprintsug/dimensions-badge/blob/master/lib/plugins/EPrints/Plugin/Screen/EPrint/Box/DimensionsBadge.pm#L11-L29 (documentation)

https://github.com/eprintsug/dimensions-badge/blob/master/lib/plugins/EPrints/Plugin/Screen/EPrint/Box/DimensionsBadge.pm#L117-L149 (method added to EPrints::Script::Compiled)

 

Let me know if that helps - or if you want some more explanation.

You *could* inject a method that took a RegExp as a parameter - you would need to be careful about compiling the regex from this string if you do!

 

Cheers,

John

 

 

From: eprints-tech-bounces@ecs.soton.ac.uk [mailto:eprints-tech-bounces@ecs.soton.ac.uk] On Behalf Of Stefan Wellsandt via Eprints-tech
Sent: 02 October 2019 14:27
To: eprints-tech@ecs.soton.ac.uk
Subject: [EP-tech] Building citations based on condition with Regular _expression_

 

Hello,

 

I want to use a regular _expression_ to assemble a part in a citation. This script (see below) throws me an error – I assume the EprintsScript does not know RegExp.

<when test="type.one_of('conference_item','editor_conference_proceeding')">

    In: Proceedings of the

    <choose>

               <when test="event_title =~ \International\">

                               <if test="event_title"><print expr="event_title"/></if>

               </when>

               <otherwise>

                               <if test="event_type"><print expr="event_type"/></if> on <if test="event_title"><print expr="event_title"/></if>

               </otherwise>

    </choose>

  </when>

 

 

What is the easiest way to fix this problem?

 

Best regards

Stefan


*** Options: http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech
*** Archive: http://www.eprints.org/tech.php/
*** EPrints community wiki: http://wiki.eprints.org/
*** EPrints developers Forum: http://forum.eprints.org/
-- 
Christopher Gutteridge <totl@soton.ac.uk> 
You should read our team blog at http://blog.soton.ac.uk/webteam/