EPrints Technical Mailing List Archive

Message: #04690


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

[EP-tech] Re: How to set a field to be multilang (Imports brake)


Adam hi!

Don't apologise, I know you had been busy since I had read the emails regarding the hack-day and saw your absent in the list. I'll test your code tomorrow at work and see if it works. The way I see it, it is similar to the code I posted in my last email, but mine was missing the get_property_defaults, which might be the problem.

As far as the wiki is concerned, don't worry, as I promised I'll write a full guide of how to set the title and abstract fields to be multilang, but I'll do it once everything is tested by my library staff (our site is not up yet).

Thanks again for your help, I'll return with feedback tomorrow evening.

George.

PS. Your next task is to make a video showing how to make the Adam Field to be virtual :)

On 15/9/2015 8:19 μμ, Adam Field wrote:
Sorry, I had a UKCoRR event, a German Language User Group Meeting, a Hack Day and a UK User Group Meeting all in the last two weeks, which were my first two weeks back from Annual Leave!

I think we'll need to override set_value on our Virtualwithvalue metafield class.  Before we added code to pull values out of another field.  We need code now to insert values into another field.  Something like this (add it to the code below in the email of June 30th):

#In the field class (Virtualwithvalue?)

sub set_value
{
         my( $self, $object, $value ) = @_;
         if ( defined $self->get_property("set_value") )
         {
             return $self->call_property( "set_value", $object, $value);
         }
         return undef;
}

...and in get_property_defaults:

$defaults{set_value} = undef;

...then in any field definitions in the repository config (along the lines of get_value discussed previously):

set_value => sub
{
my ($eprint, $value) = @_;

#only use this on imports, NOT if the value is already set
if ($eprint->is_set('ml_title'))
{
return;
}

$eprint->set_value('title_ml', [text => '$value', lang => $c->{defaultlanguage} ]);
}


I leave is as an exercise for the reader to debug the above code, which hasn't even been parsed, let alone tested.

Please feedback with tested code, and some documentation on the wiki :)

--
Adam Field
Business Relationship Manager and Community Lead
EPrints Services

On 9 Sep 2015, at 12:49, George Mamalakis <mamalos@eng.auth.gr> wrote:

Yeah, this is whom I'm waiting for...:):)

On 09/09/2015 01:15 μμ, alen vodopijevec wrote:
Hmm.. maybe using similar function that you have in 'title' filed
definition.. I'm not sure in this moment, but it's a good idea and will
check out.

.. Adam would surely know better :)

--
alen

On 09/09/2015 11:16 AM, George Mamalakis wrote:
Hi Alen,

I think that through the use of virtual fields, there could be a way to
finally assign values in the appropriate fields (via some function), but
I'm not sure which function I have to override. And I am talking about
virtual fields, because in our multilingual solution we have created
additional multilingual fields for title and abstract, and have replaced
original the fields with virtual counterparts that calculate their
values through code. Hence my assumption on storing their values as well.

Thanks for your help!

On 09/09/2015 11:52 πμ, alen vodopijevec wrote:
Hi!

You will have to override default import plugins, ie. copy original ones
and make them write to new multilang field(s).

I've made a mistake a long time ago with changing original title,
abstract, keyword fileds into multilang so we are still coping with it :))

Kind regards,
Alen
--
http://fulir.irb.hr

On 09/09/2015 10:34 AM, George Mamalakis wrote:
Hello everybody, and wishes for a happy academical-year!

I am returning to the subject of multilang fields when the title and
subject are created in the way described in the last mail of this
thread, because of a problem that arises when import plugins are used.

As I was informed by our library staff, when they wanted to import (eg.
BibTeX) a document, the title and abstract fields were not filled. I
tried it myself (through the web interface) and they were true (no
errors in apache). I suppose that the import plugins use the title and
abstract field to write data, but in our case these fields are virtual,
so I have no idea how they handle inserts.

Any idea and help would be greatly appreciated, since not being use
EPrints import functionality, practically renders the creation of basic
multilang fields (title and abstract) created in that way unusable.

Thanks all in advance!

On 01/07/2015 01:05 μμ, George Mamalakis wrote:
OK,

I'll keep it in mind.

Thanks

On 01/07/2015 12:15 μμ, Field A.N. wrote:
You don't have a render_value property, but a quick scan of the MetaField object suggests that you might not need one if you're just making a text node from the value.  Not 100% sure though -- if it works, then don't worry about it :)


--
Adam Field
Business Relationship Manager and Community Lead
EPrints Services
+44 (0)23 8059 8814





On 30 Jun 2015, at 16:39, George Mamalakis wrote:

OK, it's done.

I'll upload the procedure on the wiki when I finish with my project (it'll be after the summer) or if I find free time in the meantime.

The general steps are (in order to replace the title field in this example):

