Archive for March, 2011

nametrans: renaming with search/replace

March 25th, 2011

Keeping filenames properly organized is a pain when all you have available for the job is renaming files one by one. It's most disheartening when there is something you have to do to all the files in the current directory. This is where a method of renaming by search and replace, just as in a text document, would help immensely. Something like this perhaps:

nametrans_ss

Simple substitutions

The simplest use is just a straight search and replace. All the files in the current directory will be tried to see if they match the search string.

$ nametrans.py "apple" "orange"
 * I like apple.jpg    -> I like orange.jpg
 * pineapple.jpg       -> pineorange.jpg
 * The best apples.jpg -> The best oranges.jpg

There are also a number of options that simply common tasks. Options can be combined and the order in which they are set does not matter.

Ignore case

Matching against strings with different case is easy.

$ nametrans.py -i "pine" "wood"                                                        
 * pineapple.jpg -> woodapple.jpg
 * Pinetree.jpg  -> woodtree.jpg

Literal

The search string is actually a regular expression. If you use characters that have a special meaning in regular expressions then set the literal option and it will do a standard search and replace. (If you don't know what regular expressions are, just use this option always and you'll be fine.)

$ nametrans.py --lit "(1)" "1" 
 * funny picture (1).jpg -> funny picture 1.jpg

Root

If you prefer the spelling "oranje" instead of "orange" you can replace the G with a J. This will also match the extension ".jpg", however. So in a case like this set the root option to consider only the root of the filename for matching.

$ nametrans.py --root "g" "j"
 * I like orange.jpg    -> I like oranje.jpg
 * pineorange.jpg       -> pineoranje.jpg
 * The best oranges.jpg -> The best oranjes.jpg

Hygienic uses

Short of specific cases of transforms, there are some general options that have to do with maintaining consistency in filenames that can apply to many scenarios.

Neat

The neat option tries to make filenames neater by capitalizing words and removing characters that are typically junk. It also does some simple sanity checks like removing spaces or underscores at the ends of the name.

$ nametrans.py --neat                                                                    
 * _funny___picture_(1).jpg -> Funny - Picture (1).jpg
 * i like apple.jpg         -> I Like Apple.jpg
 * i like peach.jpg         -> I Like Peach.jpg
 * pineapple.jpg            -> Pineapple.jpg
 * the best apples.jpg      -> The Best Apples.jpg

Lower

If you prefer lowercase, here is the option for you.

$ nametrans.py --lower
 * Funny - Picture (1).jpg -> funny - picture (1).jpg
 * I Like Apple.jpg        -> i like apple.jpg
 * I Like Peach.JPG        -> i like peach.jpg
 * Pineapple.jpg           -> pineapple.jpg
 * The Best Apples.jpg     -> the best apples.jpg

If you want the result of neat and then lowercase, just set them both. (If you like underscores instead of spaces, also set --under.)

Non-flat uses

Presuming the files are named consistently you can throw them into separate directories by changing some character into the path separator.

Note: On Windows, the path separator is \ and you may have to write it as "\\\\".

$ nametrans.py " - " "/"
 * france - nice - seaside.jpg -> france/nice/seaside.jpg
 * italy - rome.jpg            -> italy/rome.jpg

The inverse operation is to flatten the entire directory tree so that all the files are put in the current directory. The empty directories are removed.

$ nametrans.py --flatten
 * france/nice/seaside.jpg -> france - nice - seaside.jpg
 * italy/rome.jpg          -> italy - rome.jpg

In general, the recursive option will take all files found recursively and make them available for substitutions. It can be combined with other options to do the same thing recursively as would otherwise happen in a single directory.

$ nametrans.py -r --neat 
 * france/nice/seaside.jpg -> France/Nice/Seaside.jpg
 * italy/rome.jpg          -> Italy/Rome.jpg

In recursive mode the whole path will be matched against. You can make sure the matching only happens against the file part of the path with --files or only the directory part with --dirs.

Special uses

Directory name

Sometimes filenames carry no useful information and serve only to maintain them in a specific order. The typical case is pictures from your camera that have meaningless sequential names, often with gaps in the sequence where you have deleted some pictures that didn't turn out well. In this case you might want to just use the name of the directory to rename all the files sequentially.

$ nametrans.py -r --dirname                                                              
 * rome/DSC00001.jpg -> rome/rome 1.jpg
 * rome/DSC00007.jpg -> rome/rome 2.jpg
 * rome/DSC00037.jpg -> rome/rome 3.jpg
 * rome/DSC00039.jpg -> rome/rome 4.jpg

Rename sequentially

