Showing posts with label regular expressions. Show all posts
Showing posts with label regular expressions. Show all posts

Wednesday, October 30, 2013

Bulk edit, character formatting, and regular expressions

I am continuing to proofread and correct the Copala Triqui online dictionary at copalatriqui.webonary.org.

One error that crept in at some point was the use of the wrong character styles for accented letters and anything that follows them.  (I think perhaps I cut and pasted these examples from a Word document...)  Consider the following entry:


In this entry, the accented characters are smaller than the characters before them in a way that looks odd.

In FLEx, I found that these characters don't have the default paragraph type, but instead are in a character style called "Character Style 2".  Checking on Character Style 2, I see that it is 12pt, while the Normal Text style is currently set at 16.  I change the Normal style up and down depending on what screen is being used; when we project the entries on the wall for work with our language consultant, I set it to a large font for better visibility.

 I suppose I could have redefined the font characteristics of Character Style 2 to 16pt, but it seemed to me that it would be a pain to always have to remember to change both the Normal Style and Character Style 2.

After trying various regular expressions, I found that this one gives the desired results:


The parentheses set up a capture group, which is referred to by the variable $1 in the Replace With field.  So this regular expression says "look for any character in áéíóúńj with Character Formatting 2 and make that the 1st variable" then "replace it with the 1st Variable but with Default Paragraph Characters format"

Some notes:
  • I included n and j because the phonotactics of Triqui make these the only consonants that would follow an accute accent
  • You can access the formats under the Format button. It seems like you need to select the whole Find or Replace string first to apply this format.
  • In the Bulk Replace window, I set Example Sentences as the Target Field.
After doing this, I exported the project as XHTML again and uploaded it to Webonary.  Here is the same entry after the changes:


Saturday, March 2, 2013

More examples of regular expressions in FLEx

This regular expression is used to help me separate out the right allomorph of the habitual prefix of the Colonial Valley Zapotec verb.  The habitual aspect comes in a few allomorphic variants, which are orthographically usually written <te, to, ti>.  I want to strip this from the citation form and put it in a separate field called Cordoba habitual form.

The procedure is to copy the whole citation form to the Cordova habitual form, then use a regular expression in bulk edit to remove everything except the prefix.   The following search and replace comes fairly close to what I want:


This bulk replace operation looks for the beginning of the record (^), then any number of characters (.*), then t followed by one character (\w).   I put the sequence t & one character inside the capturing parentheses, because I want to be able to refer to it in the Replace operation on the next line.
After the parenthesis, I have any number of characters (.*) and the end of the record ($).

This is replaced by t, whatever the letter that was captured in the previous parenthesis was ($1) and a hyphen.

So if the first line finds   blah blah ti+capaya blah blah  it will be replaced by ti-.

This mostly works -- except that the way the original Cordova entries came to me, there are sometime several Zapotec verbs listed together in a single entry; possibly with differential potential prefixes.  So I have to give the results a visual inspection to make sure nothing has gone wrong before hitting the Apply button in Bulk Edit.  If there is a record where this will give the wrong result, I can just uncheck it, and edit it manually.


The counter part to this regular expression is the one that takes the citation form, strips off the habitual prefix and returns just the portion minus that prefix.   The search and replace that will do that is the following:



The Find expression looks for a t followed by one word-forming character and a literal (+) at the beginning of a record (^).  It starts to capture everything from here to the end of the record ($) and stores it in the variable $1.   When this search and replace is applied, the effect is to take a word like

ti+capaya

and replace it with capaya.

Friday, March 1, 2013

More sophisticated regular expression searching in the Cordova

I am not a computational linguist, by any means, but I have slowly been learning enough about regular expressions to be able to do some useful things with FLEx.  One aspect just learned is how to use regular expressions in search and replace operations in FLEx.  (The FLEx help menus are not really very explicit on this.)

In a FLEx search and replace function — in Bulk Edit, for example — each thing that is enclosed in parentheses will return some set of results, called a capture.  You can refer to this capture with the variable $.  So the material in the first set of parentheses is $1.  The material in the second capture is $2, and so on.   Here is an example of how I used this information in the Colonial Valley Zapotec database.


Córdova normally cites a verb in the 1st person habitual.  Depending on the allomorph of the verb, the habitual of the verb might be /ti, to, te/.  The verb root will usually be four to eight letters long.  And the first person will end in /a/.

So if the form cited is tichapa, I would like it to be segmented ti+chap-a.

The "Find what" on the first line sets up a first capture group, which is the prefix, made up of t plus either e, i, or o. (Elements between square brackets are options.)  Because this whole first unit is between parentheses, it is capture group one, which I can refer to as $1 in the "Replace With" line below.

I want to replace it with the same thing, followed by a + to show the boundary.

The next capture group is a group of letters (shown by \w — meaning any wordforming character), and I have shown the number as between 4 and 8.  (On second thought, perhaps the lower number should have been three…)

Since this is the second capture group, I can refer to it by $2, in the "Replace With" line, and this time I replace it with the same thing, followed by a hyphen.

This is a first attempt at using the regular expressions with FLEx, but I think I can already see how they are going to make it possible to accomplish more sophisticated data manipulation as we try to get the Córdova diccionario into a format that we can understand.