Que chato. Eu entendi a pergunta de forma errada!
De qualquer forma, se você por acaso quisesse contar notas de rodapé e estiver usando algo com ferramentas de linha de comando unix disponíveis (por exemplo, linux / mac / unix-tools para windows), então você pode fazer algo como isso:
cat FILENAME | tr '\\' '\n' | awk '/^f /{footnote++;}/^x /{xref++;}/^c /{print chapter, footnote, xref ; chapter=0+$2; footnote=0;xref=0;}END{print chapter, footnote, xref; }'
O que ele faz é garantir que cada novo SFM comece em uma nova linha e, em seguida, conta as notas de rodapé, as referências cruzadas e, quando há um número de capítulo (ou o final), imprime as contagens. Eu não falo python, no entanto, e as notas estão em um arquivo XML, que é um pouco difícil demais para decodificar com awk.
Bother. I misunderstood the question!
Anyway, if you happened to want to count footnotes, and are using something with unix command-line tools available (e.g. linux / mac / unix-tools for windows), then you can do something like this:
cat FILENAME | tr '\\' '\n' | awk '/^f /{footnote++;}/^x /{xref++;}/^c /{print chapter, footnote, xref ; chapter=0+$2; footnote=0;xref=0;}END{print chapter, footnote, xref; }'
What it does is make sure that every new SFM starts a new line, and then counts the footnotes, xrefs and when there’s a chapter number (or the end) it prints the counts. I don’t speak python though, and notes are in an XML file which is quite a bit too nasty to decode with awk.