Skip to content

Commit

Permalink
Using REF attribute in genre mapping when possible #36
Browse files Browse the repository at this point in the history
  • Loading branch information
alliyya committed May 8, 2022
1 parent 2851ebb commit c7e6f05
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions Mods/modsBib.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,22 @@ def __init__(self, filename, matched_documents):
# input()
def parse_db_refs(self):
"""
Maps all genres within a textscope to the given dbref
Used to map to blibiography
Maps all genres within a textscope to the given ref/dbref
Used to map to bibliography
:return: None
"""
textscopes = self.soup.find_all('TEXTSCOPE')

for ts in textscopes:
ts_parent = ts.parent
rec_id = None
if 'REF' in ts.attrs:
rec_id = ts.attrs['REF'].split(":")[2]

elif 'DBREF' in ts.attrs:
rec_id = ts.attrs['DBREF']

if 'DBREF' in ts.attrs:
db_ref = ts.attrs['DBREF']
if rec_id:

tgenres = ts_parent.find_all('TGENRE')
genres = []
Expand All @@ -273,22 +278,10 @@ def parse_db_refs(self):
name = genre.attrs['GENRENAME']
genres.append(name)

temp = 0
if db_ref in self.matched_documents:
print("pre:",self.matched_documents[db_ref])
temp = 1

self.matched_documents[db_ref] = genres

if db_ref in self.matched_documents:
print("post:",self.matched_documents[db_ref])
self.matched_documents[rec_id] = genres
else:
logger.error("TEXTSCOPE missing REF & DBREF attribute")

if temp:
input()

print("\n"*3)
temp = 0


class BibliographyParse:
"""
Expand Down Expand Up @@ -976,7 +969,6 @@ def build_graph(self):
else:
logger.warning(F"GENRE NOT FOUND: {genre['genre']}")


if self.id in genre_map:
genres = genre_map[self.id]
for genre in genres:
Expand Down

0 comments on commit c7e6f05

Please sign in to comment.