Listing Apertium element using command-line

From Apertium
Revision as of 21:34, 17 February 2019 by Bech (talk | contribs) (→‎Listing a project branche: New command-line, the previous one stopped working)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

En français

Changes in Apertium implementation mode

Originally, or at least for ten years, the Apertium project was archived on sourceforge using subversion software.

The project was then organised as a tree :

  • The repository apertium directory only countained subdirectories called branches.
  • Each branche included several subdirectories and each of them contained one of the following three elements:
    • Apertium project software,
    • a language pair,
    • the reference files for a language.

Language pairs, could be implemented into 4 distinct subdirectories (incubator, nursery, staging et trunk) according to their progress.

In the current Apertium implementation, any project element is directly located in a first level subdirectory of "apertium" ( and branches, and branches, which corresponded to first level subdirectories:

  • apertium-incubator
  • apertium-nursery
  • apertium-staging
  • apertium-trunk
  • apertium-languages
  • apertium-tools

only countain a list of project elements.

Listing a project branche

To get the list of elements in a branche, you just need to download the web page :<branche_name>/blob/master/.gitmodules

and extract lines containing "submodule" , or lines containing '<span class="pl-e">' (it seems to be the same ones).

Then, you need to keep only project elements from the extracted lines.

Code example to get data from lines containing "submodule" :

motifsed='<span class="pl-e">'
wget -q$1/blob/master/.gitmodules
fgrep "submodule" .gitmodules | sed "s/.*$motifsed// s/<\/span>.*//" | sort
rm .gitmodules*

Call example (assuming the command is called branchlist)

branchlist trunk

Date of last change for a project element (trivial method)

This method also consists in retrieving information from a web page. This is the page:<element_name>

You will need to retrieve date and hour fron line containing "pushed_at"

Code example :

wget -q$1
fgrep "pushed_at" $1 | sed "s/.*: \"// s/T/ / s/Z.*//"
rm $1

This system works fine with recently changed Apertium project elements. However, for the other elements, you will never get a date prior to March 2018. The reason is the Apertium project was transferred from sourceforge to github in March 2018.

For the elements not updated for a long time, it is possible to use the command svn list and to take off referencies to git repository files (their name stard by a . ) before searching the most recently changed.

Listing file and subdirectories of a project element

To list file and subdirectories of a project element, you can execute the command svn list -v on the trunk subdirectory (!!!) of this element.

For example, for the apertium-fra language:

svn list -v

The one line message appearing at the beginning may be deleted, as git files and reference to the current directory whose names start by a .

If you call the command svn list on a non existing element, subversion will ask for pa password. This problem can be avoided by setting standard input to /dev/null

Code example :

svn list -v$1/trunk < /dev/null | fgrep -v " ." | tail -n +2

Date of the last change for a project element (using svn)

Solution using svn list -v

To find the date of the last change for a project element, you just need to search into the result of a svn list command the last file which was changed. For the Apertium project, the important changes are in the root directory of the project element. The contents of subdirectories will not be examined.

However, with the svn list -v command, there are two issues for displaying dates:

  • An abbreviated month name is displayed, that would be easier with a month number
  • For files changed during the last 6 months, we get the time of the change instead of the year. The change may have occurred this year or at the end of the previous year.

It will be necessary to change displayed dates to solve these problems. These changes can be done using 2 sed commands and by creating two sedfiles.

The first of this sedfile will depend on the language used to display month names. If the display is in English (that can be forced doing LANG=en_US.UTF-8), it will be possible tu use the following numbering_month file:

s/ Jan / m01 /
s/ Feb / m02 /
s/ Mar / m03 /
s/ Apr / m04 /
s/ May / m05 /
s/ Jun / m06 /
s/ Jul / m07 /
s/ Aug / m08 /
s/ Sep / m09 /
s/ Oct / m10 /
s/ Nov / m11 /
s/ Dec / m12 /

A second sedfile will generate a year number before the month number. The contents of this file will change every month. A first script will be used to generate it:

year=`date +%Y` changemonth=`date +%m`
> year_month
while [ $month -le $changemonth ] do echo "s/ m$month /$year $month /" >> year_month month=`expr $month + 101 | cut -c2-` done
year=`expr $year - 1`
while [ $month -le 12 ] do echo "s/ m$month /$year $month /" >> year_month month=`expr $month + 101 | cut -c2-` done

The main script principal to fetch the last modification date of the project element will proceed as follows:

  • do a svn list -v on the trunk subdirectory of the element
  • take off files and directories whose name starts by a .
  • reorder columns to get a year month day filename display (warning, for subdirectories ((identifiable by a / after the name) the field file_size is empty)
  • replace abbreviated month names by m followed by a month number (using 2 digits)

Then, there are two possibilities:

1) All the files are at least 6 months old: every line start with the year.

In this case, lines are sortered by alphabetical order. The most recent date is the date for the file (or the subdirectory) which appears on the last line.

2) Several files were changed during the 6 last months. We can see lines starting by the time of the change which includes : symbol

In this case, it is enough to look at theses files. The time at the beginning of the line will be took off and replaced by the year. Then after an alphabetical sort, the date appearing on the last line will be selected.

The script doing this process is the following:

list1=/tmp/listpair1_$$ list2=/tmp/listpair2_$$
svn list -v$1/trunk < /dev/null | fgrep -v " ." | tail -n +2 > $list1
grep -v "/$" $list1 | awk '{print $6 " " $4 " " $5}' > $list2 grep "/$" $list1 | awk '{print $5 " " $3 " " $4}' >> $list2
sed -f numbering_month $list2 | sort > $list1
fgrep : $list1 > $list2
if test -s $list2 then cut -c6- $list2 | sed -f year_month | sort | tail -1 | awk '{print $3 " " $2 " " $1}' else tail -1 $list1 | sed "s/m//" | awk '{print $3 " " $2 " " $1}' fi
rm $list1 $list2

Solution using svn list --xml

With this option of the svn command, the file name and the last change date appear on separate lines and are surrounded by XML tags.

These lines will have to be selected and put together.

As previously, after taking off lines containing files whose name starts by a . keeping only the date and doing an alphabetical sort, the last date apearing is the one to display.

Here is an example of a script doing the process.

svn list --xml$1/trunk < /dev/null | egrep "<(nam|dat)e>" | paste - - | fgrep -v ">." | sed "s/.*<date>//" | sort | tail -1 | cut -c1-10

In this example, the date appears using year-month-day format.

It would be easy to change the display as day/month/year and also to display the update time that would appear if display was not truncated to the first 10 characters.