1) Create a MetaField which returns a value ( ~eprints/lib/plugins/EPrints/MetaField/Virtualwithvalue.pm) containing the code found in Adam's video:

package EPrints::MetaField::Virtualwithvalue;

use strict;
use warnings;

use EPrints::MetaField;

our @ISA = qw( EPrints::MetaField );

use strict;

sub get_property_defaults
{
         my ( $self ) = @_;
         my %defaults = $self->SUPER::get_property_defaults;
         $defaults{get_value} = undef;
         return %defaults;
}

sub get_value
{
         my( $self, $object ) = @_;
         if ( defined $self->get_property("get_value") )
         {
             return $self->call_property( "get_value", $object);
         }
         return undef;
}

2) Change ./archives/myarchive/cfg/cfg.d/eprint_fields.pl to contain the new fields (ml_title and the new title field (which is based on our newly created MetaField derivative)), ie:

{
         name => 'ml_title',
         type => 'multilang',
         multiple => 1,
         fields => [ { sub_name => "text", type => "longtext", input_rows => 3, make_single_value_orderkey => 'EPrints::Extras::english_title_orderkey' } ],
         input_add_boxes => 1,
},

{
         name => 'title',
         type => 'virtualwithvalue',
         virtual => 1,

         get_value => sub
         {
             my ($eprint) = @_;
             if ($eprint->is_set('ml_title'))
             {
                 my $vals = $eprint->get_value('ml_title');
                 my $title = '';
                 # set the default lang's text as title
                 foreach my $v1 (@{$vals})
                 {
                     if (%$v1{'lang'} eq $c->{defaultlanguage})
                     {
                         $title = %$v1{'text'};
                     }
                 }
                 # if not a default lang found, get the first object's text as title
                 if ($title eq '')
                 {
                     $title = ${$$vals[0]}{'text'} ;
                 }
                 return $title;

             }
             return undef;
         }
},

3) Update your archive in order to create the new field:

$ ./bin/epadmin update myarchive

4) Add the appropriate phrases in ~/archives/myarchive/cfg/lang/en/phrases/local.xml (and do it for any other language you may have):

<!-- multilang title related phrases -->
         <epp:phrase id="eprint_fieldname_ml_title">Title</epp:phrase>
         <epp:phrase id="eprint_fieldname_ml_title_text">Text</epp:phrase>
         <epp:phrase id="eprint_fieldname_ml_title_lang">Language</epp:phrase>
         <epp:phrase id="eprint_fieldhelp_ml_title">The title of the item. The title should not end with a full stop, but may end with a question mark. There is no way to make italic text, please enter it normally. If you have a subtitle, it should be preceded with a colon [:]. Use capitals only for the first word and for proper nouns.
<br/>Example: <span class="ep_form_example">A brief history of time</span>
<br/>Example: <span class="ep_form_example">Life: an unauthorised biography</span>
<br/>Example: <span class="ep_form_example">Mathematics for engineers and scientists. 5th edition</span>
<br/>Example: <span class="ep_form_example">Ecosystems of the world. Vol. 26. Estuaries of the world</span>
</epp:phrase>

5) Add (and remove) the appropriate entries in you workflows (~/archives/myarchive/cfg/workflows/eprint/default.xml) in the "core" section:

<!--    <component><field ref="title" required="yes" input_lookup_url="{$config{rel_cgipath}}/users/lookup/title_duplicates" input_lookup_params="id={eprintid}&amp;dataset=eprint&amp;field=title" /></component>
-->
         <component><field ref="ml_title" required="yes"/></component>

6) Test and reload your archive for your changes to take effect:
$ ./bin/epadmin test
$ ./bin/epadmin reload myarchive


Thanks everyone for the help, and especially Tim and Adam for making it possible!! :):)


PS. Hope I haven't forgotten anything...:)


On 26/06/2015 05:27 μμ, George Mamalakis wrote:
Tim,

Now that I got illuminated (:-P) by the video regarding EPrints' virtual fields, I am trying to think how I could take advantage of them in order to use to solve my multilanguage-fields problem, and I think I'm a bit stuck.

I'll speak my thoughts out loud and please correct me if I'm wrong. Let the target field be the "title".

So, we need the title to be stored in more than one languages in the database, which should be "easily" accomplished using a multi-row field. Hence, multilang fields are a perfect candidate for this. We therefore create a new field, let's say ml_title (as you proposed) and store our values in it. Now, in order for EPrints not to break, we change the title field to be a virtual field and compose its output based on ml_title field. In the end, we'll have two fields for the title. The title field (of type virtualfield) that will be calculating its value each time it's called, and the ml_title field (of type multilang). Is that correct?