Still in the area of sequential names, at times the numbers have either too few leading zeros to be sorted correctly or too many unnecessary zeros. With this option you can specify how many leading zeros you want (and if you don't say how many, it will find out on its own). Based on an old piece of code that has been integrated.

$ nametrans.py -r --renseq 1:3                                                           
 * rome/1.jpg   -> rome/001.jpg
 * rome/7.jpg   -> rome/007.jpg
 * rome/14.jpg  -> rome/014.jpg
 * rome/18.jpg  -> rome/018.jpg
 * rome/123.jpg -> rome/123.jpg

The argument required here means field:width, so in a name like:

series14_angle3_shot045.jpg

the number 045 can be shortened to 45 with "3:2" (third field from the beginning) or "-1:2" (first field from the end).

Get it from sourceforge:

making hypothetical statements in italian

March 7th, 2011

A hypothetical statement is one that is speculative. It speculates on the consequences of a hypothetical event. It states what would occur if something that hasn't happened, were to happen.

Expressing hypotheticals in Italian (il periodo ipotetico) is somewhat tricky because it requires use of the subjunctive, a verb tense that takes getting used to. It is further complicated by making the chapter on this topic that you will find in textbooks overly long and confusing.

Here I will start with two solid reference points in English, so that you can see exactly what is going on. Then we'll go through some examples to see what it looks like in real world use.

Could

The first case is the could scenario.

- You've never scored a penalty.
- Yeah, but I could do it.

- You don't play the piano, do you?
- I could if I wanted to!

Got it? Okay, so we build our hypothetical from the could.  And the hypothetical describes what would happen if you did the thing that you "could do". (Or, in general, what would happen if the thing that "could happen", happened.)

- If I scored a penalty, I would celebrate.

- If I played the piano, I would play Beethoven all the time.

Here is what you need to know:

  1. The action is described using the imperfect subjunctive (il congiuntivo imperfetto).
  2. The consequence of the action is described using the conditional (il condizionale).

- Se segnassi un rigore, lo festeggerei.

- Se suonassi il pianoforte, suonerei sempre Beethoven.

Of course, you are not limited to talking about yourself.

- If it rained, they would not show up.
- Se piovesse, non si farebbero vivi.

Could have

The second scenario is all about could have.

- You lost the game!
- Yeah, but we could have won.

- Al Capone never jumped out of a window.
- Yeah, but he could have, he was that crazy.

Once again, the hypothetical starts from the thing that "could have happened".

- If we had won the game, we would have been champions.

- If he had jumped out of a window, he would have terrified his underlings even more.

In this case the tenses are different:

  1. The action is described using the pluperfect subjunctive (il congiuntivo trapassato).
  2. The consequence of the action is described using the past conditional (il condizionale passato).

- Se avessimo vinto la partita, saremmo stati campioni.

- Se si fosse buttato dalla finestra, avrebbe fatto ancora più paura ai suoi subalterni.

A slight variation on this is used if the consequence is one that is still felt today, in which case you use the regular conditional:

- If he had jumped out of a window, he would be even more famous.
- Se si fosse buttato dalla finestra, sarebbe ancora più famoso.

Examples

If you're not reading Leonardo then you really should, the guy is hilarious. In a recent entry he made a superb demonstration of the hypothetical.

I'll just quote one sentence here, but read the whole thing so you understand what is being talked about. The short version is that Berlusconi is alleged to have employed underage prostitutes, one of whom was nicknamed Ruby. Hiring a prostitute in Italy does not constitute a crime, but if the person is underage then it obviously does. Leonardo here is satirizing the kind of statements made in support of Berlusconi by various figures who more or less owe their position to him. A classic case of scandal and farce in Italian politics.

Il sesso coi cyborg non è ancora regolamentato per legge, e quindi Berlusconi (che è impotente) (e se non fosse impotente sarebbe fidanzato) (e se avesse tradito la fidanzata con Ruby, comunque non l'avrebbe pagata) (e se l'avesse pagata, comunque sarebbe maggiorenne) non può essere punito per aver fatto sesso con un cyborg.

- e se non fosse impotente sarebbe fidanzato
- and if he weren't impotent, he would have a girlfriend

- e se avesse tradito la fidanzata con Ruby, comunque non l'avrebbe pagata
- and if he had cheated on his girlfriend with Ruby, he still wouldn't have paid her for it

- e se l'avesse pagata, comunque sarebbe maggiorenne
- and if he had paid her, she would be of age anyway

norwegian to dutch primer

March 3rd, 2011

There are many interesting processes that work on languages which contribute to their change over time. Prepositions (or postpositions, in other languages) quite commonly become glued to the beginnings or ends of words (or even the beginnings or ends of roots in words). They go from being prepositions to being pre- and postfixes, and in many cases quite regular, thus prepare and prescribe (or indeed, prefix) have the same suffix pre in the sense of before/prior to. In some cases, they continue to exist both as prepositions and prefixes, in others they survive only as prefixes.

I will focus mostly on prepositions here, because they are quite instructive in mapping words from Norwegian to Dutch. They basically correspond to syllables, even if not all syllables here listed are prepositions.

It has to be said also that just because the same word exists in two languages (as described by these translations), it might not mean the same thing. I've tried as much as possible to use words that correspond both in composition and meaning.

Now, I'm quite sure that encyclopedias have been compiled of this information, but I find it more fun to notice things myself than reading the encyclopedia. The cases you will see here are by no means an exhaustive list, merely the ones I have noticed (and can recall). You will discover your own patterns (and that, in my view, is quite satisfying).

Syllable translations

av -> af/van

avfall -> afval {garbage}
avhenge av -> afhangen van {to depend on}

av -> uit

avsette -> uitzetten {to expel}
kle av -> uitkleden {to undress}

bi -> bij

bidrag -> bijdrage {contribution}
bistå -> bijstaan {to assist}

for -> ver

forgå -> vergaan {to perish}
forlate -> verlaten {to abandon}

for -> voor

forbi -> voorbij {elapsed}
forberede -> voorbereiden {to prepare}
forekomme -> voorkomen {to occur}

het -> heid

mulighet -> mogelijkheid {possibility}
nødvendighet -> noodzakelijkheid {necessity}

-ig -> -ijk

mulig -> mogelijk {possible}
nødvendig -> noodzakelijk {necessary}

opp -> op

oppstå -> opstaan {to rise}

på -> op

fallende -> opvallend {remarkable}
vente -> wachten op {to wait for}

til -> toe

tillate -> toelaten {to allow}
tilstand -> toestand {condition}

u -> on

umulig -> onmogelijk {impossible}
utrolig -> ongelooflijk {incredible}

ut -> uit

utebli -> uitblijven {to fail to appear}
uttrykk -> uitdrukking {expression}

Consonant changes

I think most of these are pretty obvious, because the sound you hear is very similar, so it's more a spelling change than a sound change.

f -> v

falle -> vallen {to fall}
fare -> gevaar {danger}

k -> ch

makt -> macht {power}
vitenskap -> wetenschap {science}

kj -> k

kjenne -> kennen {to know}
kjøkken -> keuken {kitchen}

s -> z

svømme -> zwemmen {to swim}
synge -> zingen {to sing}
sønn -> zoon {son}

hv/v -> w

hvilken -> welk {which}
hva -> wat {what}
gevinst -> gewin {winning}
vinner -> winnaar {winner}

Vowel changes

The vowels are more substantial. Going from lyd to geluid is y to au in Norwegian phonology, which is pretty big. Dutch is packed to the brim with diphthongs (a single vowel that actually goes from one sound to another, like "au" or "ei", typically spelled with two letters), so there is a huge amount of these that you have to learn to match with their spellings.

e -> ei

egenskap -> eigenschap  {property/attribute}
kreativitet -> creativiteit {creativity}

i -> ij

bli -> blijven {to remain}
fri -> vrij {free}
tid -> tijd {time}

o -> oe

million -> miljoen {million}

u -> ui

bruk -> gebruik {use}

y -> u

fylle -> vullen {to fill}
fyre av -> afvuren {to fire off}

y -> ui

lyd -> geluid {sound}
tydelig -> duidelijk {clear}

æ -> ee

ærbødig  -> eerbiedig {reverential}
ære -> eer {honor}
ærlig -> eerlijk {honest}

ø -> eu

seriøs -> serieus {serious}

ø -> oe

prøve -> proef {test}
søke -> zoeken {to search}
øve -> oefenen {to rehearse}

å -> aa

gå -> gaan {to go}
måltid -> maaltijd {meal}
slå -> slaan {to hit}

Decoding

So how does it work in practice? If you're learning Dutch it won't take very long before you see the common word onwaarschijnlijk. At first sight it's a pretty scary word with crazy vowel combinations. But if you take the above list and work in the opposite direction you discover than you can split off on which is a negation. You now have something that begins with waar and since that is also a common word you probably already know that it means sann {true}. You also know that lijk is a common suffix that corresponds to lig (which is used in adjectives), so with the parts you have you can make usann-lig, which in all probability completes to usannsynlig {improbable, more literally: not-true-looks-like}. You check the context and confirm that it has to be an adjective, and that this meaning fits well.

As a matter of fact, this is exactly how I understood the word the first time I saw it. This is actually quite a good example, because it shows how you can do this with partial knowledge. There are two parts with perfect correspondence, on/u and lig/lijk. But waar is a different root from sann, and this I had to know about. I did not use schijn at all, because it didn't look like anything I knew. But I now know that it would have been a blind alley, because synlig {visible} does not correspond to schijnlijk (which is not even a word). schijnen means to seem, which I didn't know at the time.

A similar example is ongelooflijk = utrolig, where you need to know that geloof = tro {belief}, thus "unbelievable".

Now, you might think that trying to painstakingly work this out on paper sounds about as appealing as cleaning a warehouse with a toothbrush. But, of course, the point is that your brain does this to a great extent unconsciously. Sometimes you think you understand a word and you can't even figure out why, it must somehow have found an association that you're not conscious of.