|
@ -35,7 +35,7 @@ def sortkey(value): |
|
|
def processSXD(filename): |
|
|
def processSXD(filename): |
|
|
"""Parse sxd file. |
|
|
"""Parse sxd file. |
|
|
|
|
|
|
|
|
Return an index object. |
|
|
Return an Index object. |
|
|
""" |
|
|
""" |
|
|
index_file = open(filename) |
|
|
index_file = open(filename) |
|
|
data = [] |
|
|
data = [] |
|
@ -44,7 +44,7 @@ def processSXD(filename): |
|
|
index_file.close() |
|
|
index_file.close() |
|
|
|
|
|
|
|
|
i = 1 |
|
|
i = 1 |
|
|
idx = index(data[0]) |
|
|
idx = Index(data[0]) |
|
|
|
|
|
|
|
|
while len(data) > i and data[i].startswith('%'): |
|
|
while len(data) > i and data[i].startswith('%'): |
|
|
keywords = keywordPattern.match(data[i]).groups() |
|
|
keywords = keywordPattern.match(data[i]).groups() |
|
@ -59,8 +59,8 @@ def processSXD(filename): |
|
|
return idx |
|
|
return idx |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class index: |
|
|
class Index: |
|
|
"""Title, author or scripture index representation.""" |
|
|
"""Title, author or scripture Index representation.""" |
|
|
|
|
|
|
|
|
def __init__(self, indextype): |
|
|
def __init__(self, indextype): |
|
|
self.data = dict() |
|
|
self.data = dict() |
|
@ -91,7 +91,9 @@ class index: |
|
|
if self.indextype == "TITLE": |
|
|
if self.indextype == "TITLE": |
|
|
if 'prefix' in self.keywords: |
|
|
if 'prefix' in self.keywords: |
|
|
for prefix in self.keywords['prefix']: |
|
|
for prefix in self.keywords['prefix']: |
|
|
self.prefix_patterns.append(re.compile(r"^(%s)(\b|\\)(\s*.*)$" % prefix)) |
|
|
self.prefix_patterns.append(re.compile( |
|
|
|
|
|
r"^({prefix})(\b|\\)(\s*.*)$".format(prefix=prefix) |
|
|
|
|
|
)) |
|
|
|
|
|
|
|
|
if self.indextype == "AUTHOR": |
|
|
if self.indextype == "AUTHOR": |
|
|
for key in self.keywords: |
|
|
for key in self.keywords: |
|
@ -100,12 +102,18 @@ class index: |
|
|
for word in self.authwords.keys(): |
|
|
for word in self.authwords.keys(): |
|
|
if word in self.keywords: |
|
|
if word in self.keywords: |
|
|
if word == "after": |
|
|
if word == "after": |
|
|
self.authwords[word] = [re.compile(r"^.*%s\b(.*)" % after) |
|
|
self.authwords[word] = [ |
|
|
for after in self.keywords[word]] |
|
|
re.compile(r"^.*{after}\b(.*)".format(after=after)) |
|
|
|
|
|
for after in self.keywords[word] |
|
|
|
|
|
] |
|
|
elif word == "sep": |
|
|
elif word == "sep": |
|
|
self.authwords[word] = [" %s" % sep for sep in self.authwords[word]] + [","] |
|
|
self.authwords[word] = [" {sep}".format(sep=sep) |
|
|
self.authwords[word] = [re.compile(r"^(.*)%s (.*)$" % sep) |
|
|
for sep in self.authwords[word] |
|
|
for sep in self.authwords[word]] |
|
|
] + [","] |
|
|
|
|
|
self.authwords[word] = [ |
|
|
|
|
|
re.compile(r"^(.*){sep} (.*)$".format(sep=sep)) |
|
|
|
|
|
for sep in self.authwords[word] |
|
|
|
|
|
] |
|
|
else: |
|
|
else: |
|
|
self.authwords[word] = self.keywords[word] |
|
|
self.authwords[word] = self.keywords[word] |
|
|
|
|
|
|
|
@ -124,8 +132,10 @@ class index: |
|
|
match = pattern.match(key) |
|
|
match = pattern.match(key) |
|
|
if match: |
|
|
if match: |
|
|
self._raw_add( |
|
|
self._raw_add( |
|
|
"%s (%s)" % (match.group(2) + match.group(3), |
|
|
"{} ({})".format( |
|
|
match.group(1)), number, link) |
|
|
match.group(2) + match.group(3), |
|
|
|
|
|
match.group(1)), |
|
|
|
|
|
number, link) |
|
|
return |
|
|
return |
|
|
self._raw_add(key, number, link) |
|
|
self._raw_add(key, number, link) |
|
|
|
|
|
|
|
|