Now that I've written my thoughts, I think I'm no more stuck and I see that your idea is brilliant and very easy!! :):). And if the above paragraph is not your idea, and it's even easier than that, then it'll be even more brilliant!! :):)

Cheers again, I'll give it a try on Monday!

Once again, nice work Adam and thanks Tim and all of you for your help!

PS. It would be extremely beneficial if there were a guide as to how EPrints' internals work. Something that is a little be more explanatory than the "anatomy of a request (http://wiki.eprints.org/w/Anatomy_of_a_request)" and explain how the coders of EPrints really think of EPrints in their minds.

On 25/06/2015 11:42 πμ, Timothy Miles-Board wrote:
The "problem" is that when you ask $eprint->get_value() for the value of a multilang field it gives you a perl data structure - in this case arrayref (array of {langcode=>text} hashrefs) - ie. the same behaviour as you would expect for a compound field or any field with a multiple value.

$eprint->get_value() is used everywhere - including in export plugins. So any field where the plugin implicitly expects a string - like title, abstract etc - it will output something like ARRAYx01123123

So your options are:

* Fix up all the plugins to be cleverer about how they get the "best" value of multilang field (ie. use get_value() then look at the user's lang / default lang to pull out the best string from the multilang structure) - but this would mean repeating the same routine in every plugin..

* Change the way that get_value() works so that it somehow decides which behaviour to use (arrayref vs best lang string) based on calling context etc. - get_value is used everywhere in EPrints so this would probably break everything..

* Add a layer of abstraction between the low level get_value() and the plugins that defines an API for returning language dependent strings - then change all the             plugins to use that (so instead of get_value(), plugins could call get_lang_string() or something - something like this would be the best approach...

In the meantime, what you could do is instead of changing the default title, abstract etc fields, just define new multilang versions.

So eg. ml_title, ml_abstract ...

Then use these in your workflow instead of the default title, abstract .. etc.

Finally in eprint_fields_automatic.pl, write some code to take the ml_* fields and populate the equivalent scalar fields. So eg. get the value of ml_title, pull out the text in the default language (or if the default language version is not defined, some other language in order of preference - the EPrints::Language module already does stuff like this with phrases) and write that value into the title field.

Then anything that expects $eprint->get_value( "title" ) to return a string will be happy (albeit they will always give the default/preferred language).

Or...

Change the default title, abstract etc. fields to a virtual field so that you can dynamically work out the (string) value by looking at ml_title, ml_abstract etc - as long as the value returned is always a string this shouldn't break anything.

Food for thought I hope,

Tim

Timothy Miles-Board
Web & Repositories Development Specialist, University of London Computer Centre
020 7863 1342  |  07742 970 351  | timothy.miles-board@london.ac.uk | @drtjmb
The University of London is an exempt charity in England and Wales


From: eprints-tech-bounces@ecs.soton.ac.uk <eprints-tech-bounces@ecs.soton.ac.uk> on behalf of George Mamalakis <mamalos@eng.auth.gr>
Sent: 25 June 2015 8:38 AM
To: eprints-tech@ecs.soton.ac.uk
Subject: [EP-tech] Re: [spam?] Re: How to set a field to be multilang

Thanks Alen, I'll look into it deeper.

It's sad, though, that default Import/Export plugins break. Could you give a few hints on how to customise these plugins? (general guidelines). Could the changes be applied on the parent Import and Export plugin, or most child plugins tend to override functions dealing with title, abstract, etc?

And that being the case, isn't it equivalent to adding extra fields for an additional language? Either way same things are broken, right? :)

Lastly, where are these metadata fields stored in the database? Reading the article in the link you provided diagonally, it seems that I need to update the database in order to create them, right?

Thanks again!

On 24/06/2015 11:18 μμ, Alen Vodopijevec wrote:
Hi!

You have Metadata Field Types documented here:
http://wiki.eprints.org/w/Category:EPrints_Metadata_Fields

But, be aware that changing title, keywords and abstract fields to
'compound' breaks default EPrints plugins - export/import .. these
plugins expect title/keywords/abstract to be simple and not compound
(hash) value.

I'm using it that way but there is some extra effort to customize and
maintain import/export plugins.

If anybody have a suggestion or a better solution please let me know.

Maybe this is a good opportunity to discuss that i18n issues in EPrints.

Kind regards,
--
Alen

On 06/24/2015 10:15 AM, George Mamalakis wrote:
Ah,

And by the way, is there any documentation on this "fields" attribute
somewhere? Cos I think it wasn't mentioned anywhere.

Thanks again!

On 24/06/2015 10:29 πμ, Timothy Miles-Board wrote:
---------- Forwarded message ----------
From: Timothy Miles-Board <timothy.miles-board@ulcc.ac.uk>
Date: 18 Jun 2015 11:30 pm
Subject: Re: [EP-tech] How to set a field to be multilang
To: eprints-tech@ecs.soton.ac.uk
Cc:

{
name => 'title',
type => 'multilang',
multiple => 1,
fields => [ { sub_name => "text", type => "longtext",
input_rows => 3, make_single_value_orderkey =>
'EPrints::Extras::english_title_orderkey' } ],
input_add_boxes => 1,
},


Tim

On 23 Jun 2015 9:09 am, George Mamalakis <mamalos@eng.auth.gr> wrote:

Guys (and girls),

Any news on multilingual fields? Anybody using them?

Thanks!

George

On 18/06/2015 06:31 μμ, George Mamalakis wrote:
Hello again,

I am trying to make my EPrints installation support
multilanguage fields
(eg. title, abstract, etc.). The thing I did that worked (which
doesn't
feel right to me, though) was adding a new Metadata field (eg.
title_en)
and add it to the database and workflow. On the documentation,
on the
other hand, I saw that there is a Multilang field type
(./perl_lib/EPrints/MetaField/Multilang.pm) which should be
used for
this purpose. The strange thing is that its perldoc DESCRIPTION
section
starts with "not done", probably meaning that it's not implemented?
Disregarding the last comment, when I changed
./archives/myarchive/cfg/cfg.d/eprint_fields.pl title field to
read:
{
name => 'title',
type => 'multilang',
input_rows => 3,
make_single_value_orderkey =>
'EPrints::Extras::english_title_orderkey',
},

and I reloaded epadmin, I got the following error:

"Error in field property for eprint.title: fields on a multilang
metafield can't be undefined"

So, which is the proper way for adding multilanguage support in
fields
and display them in workflows?

Thanks for all help in advance!

--
George Mamalakis

IT and Security Officer,
Electrical and Computer Engineer (Aristotle Univ. of Thessaloniki),
PhD (Aristotle Univ. of Thessaloniki),
MSc (Imperial College of London)

School of Electrical and Computer Engineering
Aristotle University of Thessaloniki

phone number : +30 (2310) 994379



*** 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/



*** 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/
--
George Mamalakis

IT and Security Officer,
Electrical and Computer Engineer (Aristotle Univ. of Thessaloniki),
PhD (Aristotle Univ. of Thessaloniki),
MSc (Imperial College of London)

School of Electrical and Computer Engineering
Aristotle University of Thessaloniki

phone number : +30 (2310) 994379




----------------------------- Upozorenje -----------------------------

Automatskom detekcijom utvrdjeno je da tekst ove poruke
podsjeca na tzv. phishing poruku.

AKO SE U PORUCI TRAZI DA POSALJETE VASU IRB LOZINKU ILI
DA UNESETE IRB PODATKE NA NAVEDENOM LINKU, RADI SE O
NAPADU S CILJEM KRADJE I ZLOUPOTREBE PODATAKA.

Centar za informatiku i racunarstvo,
Institut Rudjer Boskovic

----------------------------- Upozorenje -----------------------------


*** 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/
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.

*** 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/
--
George Mamalakis

IT and Security Officer,
Electrical and Computer Engineer (Aristotle Univ. of Thessaloniki),
PhD (Aristotle Univ. of Thessaloniki),
MSc (Imperial College of London)

School of Electrical and Computer Engineering
Aristotle University of Thessaloniki

phone number : +30 (2310) 994379





*** 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/
--
George Mamalakis

IT and Security Officer,
Electrical and Computer Engineer (Aristotle Univ. of Thessaloniki),
PhD (Aristotle Univ. of Thessaloniki),
MSc (Imperial College of London)

School of Electrical and Computer Engineering
Aristotle University of Thessaloniki

phone number : +30 (2310) 994379





*** 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/
--
George Mamalakis

IT and Security Officer,
Electrical and Computer Engineer (Aristotle Univ. of Thessaloniki),
PhD (Aristotle Univ. of Thessaloniki),
MSc (Imperial College of London)

School of Electrical and Computer Engineering
Aristotle University of Thessaloniki

phone number : +30 (2310) 994379



*** 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/
*** 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/

*** 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/


*** 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/



--
George Mamalakis

IT and Security Officer,
Electrical and Computer Engineer (Aristotle Univ. of Thessaloniki),
PhD (Aristotle Univ. of Thessaloniki),
MSc (Imperial College of London)

School of Electrical and Computer Engineering
Aristotle University of Thessaloniki

phone number : +30 (2310) 994379



*** 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/



*** 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/


-- 
George Mamalakis

IT and Security Officer
Electrical and Computer Engineer (Aristotle Un. of Thessaloniki),
PhD (Aristotle Un. of Thessaloniki),
MSc (Imperial College of London)

Department of Electrical and Computer Engineering
Faculty of Engineering
Aristotle University of Thessaloniki

phone number : +30 (2310) 994379