Using framework, trying to make all upper case author names to upper case only used for the first letter

14 views
Skip to first unread message

Kouichi NAKAMURA

unread,
Sep 24, 2017, 6:05:06 AM9/24/17
to zotero-dev

I'm trying to write a web translator using the framework for an abstract search site for a large meeting. It's working and pretty close to the end, but it still has one problem. Because all the last names are written in UPPER CASE on the website, the imported zotero item (conferencePaper type) also inherits the same issue.


Iinput string is something like this
"*M. J. REDINBAUGH1, J. M. PHILLIPS1, N. A. KAMBI1, S. MOHANTA1, A. RAZ2,3, Y. B. SAALMANN1"



I thought fixing this problem should be easy. After trying many methods, however, I realized that, because the framework's FW.Xpath is relying on eval, standard approaches are not working. I need to use `addFilter` method as follows:


FW.Xpath("//xpath/expression").text().addFilter(function (s) { return s + "HELLO WORLD"; })

In FW.Scraper, the creators property is defined as below to retrieve all UPPER CASE author names (without an error).

FW.Xpath('//div[@class="span7"]/dl/dd[1]')
  .text().replace(/;.+/,"").replace(/\*/g,"").replace(/\d,(?=\d)/g,"")
 .replace(/\d,/g,";").replace(/\d$/,"").split(/;/)
 .cleanAuthors("author"),


my attempt to change the font case failed (still all in upper case). Here I assumed the datatype of `s` is array of objects with lastName property.
FW.Xpath('//div[@class="span7"]/dl/dd[1]')
  .text().replace(/;.+/,"").replace(/\*/g,"").replace(/\d,(?=\d)/g,"")
 .replace(/\d,/g,";").replace(/\d$/,"").split(/;/)
 .cleanAuthors("author")
 .addFilter(function(s) {
    var t = s;
    for (var i = 0; i < s.length; i++) {
      t[i].lastName = s[i].lastName.substr(0,1) + 
      t[i].lastName.substr(1).toLowerCase();
    }

return t;
}),,


Here is another attempt which failed (still all in upper case). Here I assumed the datatype of arr is array of strings. The function works for array of strings outside of framework, but not inside.
FW.Xpath('//div[@class="span7"]/dl/dd[1]')
.text().replace(/;.+/,"").replace(/\*/g,"").replace(/\d,(?=\d)/g,"")
.replace(/\d,/g,";").replace(/\d$/,"").split(/;/)
.addFilter(function(arr) {
        for (var i = 0; i < arr.length; i++) {
            var name = arr[i];
            var lastName = name.replace(/([A-Z].\s){1,}/,"");

            var lastNameBits = lastName.split(/-/);
            
            for (var j = 0; j< lastNameBits.length ; j++){

              if (lastNameBits.length > 1) {
                 var k = 1;
               } else {
                 var k = 2;
              }
              lastNameBits[j] = lastNameBits[j].substr(0,k)
                  + lastNameBits[j].substr(k).toLowerCase();
            }
            
            var newLastName = lastNameBits.join('-');

            var index = name.search(/(?=([A-Z].\s){1,})./);
            
            arr[i] = arr[i].replace(lastName,newLastName);

          }

        return arr;
    }.cleanAuthor("author"),


Here's a question: Is there a way to change the font case of author names with framework nicely?

You might just say don't mess around with the framework but write in usual JavaScript. But because it's so close (I thought) that I'm tempted to stick to the framework.



Sebastian Karcher

unread,
Sep 24, 2017, 10:47:57 AM9/24/17
to zoter...@googlegroups.com, Kouichi NAKAMURA
You can do this using capitalizeTitle, but if this translator is for
inclusion with Zotero, we are phasing out the Framework and would likely
not take new FW translators. There are excellent code template
available, together with a number of helper functions that make writing
translators in plain js hardly more complex than using FW and you then
can use the entirety of JS. See
https://www.mediawiki.org/wiki/Citoid/Creating_Zotero_translators



On 09/24/2017 05:46 AM, Kouichi NAKAMURA wrote:
>
> I'm trying to write a web translator using the framework for an
> abstract search site for a large meeting. It's working and pretty
> close to the end, but it still has one problem. Because all the last
> names are written in UPPER CASE on the website, the imported zotero
> item (conferencePaper type) also inherits the same issue.
>
>
> Iinput string is something like this
> |
> "*M. J. REDINBAUGH1, J. M. PHILLIPS1, N. A. KAMBI1, S. MOHANTA1, A.
> RAZ2,3, Y. B. SAALMANN1"
> |
>
>
>
> I thought fixing this problem should be easy. After trying many
> methods, however, I realized that, because the framework's FW.Xpath is
> relying on eval, standard approaches are not working. I need to use
> `addFilter` method as follows:
>
>
> |
> FW.Xpath("//xpath/expression").text().addFilter(function(s){returns
> +"HELLO WORLD";})
> |
>
> In FW.Scraper, the creatorsproperty is defined as below to retrieve
> --
> You received this message because you are subscribed to the Google
> Groups "zotero-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to zotero-dev+...@googlegroups.com
> <mailto:zotero-dev+...@googlegroups.com>.
> To post to this group, send email to zoter...@googlegroups.com
> <mailto:zoter...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/zotero-dev.
> For more options, visit https://groups.google.com/d/optout.


Kouichi NAKAMURA

unread,
Sep 24, 2017, 11:10:07 PM9/24/17
to zotero-dev
Thank you. It's good to know that you're phasing out the framework. Also, thanks for the link. I didn't know about this page.

I'm only started learning JavaScript for this about a week ago, but when I tried, I managed to write functional doWeb() for single entry already (with the feature I wanted). Hopefully, I can implement 'multiple' soon.

Best,
Kouichi
Reply all
Reply to author
Forward
0 new messages