> On 22 Oct 2014, at 18:42, Offray Vladimir Luna Cárdenas <off...@riseup.net> 
> wrote:
> 
> Hi,
> 
> Thanks again. I have a small script, using Citezen which does the trick. I 
> can explore and modify the BibTeX File from the playground with this:
> 
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> | bibFile bibliography bibStream bibOutputer |
> bibFile := ((FileLocator documents / 'U/Libertadores/Grafoscopio') children
>       detect: [:each | each basename endsWith: 'bib' ]).
> bibliography := CZBibParser parse: bibFile contents.
> bibStream := '' writeStream.
> 1 to: (bibliography size) do: [:index |
>   (((bibliography entries at: index) fields at: 2) key = 'shorttitle')
>       ifTrue: [
>        (bibliography entries at: index)
>           key: ((bibliography entries at: index) fields at: 2) value].
>       bibOutputer := CZBibtexOutputer new.
>       bibStream nextPutAll:
>         (bibOutputer entryToBibtexString:
>               (bibliography entries at: index)); cr.].
> bibliography.
> bibFile writeStreamDo: [:stream |
>          stream nextPutAll: bibStream contents withUnixLineEndings ].
> bibStream contents.
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Some constructive comments about your code (smaller is always better, 
especially for interactive snippets):

- you can change the #detect: to [ :each | each extension = #bib ]
- you can iterate directly over the entries with #do: as in bibliography 
entries do: [ :each | .. ] which saves you the #at: index
- there are handy unary shortcuts for accessing elements, like #first, #second 
and so on (up to #ninth) which also save you parenthesis
- you can also construct strings using the idiom String streamContents: [ 
:bibStream | .. ] 

Sorry, these jumped to me when I saw your code, I hope you don't mind ;-) 

> I will put some functionality inspired by this on my prototype this weekend.
> 
> Cheers,
> 
> Offray
> 
> On 10/21/2014 01:20 AM, stepharo wrote:
>> Check in the tools there is a bib writer.
>> 
>> Stef
>> 
>> On 21/10/14 03:33, Offray Vladimir Luna Cárdenas wrote:
>>> Thanks Stef and Damien,
>>> 
>>> I have this small script as a proof of concept:
>>> 
>>> ===================================
>>> | bibFile bibliography |
>>> bibFile := ((FileLocator documents / 'U/Libertadores/Grafoscopio')
>>> children
>>>    detect: [:each | each basename endsWith: 'bib' ]) contents.
>>> bibliography := CZBibParser parse: bibFile.
>>> 1 to: (bibliography size) do: [:index |
>>> (((bibliography entries at: index) fields at: 2) key = 'shorttitle')
>>>    ifTrue: [
>>>        (bibliography entries at: index)
>>>            key: ((bibliography entries at: index) fields at: 2) value
>>> ]].
>>> bibliography.
>>> ===================================
>>> 
>>> Now I want to write back the corrected file to the .bib ... just
>>> having problems finding which message does the job. I'll keep searching.
>>> 
>>> Cheers,
>>> 
>>> Offray
>>> 
>>> On 10/16/2014 06:40 AM, Damien Cassou wrote:
>>>> from Damien Pollet:
>>>> 
>>>> You will need to load the .bib file from zotero (read the file however
>>>> you like, then pass the stream to the CZ parser). You'll get a
>>>> CZBibSet (I don't recall the name exactly) which represents the
>>>> contents of the file. A Set is composed of entries, each of which has
>>>> a key and a set of fields. Finally, fields accept a few different
>>>> kinds of values.
>>>> 
>>>> Your processing is just iterating a set then setting the key of each
>>>> entry (or possibly removing and re-adding the entry, I don't recall if
>>>> it's implemented like a dictionary or more like a list).
>>>> 
>>>> 
>>>> On Mon, Oct 13, 2014 at 2:57 AM, Offray Vladimir Luna Cárdenas
>>>> <off...@riseup.net <mailto:off...@riseup.net>> wrote:
>>>> 
>>>>     Hi,
>>>> 
>>>>     I'm using a Zotero collection for keeping track of several
>>>> references I have
>>>>     found for my article about the experience of the
>>>> outline/tree-like metaphor
>>>>     for writing inside Pharo (as soon as I have a presentable
>>>> working draft I
>>>>     hope to share it with you).
>>>> 
>>>>     Now I want to make a post-processing of the bibtex file exported
>>>> from
>>>>     Zotero. The idea is to use "shorttitle" field instead to replace
>>>> the Zotero
>>>>     auto-generated one and have custom keys. So for example instead of:
>>>> 
>>>>     =======
>>>>     @misc{_holistic_????,
>>>>              title = {Holistic software assessment (Uni Zurich -
>>>> 2011) on Vimeo},
>>>>              shorttitle = {Girba-holistic-2011},
>>>>              url = {http://vimeo.com/42073344?__from=outro-local
>>>>     <http://vimeo.com/42073344?from=outro-local>},
>>>>              urldate = {2014-08-19},
>>>>              note = {00000}
>>>>     }
>>>> 
>>>>     =======
>>>> 
>>>> 
>>>>     I would like to have:
>>>> 
>>>> 
>>>>     =======
>>>> 
>>>>     @misc{Girba-holistic-2011,
>>>>              title = {Holistic software assessment (Uni Zurich -
>>>> 2011) on Vimeo},
>>>>              shorttitle = {Girba-holistic-2011},
>>>>              url = {http://vimeo.com/42073344?__from=outro-local
>>>>     <http://vimeo.com/42073344?from=outro-local>},
>>>>              urldate = {2014-08-19},
>>>>              note = {00000}
>>>>     }
>>>> 
>>>>     =======
>>>> 
>>>> 
>>>>     I have already installed Citizen and open it on the browser to
>>>> see the code,
>>>>     but I can find any place to start with examples.
>>>> 
>>>>     Any advice on how to solve this issue will be appreciated.
>>>> 
>>>>     Cheers,
>>>> 
>>>>     Offray
>>>> 
>>>> 
>>>> 
>>>> 
>>>> --
>>>> Damien Cassou
>>>> http://damiencassou.seasidehosting.st
>>>> 
>>>> "Success is the ability to go from one failure to another without losing
>>>> enthusiasm."
>>>> Winston Churchill
>>>> 
>>> 
>>> 
>>> 
>> 
>> 
>> 
> 
> 


Reply via email to