forked from citation-style-language/utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsl-count-text-value-strings.py
36 lines (30 loc) · 1.1 KB
/
csl-count-text-value-strings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Python script for additional style validation
# Author: Rintze M. Zelle
# Version: 2011-12-17
# * Requires lxml library (http://lxml.de/)
#
# Shows
# - verbatim text values used
import os, glob, re
from lxml import etree
path = 'C:\Documents and Settings\zelle\My Documents\CSL\styles\\'
verbatims = {}
for independentStyle in glob.glob( os.path.join(path, '*.csl') ):
#print(os.path.basename(independentStyle))
style = etree.parse(independentStyle)
styleElement = style.getroot()
verbatimsStyle = []
try:
verbatimsStyle = styleElement.findall(".//{http://purl.org/net/xbiblio/csl}text[@value]")
for verbatim in verbatimsStyle:
verbatim = verbatim.attrib.get("value")
if verbatim in verbatims:
verbatims[verbatim] += 1
else:
verbatims[verbatim] = 1
except:
pass
verbatimsSorted = sorted(verbatims, key=verbatims.get, reverse=True)
print("Verbatim values used with cs:text and usage:")
for verbatimSorted in verbatimsSorted:
print('"' + verbatimSorted + '"' + ": %d" % (verbatims[verbatimSorted]))