Adding tags to people based on the content of notes in their citations(!) (Person->Event->Citation)

Gramps (was 5.1) now 6.0.6 W11pro

I asked a similar question about people and events Adding tags to people based on the content of notes in their events

The solution allowed me to list all people with e.g. a Birth event has a note containing the string “familysearch”.

Now I’d like to go even further and find e.g. all people with a “Birth” event whose citation contains a particular text (or e.g. whose citation contains 1 or more media references etc.).

I can build a “Citation Filter” (with the Citation Filter Editor) which selects just the citations I want.
e.g. All citations with Notes containing “XXXXX”, or e.g. all citations with notes contains “nli.ie” and where the citation has no media objects (count media = 0), etc. …

When I then go to then “Event Filter Editor” and assemble rules for a new filter there, I can’t seem to find any Citation/Source (or any other?) filter which allows me to use the “Citation Filter” I created above. i.e. something like the “Events with source matching the [source filter]” (which is available) but instead: “Events with citations matching the [citation filter]”.

Is there a way to do this using these tools or are there some other tools which make it possible?
(I am probably missing something obvious)

For info: I installed https://raw.githubusercontent.com/Taapeli/isotammi-addons/master/addons/gramps60 via Addons/Projects and can see the isotammi project addons… but I’m not exactly sure how/whether I can use these tools to build more complex queries

All pointers/hints very welcome :slight_smile:

All the Isotammi addons are Advanced audience. So youll need to change the Filter in the Addon Manager to see them. (Or use the middle tab to install multiple addon in a single operation. It does not have an Audience filter.)

Yes, you can build complex filters in Python with SuperTool shell. And save them for use in the Filter Gramplet instead of being limited to running them in SuperTool.

There are also SQL query shell addons. And 2 other addon shells with customized Query Languages. (one contributed by @dsblank and another by @DavidMStraub.)

Hi. I created the SuperTool addon ( isotammi-addons/source/SuperTool at master · Taapeli/isotammi-addons · GitHub ) exactly for these kinds of ad-hoc needs.

There are a couple of possibilities.

With Supertool you could create an event filter implementing “Events with citations matching the [citation filter]”. It could look like this:

[Gramps SuperTool script file]
version=1

[title]
events-with-citations-matching-a-citation-filter

[description]

[category]
Events

[initial_statements]
citation_filter_name = "my-filter"

f = filter(citation_filter_name, namespace="Citation")

def match(p):
    for c in p.citations:
        if f(c.obj):
            return True
    return False

[statements]

[filter]
match(self)

[expressions]
type,date

[scope]
selected

[unwind_lists]
False

[commit_changes]
False

[summary_only]
False

Save this as e.g. “events-with-citations-matching-a-citation-filter.script”. Change the filter name in the script as needed. Open Gramps and go to the Events view. Invoke Supertool, open the script file in Supertool and select “File > Save as filter”. Then you will have a new custom filter that can be used as any other custom filter.

You can also test the above script by executing it within Supertool.

You could also do everything in SuperTool. For example, this script will find all people with their birth event having at least one citation with at least one note containing the text “familysearch”. It should be used in the People view:

[Gramps SuperTool script file]
version=1

[title]
birth-citation-match

[description]

[category]
People

[initial_statements]
searchtext = "familysearch"

def match(p):
    for c in p.birth.citations:
        for n in c.notes:
            if searchtext in n.text.lower():
                return True
    return False

[statements]

[filter]
match(self)

[expressions]
name

[scope]
all

[unwind_lists]
False

[commit_changes]
False

[summary_only]
False

I hope this helps.

3 Likes

Thanks! This was the nudge I needed :slight_smile:

I have been using gramps since 5.1 and as time went on I always wondered if gramps was scriptable in any way.

With these tools Gramps turns out to be much more powerful than I had thought. It’s almost like a revelation :slight_smile:

1 Like

@kku provides an alternative to saving scripts as external files. And I find it more convenient.

You can paste it into a Note and then set it to the SuperTool Script custom type. (I collect these scripts by attaching them to a private ficticious person with the surname Gramps) One of the menus had an option to load scripts from Notes. By default, the list is filtered by the currently active category, keyed to the [category] in the saved script.

As a kludge coder, I need to see more than a few lines code that are visible in the SuperTool GUI. So tweaking in the Note Editor is more helpful.

Another couple hints:

  • including a [description] containing a URL (to the discussion where the script was discussed) is a good policy
  • save your scripts with [commit_changes] set to False as a “safety”. This allow you to do test runs on a temporary proxy dataset without risking your Tree. You can switch Truewhen everything tests well.