domingo, 9 de agosto de 2015

New ISO 3166-1 implementation for Pharo Smalltalk


If your application lists any of Yugoslavia, Czechoslovakia, South Yemen, USSR, Serbia and Montenegro countries then you have an obsolescence problem. The same as if it doesn't known about South Sudan, Jersey or East Timor.

Geopolitical map has changed, countries around the world have dissolved, merged and new ones were created. As of August 2015, ISO web site lists 249 official countries. Unfortunately their list is not made available free of charge, but there are a few reliable places where its lists is available (ex: Wikipedia).

To keed updated regarding world political situation and providing more features, I developed an ISO 3166-1 wrapper to access objects into a ISO3166 model. This is, including only information contained in the ISO standard, not calling codes, not language tags or other data located at external standards. Installation instructions, usage and reference links are provided in this document. Code is in the SmalltalkHub repository. The Metacello Configuration is accessible from the Pharo Configuration Browser, in Pharo 4 (released in 2015), or Pharo catalog in Pharo 5 (to be released in 2016).

Documentation is available in PDF format. Suggestion, fixes and improvements are very welcome. Don’t hesitate to contribute if you want to add new features.


To get a sorted Collection with all ISO-3166 codes:
ISO3166P1 sortedIso3166Codes.
To obtain a Collection of all the countries with all ISO-3166 country names:
ISO3166P1 sortedCountryNames.   " a SortedCollection('Afghanistan' 'Albania' 'Algeria' ... "
Get an ISO3166P1Code of France from 2-letter or 3-letter code:
ISO3166P1 atLetterCode: 'FR'.
ISO3166P1 atLetterCode: 'FRA'.  " an ISO3166P1Code (France) "
Obtain a String with the ISO 3166 code number for Zimbabwe:
ISO3166P1 codeNumberFrom2LetterCode: 'ZW'. "716"
Obtain the three-letter String country code of Niger:
(ISO3166P1 atCountryName: 'Niger') codeThreeLetter. " 'NER' "
(ISO3166P1 atCountryName: 'nIGeR') codeThreeLetter. " 'NER' "
Obtain the two-letter String country code of Burundi:
(ISO3166P1 atCountryName: 'Burundi') codeTwoLetter. " 'BI' "
Obtain a String representing the country code top-level domain of Denmark:
(ISO3166P1 atCountryName: 'Denmark') ccTLD. " '.dk' "

miércoles, 15 de abril de 2015

Iliad 0.9.4 is out


I have updated the Iliad Web Application Server to load properly in Pharo 4 (good tutorials here and here). All tests passes. As usuall you can load it from the Configuration Browser or by evaluating the expression:
Gofer it
 smalltalkhubUser: 'hernan' project: 'Iliad';


