Skip to content
Merged
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
13 changes: 11 additions & 2 deletions ace/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1413,9 +1413,18 @@ def parse_article(self, html, pmid=None, **kwargs):
if not soup:
return False

# Current pages carry no public URL and print their tables inline.
public_url = soup.find('meta', {'name': 'citation_public_url'})
if public_url is None:
tables = []
self._append_leaf_candidate_tables(soup, tables)
self.article.tables = tables
if not tables:
self.article.missing_source = True
return self.article

# To download tables, we need the content URL and the number of tables
content_url = soup.find('meta', {
'name': 'citation_public_url'})['content']
content_url = public_url['content']

n_tables = len(soup.find_all('span', class_='table-label'))

Expand Down
26 changes: 26 additions & 0 deletions ace/tests/data/highwire_inline_table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="citation_doi" content="10.1126/science.0000000">
<meta name="citation_pmid" content="99900001">
<title>Inline table without a public URL</title>
</head>
<body class="highwire-journal-article">
<article>
<h1>Inline table without a public URL</h1>
<div class="core-container">
<p>Activation peaks are listed in Table 1.</p>
<div class="table-wrap">
<span class="table-label">Table 1</span>
<table>
<caption>Peak coordinates</caption>
<tr><th>Region</th><th>x</th><th>y</th><th>z</th><th>Peak Z</th></tr>
<tr><td>Left amygdala</td><td>-22</td><td>-6</td><td>-16</td><td>4.1</td></tr>
<tr><td>Right insula</td><td>36</td><td>18</td><td>2</td><td>3.8</td></tr>
</table>
</div>
</div>
</article>
</body>
</html>
16 changes: 16 additions & 0 deletions ace/tests/test_ace.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,22 @@ def test_sciencedirect_combined_coordinate_column_source(test_weird_data_path, s
assert _count_valid_activations(article.tables) >= 1


def test_highwire_page_without_public_url_parses_inline_tables(test_data_path, source_manager):
# Current science.org pages have no citation_public_url, so the expansion
# download is skipped and the table comes from the page itself.
html = open(join(test_data_path, 'highwire_inline_table.html')).read()
source = source_manager.identify_source(html)
assert source.__class__.__name__ == 'HighWireSource'

article = source.parse_article(html, pmid='99900001', skip_metadata=True)

assert article is not None
assert len(article.tables) == 1
table = article.tables[0]
assert table.position == 1
assert table.n_activations == 2


def test_springer_inline_table_fallback_source(test_weird_data_path, source_manager):
pmid = '27007121'
html = open(join(test_weird_data_path, pmid + '.html')).read()
Expand Down
Loading