[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[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<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwiki.eprints.org%2Fw%2FEPScript&data=01%7C01%7C%7C36c98e98823843c40d4d08d74741bc37%7C4a5378f929f44d3ebe89669d03ada9d8%7C0&sdata=msCezdc%2FURhLB00q6MXSvGLllyfKyXJcr72l2vGE%2BIw%3D&reserved=0>

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<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Feprintsug%2Fdimensions-badge%2Fblob%2Fmaster%2Flib%2Fplugins%2FEPrints%2FPlugin%2FScreen%2FEPrint%2FBox%2FDimensionsBadge.pm%23L11-L29&data=01%7C01%7C%7C36c98e98823843c40d4d08d74741bc37%7C4a5378f929f44d3ebe89669d03ada9d8%7C0&sdata=ZG8zXmB%2Feit8RNLDIJqPz4sUrkVhw2qegNwpgx0H60w%3D&reserved=0> (documentation)
https://github.com/eprintsug/dimensions-badge/blob/master/lib/plugins/EPrints/Plugin/Screen/EPrint/Box/DimensionsBadge.pm#L117-L149<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Feprintsug%2Fdimensions-badge%2Fblob%2Fmaster%2Flib%2Fplugins%2FEPrints%2FPlugin%2FScreen%2FEPrint%2FBox%2FDimensionsBadge.pm%23L117-L149&data=01%7C01%7C%7C36c98e98823843c40d4d08d74741bc37%7C4a5378f929f44d3ebe89669d03ada9d8%7C0&sdata=NLk7FpVYZfHODyWi88qDEm3h7p80bRiAVYFIRy5MUnM%3D&reserved=0> (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 at ecs.soton.ac.uk<mailto:eprints-tech-bounces at ecs.soton.ac.uk> [mailto:eprints-tech-bounces at ecs.soton.ac.uk] On Behalf Of Stefan Wellsandt via Eprints-tech
Sent: 02 October 2019 14:27
To: eprints-tech at ecs.soton.ac.uk<mailto:eprints-tech at 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/<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.eprints.org%2Ftech.php%2F&data=01%7C01%7C%7C36c98e98823843c40d4d08d74741bc37%7C4a5378f929f44d3ebe89669d03ada9d8%7C0&sdata=T0cK9IHed5fOgK42wgHpbWKHr5mJK1PPCxiOINQ111k%3D&reserved=0>
*** EPrints community wiki: http://wiki.eprints.org/<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwiki.eprints.org%2F&data=01%7C01%7C%7C36c98e98823843c40d4d08d74741bc37%7C4a5378f929f44d3ebe89669d03ada9d8%7C0&sdata=U8FNs%2F0WR81dQjjAr%2BS%2BTYHZ1tpjdw7Fe%2B7i2zC91is%3D&reserved=0>
*** EPrints developers Forum: http://forum.eprints.org/<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fforum.eprints.org%2F&data=01%7C01%7C%7C36c98e98823843c40d4d08d74741bc37%7C4a5378f929f44d3ebe89669d03ada9d8%7C0&sdata=YBWGH4n8wqKDQ2IlR2QAmWvi6rrFyio8G2aWRR8NuGc%3D&reserved=0>


--
Christopher Gutteridge <totl at soton.ac.uk><mailto:totl at soton.ac.uk>
You should read our team blog at http://blog.soton.ac.uk/webteam/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ecs.soton.ac.uk/pipermail/eprints-tech/attachments/20191002/1be4d1a4/attachment.html