Start the Iliad Web Application Server in port 8888 using the Comanche/Kom Web Server adapter:
IliadKom startOn: 8888.
And point your browser to: http://localhost:8888/ Stop all servers:
IliadKom stop.
If things go bad you can start Iliad in Debug Mode:
IliadKom startDebugOn: 8888.
and enjoy the opened Debugger in the signaler method when an exception is signaled.


  • Use the Grease latest stable version which includes a fix of the #next: method in GRPharoUtf8CodecStream (thanks Benoit Astruc)
  • Added ILTempFile helper methods (#printOn: and #extension).
  • Added ILCaptionElement and ILDatalistElement (thanks Benoit Astruc).
  • Added methods to start Comanche in debug and verbose mode.
  • Changed HttpService name to be more descriptive in the Process list.
  • Removed versions for GemStone and Squeak in ConfigurationOf (will add later after check)
  • Use convertToEncoding: instead of #decode: to patch the Invalid UTF-8 bug.
  • Replaced Pharo 4 deprecated TimeStamp with DateAndTime.
  • Replaced senders of Pharo 4 deprecated #displayString with #asString.
  • Updated acknowledgements windows and text.

viernes, 27 de febrero de 2015

LanguageDetection API Client in Smalltalk


Language Detection API is a service to query the language of a given input text. You will need to register an API key in the web site to use the service. This client enables to use the service from Pharo Smalltalk. The output is an object containing the language code, a confidence score and a 'is reliable' boolean value.


Inside Pharo, open the Configuration Browser and select LanguageDetection, then Install. Or evaluate the following expression:
Gofer it 
 smalltalkhubUser: 'hernan' project: 'LanguageDetection';
 configurationOf: 'LanguageDetectionAPI';


| ldClient |
ldClient := LDApiClient new.
 query: 'Des perles de pluie venues de pays où il ne pleut pas'; 
 query: 'Een enkele taal is nooit genoeg ';
 query: 'buenos dias señor';

miércoles, 25 de febrero de 2015

StNER: Interface to the Stanford Named Entity Recognizer


StNER provides a Pharo Smalltalk interface to the Stanford Named Entity Recognizer (NER). The Stanford NER recognizer is an implementation of a Named Entity Recognizer, used for tagging raw text which is a central task in Information Retrieval and Natural Language Processing. The input is a sequence of words in a text, and the NER classifier - using already trained data - try to recognize typically three types of "Named Entities" (NEs) : NAME, LOCATION and ORGANIZATION (more classes exists). The output is the tagged text in some common tagging format for tagging tokens. This recognizer works better on input more similar to the already trained labeled data sets (muc6, muc7, conll2003), however there are reports to use it with tweets, and you can retrain to recognize entities for your particular needs.

To recognize text in other languages, for example, Chinese, German, or Spanish, a different classifier (in this context a .tgz file) can be used (see NLP Stanford Demo).


  • Java is required to run the server locally.
  • Download the Stanford NER packages.
  • Inside Pharo, open the Configuration Browser and select StNER, then Install. Or evaluate
    Gofer it
     smalltalkhubUser: 'hernan' project: 'StNER';
     configurationOf: 'StNER';

Launch the server

  • Start (from Smalltalk) the (Java) server using the StNER Smalltalk server interface. For example, to start the server with default parameters in Windows:
    StSocketNERServer new
        stanfordNERPath: 'c:\stanford-ner-2015-01-30\';
  • Query an input text using the StNER Smalltalk client interface.

Server Settings

Providing path location is mandatory. If no host or port is supplied, defaults to:
  • localhost (,
  • port 8080
  • JVM memory 1000m.
  • output format: inlineXML

You can configure the server with the following taggers:
  • 3 class NER tagger that can label: PERSON, ORGANIZATION, and LOCATION entities. (#setEnglish3ClassTagger)
  • 4 class NER tagger trained on the CoNLL 2003 Shared Task training data that labels for PERSON, ORGANIZATION, LOCATION, and MISC. (#setEnglish4ClassTagger)
  • 7 class NER tagger trained only on data from MUC (#setEnglish7ClassTagger): TIME, LOCATION, ORGANIZATION, PERSON, MONEY, PERCENT, DATE.

Client Usage

To tag text you can use the #tagText: method as follows:
StSocketNERClient new 
  tagText: 'University of California is located in California, United States'
and the output will be:
'University of California 
is located in California, 
United States' "
Another example including PERSON tagging:
StSocketNERClient new 
 tagText: 'Argentina President Kirchner has been asked to testify in court on the death of Alberto Nisman the crusading prosecutor who had accused her of conspiring to cover up involvement of Iran'
which results in:
'Argentina President Kirchner has been asked to testify in court on the death of Alberto Nisman the crusading prosecutor who had accused her of conspiring to cover up involvement of Iran'
Parse text to in-line XML
StSocketNERClient new 
  parseText: 'University of California is located in California, United States'
results in a Dictionary of Bag's with occurrences of tagged classes.

martes, 24 de febrero de 2015

GADM: Access to Global Administrative Areas in Smalltalk


GADM is a high-resolution spatial database of the location of the world's administrative areas for use in GIS and similar software. GADM is freely available for academic and other non-commercial use. The data contained in GADM was collected from spatial databases provided by NGO, National Governments, and/or maps and list of names available on the Internet (e.g. from Wikipedia).

Administrative areas include: countries, provinces, counties, departments, etc. up to five sublevels, which cover most boundaries in the world. For each level it provides some attributes, foremost being the name and in some cases variant names. GADM can also be used to extract polygon shapes for visualization, for example to build choropleth maps for regions. The GADM package includes the raw data in CSV format, which I parsed to build a browseable GADM world tree, allowing off-line access to the GADM database in a hierarchical fashion with objects, without need to perform on-line queries for basic requests. A hierarchical tree can be used to build a toponym browser for example.


From within Pharo 3, or Pharo 4 you can use the Configuration Browser, or evaluate the following expression:
Gofer it
 smalltalkhubUser: 'hernan' project: 'GADM';
 configurationOf: 'GADM';

Usage Examples

" To access to the whole World (as seen by GADM), evaluate "
GADMWorldTree root.

" Access country Lithuania "
GADMWorldTree @ 'Lithuania'.

" To acces the Part (Partido: spanish) where I am living:"
GADMWorldTree @ 'Argentina' @ 'Buenos Aires' @ 'La Plata'.

" You want to know which type of region is Los Angeles "
(GADMWorldTree @ 'United States' @ 'California' @ 'Los Angeles') typeName " 'County' "

" You wish to list all subregions in San Marino "
(GADMWorldTree @ 'San Marino') nodeNames
 " a SortedCollection('Acquaviva' 
'Borgo Maggiore' 
'San Marino' 
'Serravalle') "

sábado, 7 de febrero de 2015

Application Security 3: Setting your password rules

The post you are reading is about password enforcement rules in the Application Security package, released as Open Source on March 2014 for the Pharo Smalltalk community. Rules which you can set up are:
  • Increase the password length, which results in increasing the number of combinations search space.
  • Increase the size of character set, to increase the number of password combinations.
The default character set in the Application Security package, includes uppercase and lowercase letters, numbers and a set of non-letters. This forms a 95-character set as recommended by the FIPS, and if passwords are between 5 and 8 characters, a brute-force attack would have to guess between 7.7 billion to 6.6 quadrillion combinations. It is possible to change the password creation rules by creating checkpointed validation settings:
| settings |
settings := ASValidationSettings forCheckPoint: ASDeployCheckPoing new.

" Set my passwords will allow up to 14 characters "
settings maxPasswordCharacters: 14.

" Set the user name character length maximum "
settings maxUsernameCharacters: 14.
You can also change the default character set allowed by user names. The default is the result of evaluating:
ASValidationSettings defaultUsernameCharactersList 
  evalString gather: [ : c | c ].

" but for convenience, you should grab the 
#defaultUsernameCharactersList method and customize for your purposes:

{ '$0 to: $z' . '$A to: $z' . '$a to: $z' . 
  '($0 to: $9) , ($A to: $Z) , ($a to: $z)' . 
  '($0 to: $9) , ($A to: $Z) , ($a to: $z) , 
  #($_ $- $.)' } "
Continuing with the validation settings example, this is how you do it:
settings allowedUsernameCharacters: {'$A to: $z' . '$a to: $z' }.

" and the same could be achieved for password characters : "

settings allowedPasswordCharacters: ...
Recent password research, have claimed that using passphrases increase the combinations needed by brute-force attacks, but there is more chance of making typographical mistakes, and so is good practice to increase the number of allowed failure attempts. This can be done in Application Security by evaluating:
" Set the maximum count of allowed fails per user during a period of time "
" Default is 40 "
settings maxUserFailCount: 5.

lunes, 2 de febrero de 2015

Pharo Smalltalk Scripts, part 1

These are some scripts and tips I used in my daily developement with Pharo Smalltalk in the last years. Hope you find them useful:

Parsing XML with DOM

You can instantiate and parse a XML DOM parser with one line of code:
(XMLDOMParser parseFileNamed: 'fao_country_names.xml') 
  allElementsSelect: [ : each | 
    each localName = 'geographical_region' ].


You can quickly parse a CSV file using NeoCSV with just a snippet for most tasks:
(NeoCSVReader on: 'myfile.csv' asFileReference readStream)
 separator: Character tab; 
 do: [ : row | " do something with row " 
      third ]
or using a one-liner
'myfile.csv' asFileReference readStreamDo: [ : stream | 
  (NeoCSVReader on: stream) upToEnd ]

Lorem Ipsum

You already have the first paragraph of "Lorem ipsum" available in Pharo.
String loremIpsum


If you are developing UI you can have the Time Profiler (Pharo) opened in any method by enclosing your code between:
 TimeProfiler new openOnBlock: [ 
   " Your code ... "

Open File Dialog

Opening a File Dialog for specific file type is a one-liner:
UIManager default chooseFileMatching: #('*.xml').


Spec is a relatively young UI Specification library. You can prototype UI's easily by using Dynamic Composable Models, for example:
| view layout |
" Configure the Spec models "
view := DynamicComposableModel new
        instantiateModels: #(labelA LabelModel textA TextInputFieldModel labelB LabelModel textB TextInputFieldModel);
        extent: 500@200;
        title: 'Title'
" Configure the Spec layout "
layout := SpecLayout composed
        newColumn: [ : r | r
                add: #labelA; add: #textA;
                add: #labelB; add: #textB ];
" Set up the widgets "
view labelA text: 'A'.
view labelB text: 'B'.
" Open the Window "
(view openDialogWithSpecLayout: layout)
        modalRelativeTo: World.

Morphic Window and Controls

If you need a basic container Morph window, just evaluate:
| s |
(s := SystemWindow labelled: 'Window')
 s addMorph: (StringMorph new
  contents: 'Comments:';
  color: Color black)
   frame: (0@0.0 corner: 1@0.2).
But you can have a control like a TextArea without container
| o ptm |
o := Object new.
ptm := PluggableTextMorph on: o text: #printString accept: nil.
ptm height: TextStyle defaultFont height + 6.
ptm acceptOnCR: true; openInHand.
And instantiated differently
(PluggableTextMorph on: Workspace new
 text: #contents
 accept: #acceptContents:
 readSelection: nil
 menu: #codePaneMenu:shifted:) openInHand.


Udo Schneider recently wrote an FTP/WebDAV Plugin for the Pharo FileSystem, and you get almost for free a FTP client using the File Browser
fs := FileSystem ftp: ''.
FileList openOn: fs workingDirectory.
fs close.

jueves, 15 de enero de 2015