I really need a Citations filter which gives the Citations belonging to a Subset of people

I am being extremely pedantic, so please do not take offence at anything I say here.
I have read the above answer by PLegoux several times and I do not understand what it is doing. It looks to be a work-around the problem of only one filter works. I would have to drop the use of Active Person. Use a “Descendants of my 4/Gt Grandfather” as the initial filter and then I get lost.

I was hoping for a solution like

[initial_statements]
# Results is a system variable which feeds the next filter
Results = filter("activeperson", namespace = "Person")
# there may be a conflict here with Results being both i/p and o/p, not insoluble
Results = filter("activepersondescendants", namespace = "Person")
Answer = filter("eventsofactivedescent", namespace = "Event")

I think the gramps filters work in similar way with the second filter having to find the output of the first (in a known location).
I must admit, I have no idea if it would work with a Y system where two branches merge into one.

Having said all that I shall have a go with PLegoux answer and see what it does.

1 Like

Yes, I should include the namespace as a global setting.

Actually you could also use

uistate.viewmanager.active_page.get_category()

which returns the ‘category’ (DashBoard, People, Families etc).

I will probably add both namespace and category as new global variables. Thanks.

1 Like

In your case, you have to test it like that:

[Gramps SuperTool script file]
version=1

[title]
SuperTool-Citations - Citations matching citations in another namespace filter results

[category]
Citations

[initial_statements]
filter_ns = "Event" # Valid values: Person, Event, ...
filter_name = "eventsofactivedescent" # Any filter name defined in previous namespace

ns_proxy = filter_ns + "Proxy"
ns_with_citations = ["Person", "Event", "Place", "Media", "Family"]
authorized = True if filter_ns in ns_with_citations else False
if authorized:
    try:
        sel_objects = filter(filter_name, namespace=filter_ns)
    except:
        authorized = False

[statements]
found = False
if authorized and filter_ns != namespace:
    for c in citators:
        if type(c).__name__ == ns_proxy:
            if sel_objects(c):
                found = True
                break

[filter]
found

[expressions]
source.title, page

[scope]
all

[unwind_lists]
False

[commit_changes]
False

[summary_only]
False

Only the two first lines of Initial statements need to be changed:

  • the first one to say where is the filter you want to run
  • the second to say what is the filter name you want to search for citations in its filtering results

If after running it it’s okay for you (it shows 3 columns: citation id, source title and citation page use by filtered objects), save it as a Citation filter, then run it as any regular filter

I’m using SuperTool 1.2.5
and with your latest script I get
AttributeError: ‘NoneType’ object has no attribute "uistate’

It fails at Citation ID C00000

Some of my Events have no Citations, would that be the cause.

I noticed that SuperTool (I use the same version as you) doesn’t like active person filter (ST even created its special one). Try in your activeperson filter to replace active person filter with another filter with that person’s id, or use bookmarked persons filter and bookmark the active person (this one have my preference), I think it will work better

If events have no citations my filter work well anyway.

Tried using Home Person
A progress bar appeared with little progress CANCEL gave
Objects: 7/12749, rows 7 (14.15s)
Tried using Person ID
Objects 24/12749, rows 24 (108.63s)

In both cases the data produced was correct.

Am I right thinking that you are cycling through all the Citations and then checking to see if it is referencing an event which is in the filter.
Can we not just read the citation list from each event on the list.? Surely that would be quicker?

Yes, you’re right.

Then what?

Maybe, you can try it :wink:

All I want from this is a list of citations that I can use as the input to a report.

I can see that you are creating a General purpose any filter - any Category type of thing. Way over my head.

You have at least shown me that the Multi filter does work, Though the Active Person filter does not.
Thank you, I will have a play and see where I end up.

Just reloaded from script and run.
Objects: 1000/12749, rows: 1000 (4.42s)
I have no idea why the speed difference, Thanks again. Appreciated.

1 Like

Unless and until a filter can be created…

Create your people filter. Then create a .gramps XML export using this filter and make sure to set the References Filter to Do not include records not linked to a selected person.

Import this exported file into a new empty database. The citations in this database will be those you seek.

1 Like

The most straightforward (and IMHO Gramps-ish) way to solve this would be a new Citation filter:

Citations of Events matching the

Since Events already support:

Events of Persons matching the

2 Likes

I think it may need a generic new rule functionality that flattens the Primary/Secondary object hierarchy.

So while a current rule may return Citations of a Person, we want a recursive option that returns all the citations of Person and the Citations of all the secondary objects… and all their secondary object’s objects. Or likewise, for those of a Selection of Events or Media objects.

And probably with Privacy exclusion option.

Such a recursive seeking option for Persons creates an extra challenge: what to consider of the Family.

And the distinctive differences between being a familymember as a Spouse or as offspring. (Many of the Family rules have an ‘include spouse’ checkbox. But none have checkbox options to include Parents or Siblings.)

I believe you are overthinking the problem. If a person filter has the correct people then there is no need to look for parents or children. The problem is simply that there is currently no citation filter which can look at the Events namespace.

1 Like

I’m overthinking your issue. That one is addressable with a SuperRule (a SuperTool created generic Citations rule).

But some of the power expansions to Rules that Kari ( @kku ) has created make the effective use of complex Filters accessible by mere mortals.

You will probably need to refine the scope bit more… most developers like well-defined & interesting problems before they start work.

But Kari has always been very interested in verifying that his tools CAN do the task. And he shares what he builds for his test case afterwards.

So his testing should yield your requested filter rule.

That would be fine if you use citations only for a person’s events and not for their names, associations, etc.

I keep thinking of the Citations gramplet. I understand it can’t be used as part of a filter, but can’t some of its code be copied (or at least used as a model)?

Look at the display_citations() function in the PersonCitations class in citations.py. Given a person, it gets all the related citations with just a few lines of code:

    self.add_citations(person)
    self.add_eventref_citations(person)
    for handle in person.get_family_handle_list():
        family = self.dbstate.db.get_family_from_handle(handle)
        self.add_eventref_citations(family)
    self.add_name_citations(person)
    self.add_attribute_citations(person)
    self.add_address_citations(person)
    self.add_mediaref_citations(person)
    self.add_association_citations(person)
    self.add_lds_citations(person)

Can’t that code, or at least the idea of it, be put in a new filter rule “Citations of People matching the <filter>”? (Easy for me to ask, since I don’t know how to do it myself.)