Skip to content

Commit

Permalink
fix __str__ bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Laura Dietz committed May 22, 2020
1 parent 7481dd1 commit fb0d337
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
4 changes: 2 additions & 2 deletions python3/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cbor>=0.1.4
typing
cbor>=1.0.0
typing>=3.6.2
4 changes: 2 additions & 2 deletions python3/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='trec-car-tools',
version='2.5',
version='2.5.2',
packages=['trec_car'],
url='https://github.com/TREMA-UNH/trec-car-tools/python3',
# download_url='https://github.com/TREMA-UNH/trec-car-tools/archive/2.0.tar.gz',
Expand All @@ -12,7 +12,7 @@
author='laura-dietz',
author_email='Laura.Dietz@unh.edu',
description='Support tools for TREC CAR participants. Also see trec-car.cs.unh.edu',
install_requires=['cbor>=0.1.4', 'typing'],
install_requires=['cbor>=1.0.0', 'typing>=3.6.2', 'numpy>=1.11.2],
python_requires='>=3',
classifiers=[
'Programming Language :: Python :: 3',
Expand Down
48 changes: 39 additions & 9 deletions python3/trec_car/read_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,14 @@ def __init__(self, heading, headingId, children):
self.children = list(children)
self.child_sections = [child for child in self.children if isinstance(child, Section)]

def __str__(self, level=1):
def str_(self, level):
bar = "".join("="*level)
children = "".join(c.__str__(level=level+1) for c in self.children)
children = "".join(c.str_(level=level+1) for c in self.children)
return "\n%s %s %s\n\n%s" % (bar, self.heading, bar, children)

def __str__(self):
return self.str_(level=1)

def __getitem__(self, idx):
return self.children[idx]

Expand All @@ -415,9 +418,12 @@ class Para(PageSkeleton):
def __init__(self, paragraph):
self.paragraph = paragraph

def __str__(self, level=None):
def str_(self, level=None):
return str(self.paragraph)

def __str__(self):
return self.str_()

def get_text(self):
return self.paragraph.get_text()

Expand All @@ -442,9 +448,12 @@ def __init__(self, imageurl, caption):
self.caption = caption
self.imageurl = imageurl

def __str__(self, level=None):
def str_(self, level=None):
return str("!["+self.imageurl+"]. Caption: "+(''.join([str(skel) for skel in self.caption])))

def __str__(self):
return self.str_()

def get_text(self):
return '\n'.join(skel.get_text() for skel in self.caption)

Expand All @@ -466,9 +475,13 @@ def __init__(self, level, body):
self.level = level
self.body = body

def __str__(self, level=None):
def str_(self, level=None):
return str("*" * self.level + " " + str(self.body) + '\n')

def __str__(self):
return self.str_()


def get_text(self):
return self.body.get_text()

Expand All @@ -491,9 +504,14 @@ def __init__(self, infobox_type, entries):
self.title = infobox_type
self.entries = entries

def __str__(self):
def str_(self, level=None):
return self.title+ "\n"+ ("\n".join([key+": "+str(values) for (key,values) in self.entries]))

def __str__(self):
return self.str_()



def get_text(self):
return ""

Expand Down Expand Up @@ -521,9 +539,13 @@ def get_text(self):
"""
return ''.join([body.get_text() for body in self.bodies])

def __str__(self, level=None):
def str_(self, level=None):
return ' '.join(str(body) for body in self.bodies)

def __str__(self):
return self.str_()


class ParaBody(object):
"""
An abstract superclass representing a bit of :class:`Paragraph` content.
Expand Down Expand Up @@ -568,9 +590,13 @@ def __init__(self, text):
def get_text(self):
return self.text

def __str__(self, level=None):
def str_(self, level=None):
return self.text

def __str__(self):
return self.str_()


class ParaLink(ParaBody):
"""
A link within a paragraph.
Expand Down Expand Up @@ -609,9 +635,13 @@ def __init__(self, page, link_section, pageid, anchor_text):
def get_text(self):
return self.anchor_text

def __str__(self, level=None):
def str_(self, level=None):
return "[%s](%s)" % (self.anchor_text, self.page)

def __str__(self):
return self.str_()


def _iter_with_header(file, parse, expected_file_types):
maybe_hdr = cbor.load(file)
if isinstance(maybe_hdr, list) and maybe_hdr[0] == 'CAR':
Expand Down

0 comments on commit fb0d337

Please sign in to comment.