Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JARS-144] Document that dont have rdf:type relation are ingested #146

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions cookies/accession/zotero.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
BIB.Illustration, BIB.Recording, BIB.Legislation, BIB.Document,
BIB.BookSection, BIB.Book, BIB.Data, BIB.Letter, BIB.Report,
BIB.Article, BIB.Thesis, BIB.Manuscript, BIB.Image,
BIB.ConferenceProceedings,
BIB.ConferenceProceedings
]


Expand Down Expand Up @@ -114,8 +114,8 @@ def _unpack_zipfile(self, path):

self.paths = []
for file_path in self.zipfile.namelist():

if path.startswith('.'):
filename = os.path.basename(file_path)
if filename.startswith('.'):
continue
temp_path = self.zipfile.extract(file_path, self.dtemp)
if temp_path.endswith('.rdf'):
Expand All @@ -141,10 +141,9 @@ def _init_graph(self, rdf_path, classes=RESOURCE_CLASSES):
self.graph = rdflib.Graph()
self.graph.parse(rdf_path)
self.entries = []

self.classes = copy.deepcopy(classes)
self.current_class = None
self.current_entries = None
self.current_entries = self.graph.subjects(ZOTERO.itemType)

def _init_dtemp(self):
self.dtemp = tempfile.mkdtemp()
Expand Down Expand Up @@ -430,14 +429,10 @@ def __iter__(self):
def next(self):
next_entry = None
while next_entry is None:
try:
next_entry = self.current_entries.next()
except (StopIteration, AttributeError):
try:
self.current_class = self.classes.pop()
except IndexError: # Out of classes.
raise StopIteration()
self.current_entries = self._get_resources_nodes(self.current_class)
next_entry = self.current_entries.next()
if str(next(self.graph.objects(subject=next_entry, predicate=ZOTERO.itemType))) == \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if 'self.graph.objects(subject=next_entry, predicate=ZOTERO.itemType)' is None?

settings.ATTACHMENT_ITEMTYPE:
next_entry = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len still returning wrong length


self._new_entry()
self.process(next_entry)
Expand All @@ -448,7 +443,9 @@ def current(self):
return EntryWrapper(self.data[-1])

def __len__(self):
return sum([len(list(self._get_resources_nodes(cl))) for cl in self.classes])
return len([entry for entry in self.graph.subjects(ZOTERO.itemType)
if str(self.graph.objects(subject=entry, predicate=ZOTERO.itemType)) !=
settings.ATTACHMENT_ITEMTYPE])

def __del__(self):
"""
Expand Down
4 changes: 4 additions & 0 deletions jars/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,7 @@


SESSION_COOKIE_NAME = 'amphora'


# Zotero item-type for attachment
ATTACHMENT_ITEMTYPE = 'attachment'