* Add "County" to second place field

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
User avatar
BakerJL75
Famous
Posts: 201
Joined: 14 Dec 2020 11:29
Family Historian: V7

Add "County" to second place field

Post by BakerJL75 »

My places are CITY, COUNTY, STATE, UNITED STATES very consistently. If something doesn't exist, it gets , space, ie:
CITY, , STATE, UNITED STATES or , COUNTY, STATE, UNITED STATES.

I would like to add the word County to the 2nd field, COUNTY. So Brown becomes Brown County, etc.

I can reduce the work using search and replace, but there are many single instances which will need manual editing.

Is there an easy way to just add "space County" to all locations in the number 2 field? Preferably only for places ending in United States. But even if it does every Country it would be a lot less work to edit that back out than to manually add County, as the vast majority of my Places are in the US.

I'm assuming it would be the Search and Replace field plugin with LUA, but can't figure out the details.
Thanks,
Jackie
User avatar
tatewise
Megastar
Posts: 28333
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Add "County" to second place field

Post by tatewise »

Yes, I think the Search and Replace plugin in Lua Pattern mode should be able to cope.

So the Search must match CITY, COUNTY, STATE, UNITED STATES where the first three column parts might be empty.
Therefore, the pattern will be something like:
^.*, .+, .*, UNITED STATES$
where ^ and $ anchor the pattern to the start and end of the Place name, although probably not strictly necessary.
It assumes that each comma is always followed by a space.
.* will match any character sequence including no characters, so CITY and STATE can be anything or nothing.
.+ will only match one or more characters, so COUNTY must exist and an empty column won't match.

That is the pattern, but the variable CITY and COUNTY and STATE text must be captured for use in the Replace field.
^(.*), (.+), (.*), UNITED STATES$

The Replace field will be something like:
%1, %2 COUNTY, %3, UNITED STATES

You typed everything in uppercase, so I've done the same in the patterns, but you must use whatever is actually appropriate.
e.g. County and United States

Backup before using, although the automatic Snapshots should offer a suitable recovery option.

I have not actually tested that pattern but I'm confident it should work.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
BakerJL75
Famous
Posts: 201
Joined: 14 Dec 2020 11:29
Family Historian: V7

Re: Add "County" to second place field

Post by BakerJL75 »

Something isn't working quite right. To make it simpler, I made a dummy database with only one place:

Wichita Falls, Wichita, Texas, United States

Search Criteria: ^.*,·.+,·.*,·United·States$

Replace: %1,·%2·County,·%3,·United·States

Search only is fine. When I run Search and Replace I get

[string "C:\ProgramData\Calico Pie\Family Historian\Pl..."]:3584: invalid capture index %2
Thanks,
Jackie
User avatar
tatewise
Megastar
Posts: 28333
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Add "County" to second place field

Post by tatewise »

That is because you have forgotten to add the capture parentheses ( ) as instructed.

^(.*), (.+), (.*), United·States$
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
BakerJL75
Famous
Posts: 201
Joined: 14 Dec 2020 11:29
Family Historian: V7

Re: Add "County" to second place field

Post by BakerJL75 »

I'm sorry. I should have caught that.

Thank you, you are a life saver.
Thanks,
Jackie
User avatar
BakerJL75
Famous
Posts: 201
Joined: 14 Dec 2020 11:29
Family Historian: V7

Re: Add "County" to second place field

Post by BakerJL75 »

That worked, kind of. Same example, after I run Search and Replace I end up with two places. And I experimented, it's because my original place had latitude/longitude. The replacement place does not. I'm not sure there is any way around this. I suspect I will have to decide which is more important to me. Adding County or keeping my lat/long. Although I can always use the Map Life Facts to put them back. Thought I'd post just in case you have an ideas.
Screenshot 2021-04-21 111841.png
Screenshot 2021-04-21 111841.png (46.78 KiB) Viewed 3081 times
Thanks,
Jackie
User avatar
tatewise
Megastar
Posts: 28333
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Add "County" to second place field

Post by tatewise »

The latest version of Search and Replace should not do that. Which version are you running?
Does it tell you there is a later version in the Plugin Store?
It should change the existing Place record Text name and retain the Lat/Longitude values.

Earlier versions of the plugin exhibited exactly the symptoms you have posted.
There is a workaround but the latest version is the easier path.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
BakerJL75
Famous
Posts: 201
Joined: 14 Dec 2020 11:29
Family Historian: V7

Re: Add "County" to second place field

Post by BakerJL75 »

I'm running 3.3
That's the latest I see in the Store.
Thanks,
Jackie
User avatar
tatewise
Megastar
Posts: 28333
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Add "County" to second place field

Post by tatewise »

What are your plugin Major Options tab settings?
Search Scope: All Records & Events/Attributes or Place Records (_PLAC) are OK but anything else won't work correctly.
Basic Filters: Place fields must be ticked.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
BakerJL75
Famous
Posts: 201
Joined: 14 Dec 2020 11:29
Family Historian: V7

Re: Add "County" to second place field

Post by BakerJL75 »

All Records & Events/Attributes and Place Fields
Screenshot 2021-04-21 111841.png
Screenshot 2021-04-21 111841.png (106.26 KiB) Viewed 3058 times
Thanks,
Jackie
User avatar
tatewise
Megastar
Posts: 28333
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Add "County" to second place field

Post by tatewise »

I've just had a thought that it would be safer to set Search Scope: Place Records (_PLAC)
Otherwise, it could upset some Place fields. Sorry, I should have suggested that to start with.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
BakerJL75
Famous
Posts: 201
Joined: 14 Dec 2020 11:29
Family Historian: V7

Re: Add "County" to second place field

Post by BakerJL75 »

If I do that I get No matching data items have been reported.
Thanks,
Jackie
User avatar
tatewise
Megastar
Posts: 28333
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Add "County" to second place field

Post by tatewise »

We'll get there eventually :D
Please tick the All other Text fields option. I've just double-checked and that does work.

It is because the Place records don't actually have a Place field and the Place name is in a TEXT field!
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
BakerJL75
Famous
Posts: 201
Joined: 14 Dec 2020 11:29
Family Historian: V7

Re: Add "County" to second place field

Post by BakerJL75 »

That worked! Thank you so much.
Thanks,
Jackie
User avatar
tatewise
Megastar
Posts: 28333
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Add "County" to second place field

Post by tatewise »

Sorry, it took so long Jackie. I'll try and do better next time :lol:
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
Post Reply