era-data 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- era_data-0.1.0/.gitignore +12 -0
- era_data-0.1.0/LICENSE +21 -0
- era_data-0.1.0/PKG-INFO +68 -0
- era_data-0.1.0/README.md +42 -0
- era_data-0.1.0/examples/journal_history.py +67 -0
- era_data-0.1.0/pyproject.toml +33 -0
- era_data-0.1.0/src/era_data/__init__.py +123 -0
- era_data-0.1.0/src/era_data/py.typed +0 -0
- era_data-0.1.0/tests/test_era_data.py +136 -0
era_data-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 John Vandenberg
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
era_data-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: era-data
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The ERA journal and conference lists and the ANZSRC classifications, as an RDF graph
|
|
5
|
+
Project-URL: Homepage, https://github.com/jayvdb/era_data
|
|
6
|
+
Project-URL: Issues, https://github.com/jayvdb/era_data/issues
|
|
7
|
+
Project-URL: Vocabulary, https://github.com/jayvdb/era_data/blob/master/VOCAB.md
|
|
8
|
+
Author: John Vandenberg
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: anzsrc,australia,era,rdf,research
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.14
|
|
21
|
+
Requires-Dist: platformdirs>=4
|
|
22
|
+
Requires-Dist: rdflib>=7
|
|
23
|
+
Provides-Extra: test
|
|
24
|
+
Requires-Dist: pytest; extra == 'test'
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# era-data
|
|
28
|
+
|
|
29
|
+
The Excellence in Research for Australia (ERA) journal lists of 2010, 2012, 2015, 2018 and 2023, its conference lists
|
|
30
|
+
of 2010 and 2015, and the ANZSRC 2008 and 2020 Fields of Research and Socio-Economic Objectives, as one RDF graph.
|
|
31
|
+
|
|
32
|
+
The journals and conferences can also be searched in a browser, at
|
|
33
|
+
[era-open-data.vercel.app](https://era-open-data.vercel.app/).
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
import era_data
|
|
37
|
+
|
|
38
|
+
graph = era_data.graph() # an rdflib.Graph of every triple
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The package holds no data. On first use it downloads `era_data.nt.gz`, gzipped N-Triples, from the
|
|
42
|
+
[era_data](https://github.com/jayvdb/era_data) release `data-v4`, checks its SHA-256 and keeps it in the user's cache
|
|
43
|
+
directory. Set `ERA_DATA_NT` to the path of a local copy to use that instead, and `ERA_DATA_CACHE` to keep the
|
|
44
|
+
download somewhere else.
|
|
45
|
+
|
|
46
|
+
- `era_data.graph()` returns the triples as an `rdflib.Graph`.
|
|
47
|
+
- `era_data.ntriples()` returns them as N-Triples text.
|
|
48
|
+
- `era_data.path()` returns the path of the file.
|
|
49
|
+
|
|
50
|
+
`era_data.graph()` is slow: rdflib parses the 1.6 million triples into memory, which takes about two minutes and
|
|
51
|
+
2 GB of memory on a 2019 laptop. Where that matters, load the graph once and keep it, or give `era_data.path()` or
|
|
52
|
+
`era_data.ntriples()` to a faster RDF library or a triple store.
|
|
53
|
+
|
|
54
|
+
`examples/journal_history.py` prints how one journal changed from list to list: its titles, fields of research,
|
|
55
|
+
ISSNs and, in ERA 2010, its rank. It defaults to ERA ID 4465, IEEE Transactions on Cybernetics:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
python examples/journal_history.py 4465
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The repository's README describes the data, and its
|
|
62
|
+
[VOCAB.md](https://github.com/jayvdb/era_data/blob/master/VOCAB.md) the vocabulary.
|
|
63
|
+
|
|
64
|
+
## Copyright
|
|
65
|
+
|
|
66
|
+
The data comes from the Australian Research Council and the Australian Bureau of Statistics. The
|
|
67
|
+
[Copyright section](https://github.com/jayvdb/era_data#copyright) of the repository's README describes the terms
|
|
68
|
+
each was published under.
|
era_data-0.1.0/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# era-data
|
|
2
|
+
|
|
3
|
+
The Excellence in Research for Australia (ERA) journal lists of 2010, 2012, 2015, 2018 and 2023, its conference lists
|
|
4
|
+
of 2010 and 2015, and the ANZSRC 2008 and 2020 Fields of Research and Socio-Economic Objectives, as one RDF graph.
|
|
5
|
+
|
|
6
|
+
The journals and conferences can also be searched in a browser, at
|
|
7
|
+
[era-open-data.vercel.app](https://era-open-data.vercel.app/).
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
import era_data
|
|
11
|
+
|
|
12
|
+
graph = era_data.graph() # an rdflib.Graph of every triple
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The package holds no data. On first use it downloads `era_data.nt.gz`, gzipped N-Triples, from the
|
|
16
|
+
[era_data](https://github.com/jayvdb/era_data) release `data-v4`, checks its SHA-256 and keeps it in the user's cache
|
|
17
|
+
directory. Set `ERA_DATA_NT` to the path of a local copy to use that instead, and `ERA_DATA_CACHE` to keep the
|
|
18
|
+
download somewhere else.
|
|
19
|
+
|
|
20
|
+
- `era_data.graph()` returns the triples as an `rdflib.Graph`.
|
|
21
|
+
- `era_data.ntriples()` returns them as N-Triples text.
|
|
22
|
+
- `era_data.path()` returns the path of the file.
|
|
23
|
+
|
|
24
|
+
`era_data.graph()` is slow: rdflib parses the 1.6 million triples into memory, which takes about two minutes and
|
|
25
|
+
2 GB of memory on a 2019 laptop. Where that matters, load the graph once and keep it, or give `era_data.path()` or
|
|
26
|
+
`era_data.ntriples()` to a faster RDF library or a triple store.
|
|
27
|
+
|
|
28
|
+
`examples/journal_history.py` prints how one journal changed from list to list: its titles, fields of research,
|
|
29
|
+
ISSNs and, in ERA 2010, its rank. It defaults to ERA ID 4465, IEEE Transactions on Cybernetics:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
python examples/journal_history.py 4465
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The repository's README describes the data, and its
|
|
36
|
+
[VOCAB.md](https://github.com/jayvdb/era_data/blob/master/VOCAB.md) the vocabulary.
|
|
37
|
+
|
|
38
|
+
## Copyright
|
|
39
|
+
|
|
40
|
+
The data comes from the Australian Research Council and the Australian Bureau of Statistics. The
|
|
41
|
+
[Copyright section](https://github.com/jayvdb/era_data#copyright) of the repository's README describes the terms
|
|
42
|
+
each was published under.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""Print how one journal changed across the ERA journal lists: its titles, fields of research, ISSNs and rank.
|
|
2
|
+
|
|
3
|
+
Usage: python journal_history.py [<ERA journal ID>]
|
|
4
|
+
|
|
5
|
+
The ERA ID defaults to DEFAULT, a journal whose fields of research and ISSNs change from list to list. A journal
|
|
6
|
+
has a rank only in ERA 2010, the one list that ranked journals. The journal lists assign fields of research but no
|
|
7
|
+
socio-economic objectives, so there are none to print.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import sys
|
|
11
|
+
|
|
12
|
+
import era_data
|
|
13
|
+
import rdflib
|
|
14
|
+
from rdflib.namespace import DCTERMS, SKOS, XSD
|
|
15
|
+
|
|
16
|
+
VOCAB = rdflib.Namespace("https://jayvdb.github.io/era_data/vocab#")
|
|
17
|
+
BIBO_ISSN = rdflib.URIRef("http://purl.org/ontology/bibo/issn")
|
|
18
|
+
|
|
19
|
+
# IEEE Transactions on Cybernetics: renamed, and given divisions, MD, then 2008 and 2020 groups, and more ISSNs.
|
|
20
|
+
DEFAULT = 4465
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def history(graph, eraid):
|
|
24
|
+
"""Return, for each journal list that has the journal, its title and that list's details of the journal.
|
|
25
|
+
|
|
26
|
+
The details are a dict of its title, its rank or None, its fields of research as (code, name) pairs and its
|
|
27
|
+
ISSNs. The lists come in the order of their titles, which is the order they were published in.
|
|
28
|
+
"""
|
|
29
|
+
entries: list[tuple[str, dict]] = []
|
|
30
|
+
for journal in graph.subjects(VOCAB.eraId, rdflib.Literal(eraid, datatype=XSD.integer)):
|
|
31
|
+
journal_list = graph.value(journal, VOCAB.journalList)
|
|
32
|
+
fields = sorted(
|
|
33
|
+
(str(graph.value(field, SKOS.notation)), str(graph.value(field, SKOS.prefLabel)))
|
|
34
|
+
for field in graph.objects(journal, VOCAB.fieldOfResearch)
|
|
35
|
+
)
|
|
36
|
+
rank = graph.value(journal, VOCAB.rank)
|
|
37
|
+
details = {
|
|
38
|
+
"title": str(graph.value(journal, DCTERMS.title)),
|
|
39
|
+
"rank": str(rank) if rank is not None else None,
|
|
40
|
+
"multidisciplinary": graph.value(journal, VOCAB.multidisciplinary) == rdflib.Literal(True),
|
|
41
|
+
"fields": fields,
|
|
42
|
+
"issns": sorted(str(issn) for issn in graph.objects(journal, BIBO_ISSN)),
|
|
43
|
+
}
|
|
44
|
+
entries.append((str(graph.value(journal_list, DCTERMS.title)), details))
|
|
45
|
+
return sorted(entries)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def main(eraid=None):
|
|
49
|
+
"""Print the history of the journal with the ERA ID eraid, or DEFAULT."""
|
|
50
|
+
eraid = int(eraid) if eraid else DEFAULT
|
|
51
|
+
entries = history(era_data.graph(), eraid)
|
|
52
|
+
if not entries:
|
|
53
|
+
sys.exit(f"No journal has the ERA ID {eraid}")
|
|
54
|
+
for list_title, details in entries:
|
|
55
|
+
print(list_title)
|
|
56
|
+
print(f" Title: {details['title']}")
|
|
57
|
+
if details["rank"]:
|
|
58
|
+
print(f" Rank: {details['rank']}")
|
|
59
|
+
fields = [f"{code} {name}" for code, name in details["fields"]]
|
|
60
|
+
if details["multidisciplinary"]:
|
|
61
|
+
fields.append("MD Multidisciplinary")
|
|
62
|
+
print(f" Fields of research: {'; '.join(fields) or 'none'}")
|
|
63
|
+
print(f" ISSNs: {', '.join(details['issns']) or 'none'}")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
if __name__ == "__main__":
|
|
67
|
+
main(*sys.argv[1:])
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
authors = [{ name = "John Vandenberg" }]
|
|
3
|
+
classifiers = [
|
|
4
|
+
"Development Status :: 4 - Beta",
|
|
5
|
+
"Intended Audience :: Science/Research",
|
|
6
|
+
"Operating System :: OS Independent",
|
|
7
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
8
|
+
"Programming Language :: Python :: 3",
|
|
9
|
+
"Programming Language :: Python :: 3.14",
|
|
10
|
+
"Topic :: Scientific/Engineering",
|
|
11
|
+
"Typing :: Typed",
|
|
12
|
+
]
|
|
13
|
+
dependencies = ["platformdirs>=4", "rdflib>=7"]
|
|
14
|
+
description = "The ERA journal and conference lists and the ANZSRC classifications, as an RDF graph"
|
|
15
|
+
keywords = ["anzsrc", "australia", "era", "rdf", "research"]
|
|
16
|
+
license = "MIT"
|
|
17
|
+
license-files = ["LICENSE"]
|
|
18
|
+
name = "era-data"
|
|
19
|
+
readme = "README.md"
|
|
20
|
+
requires-python = ">=3.14"
|
|
21
|
+
version = "0.1.0"
|
|
22
|
+
|
|
23
|
+
[project.optional-dependencies]
|
|
24
|
+
test = ["pytest"]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://github.com/jayvdb/era_data"
|
|
28
|
+
Issues = "https://github.com/jayvdb/era_data/issues"
|
|
29
|
+
Vocabulary = "https://github.com/jayvdb/era_data/blob/master/VOCAB.md"
|
|
30
|
+
|
|
31
|
+
[build-system]
|
|
32
|
+
build-backend = "hatchling.build"
|
|
33
|
+
requires = ["hatchling"]
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""The ERA journal and conference lists and the ANZSRC classifications, as an RDF graph.
|
|
2
|
+
|
|
3
|
+
The data is the triple store published with the era_data release RELEASE: era_data.nt.gz, gzipped N-Triples.
|
|
4
|
+
This package has none of it. On first use, `path()` downloads the file from GitHub, checks it against SHA256 and
|
|
5
|
+
keeps it in `cache_dir()`. Set ERA_DATA_NT to the path of a local copy to use that instead, without a download.
|
|
6
|
+
The download gives up when the server sends nothing for TIMEOUT seconds.
|
|
7
|
+
|
|
8
|
+
import era_data
|
|
9
|
+
|
|
10
|
+
graph = era_data.graph() # an rdflib.Graph of every triple
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import gzip
|
|
14
|
+
import hashlib
|
|
15
|
+
import os
|
|
16
|
+
import shutil
|
|
17
|
+
import tempfile
|
|
18
|
+
import urllib.request
|
|
19
|
+
import zlib
|
|
20
|
+
from os import PathLike
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
|
|
23
|
+
import platformdirs
|
|
24
|
+
import rdflib
|
|
25
|
+
|
|
26
|
+
__version__ = "0.1.0"
|
|
27
|
+
|
|
28
|
+
# The release the data comes from, and the checksum of the N-Triples text in its file; `mise run pin` writes both.
|
|
29
|
+
RELEASE = "data-v4"
|
|
30
|
+
SHA256 = "bc68654497e876d01b82efea1fbf30cc8f75320d98ecc742cc9b87d764bcf5d6"
|
|
31
|
+
FILE = "era_data.nt.gz"
|
|
32
|
+
URL = f"https://github.com/jayvdb/era_data/releases/download/{RELEASE}/{FILE}"
|
|
33
|
+
|
|
34
|
+
# The environment variable naming a local copy of the file, which is used as it is.
|
|
35
|
+
LOCAL = "ERA_DATA_NT"
|
|
36
|
+
# The environment variable naming the directory to keep downloads in.
|
|
37
|
+
CACHE = "ERA_DATA_CACHE"
|
|
38
|
+
# How many seconds a download waits for the server to connect or send more, before it gives up.
|
|
39
|
+
TIMEOUT = 60
|
|
40
|
+
|
|
41
|
+
type StrPath = str | PathLike[str]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class ChecksumError(ValueError):
|
|
45
|
+
"""A downloaded file is not the one the release published."""
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def cache_dir() -> Path:
|
|
49
|
+
"""Return the directory the file is kept in once downloaded.
|
|
50
|
+
|
|
51
|
+
It is ERA_DATA_CACHE when that is set, and otherwise era_data in the user's cache directory, as platformdirs
|
|
52
|
+
finds it: %LOCALAPPDATA% on Windows, ~/Library/Caches on macOS and $XDG_CACHE_HOME, or ~/.cache, elsewhere.
|
|
53
|
+
Each release has its own directory in it.
|
|
54
|
+
"""
|
|
55
|
+
if base := os.environ.get(CACHE):
|
|
56
|
+
return Path(base) / RELEASE
|
|
57
|
+
# No author or "Cache" subdirectory, which platformdirs adds on Windows by default, so the directory is the same
|
|
58
|
+
# as the Rust crate's.
|
|
59
|
+
return platformdirs.user_cache_path("era_data", appauthor=False, opinion=False) / RELEASE
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def sha256(file: StrPath) -> str:
|
|
63
|
+
"""Return the SHA-256, in hex, of the N-Triples text in the gzipped file at a path.
|
|
64
|
+
|
|
65
|
+
The text is what is checked, not the gzip bytes around it, which differ with the zlib that compressed them.
|
|
66
|
+
"""
|
|
67
|
+
with gzip.open(file, "rb") as f:
|
|
68
|
+
return hashlib.file_digest(f, "sha256").hexdigest()
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def cached(file: StrPath) -> str | None:
|
|
72
|
+
"""Return the checksum of a kept copy of the file, or None when it is not gzip, so that it is downloaded again.
|
|
73
|
+
|
|
74
|
+
Any other error, such as being unable to read it, is raised.
|
|
75
|
+
"""
|
|
76
|
+
try:
|
|
77
|
+
return sha256(file)
|
|
78
|
+
except gzip.BadGzipFile, EOFError, zlib.error:
|
|
79
|
+
return None
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def fetch(url: str = URL, checksum: str = SHA256, dest: StrPath | None = None) -> Path:
|
|
83
|
+
"""Return the path of the file at url, downloading it to dest unless a copy with that checksum is there already.
|
|
84
|
+
|
|
85
|
+
dest defaults to FILE in `cache_dir()`. The download goes to a temporary directory beside it, and the file replaces
|
|
86
|
+
dest, in one rename, only once its checksum matches, so dest is never a partial or wrong file. ChecksumError is
|
|
87
|
+
raised when it does not, and the temporary directory is removed whatever happens. A copy at dest that is damaged,
|
|
88
|
+
and is not gzip, is downloaded again.
|
|
89
|
+
"""
|
|
90
|
+
dest = Path(dest) if dest else cache_dir() / FILE
|
|
91
|
+
if dest.is_file() and cached(dest) == checksum:
|
|
92
|
+
return dest
|
|
93
|
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
|
94
|
+
# A directory rather than a file, as Windows will not rename a file that is still open.
|
|
95
|
+
with tempfile.TemporaryDirectory(dir=dest.parent) as tmp:
|
|
96
|
+
part = Path(tmp) / FILE
|
|
97
|
+
with urllib.request.urlopen(url, timeout=TIMEOUT) as response, open(part, "wb") as f:
|
|
98
|
+
shutil.copyfileobj(response, f)
|
|
99
|
+
if (actual := sha256(part)) != checksum:
|
|
100
|
+
raise ChecksumError(f"{url} has SHA-256 {actual}, not {checksum}")
|
|
101
|
+
part.replace(dest)
|
|
102
|
+
return dest
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def path() -> Path:
|
|
106
|
+
"""Return the path of the file: ERA_DATA_NT when that is set, or else the release's file, downloaded if need be."""
|
|
107
|
+
if local := os.environ.get(LOCAL):
|
|
108
|
+
return Path(local)
|
|
109
|
+
return fetch()
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def ntriples(source: StrPath | None = None) -> str:
|
|
113
|
+
"""Return the whole triple store as N-Triples text, from source or, by default, `path()`."""
|
|
114
|
+
with gzip.open(source or path(), "rt", encoding="ascii") as f:
|
|
115
|
+
return f.read()
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def graph(source: StrPath | None = None) -> rdflib.Graph:
|
|
119
|
+
"""Return the whole triple store as an rdflib.Graph, from source or, by default, `path()`."""
|
|
120
|
+
result = rdflib.Graph()
|
|
121
|
+
with gzip.open(source or path(), "rb") as f:
|
|
122
|
+
result.parse(f, format="nt")
|
|
123
|
+
return result
|
|
File without changes
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"""Tests of the era_data package, against the file named by ERA_DATA_NT: a local build of the release's file."""
|
|
2
|
+
|
|
3
|
+
import gzip
|
|
4
|
+
import importlib.util
|
|
5
|
+
import os
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
import era_data
|
|
9
|
+
import pytest
|
|
10
|
+
import rdflib
|
|
11
|
+
|
|
12
|
+
LOCAL = os.environ.get(era_data.LOCAL, "")
|
|
13
|
+
pytestmark = pytest.mark.skipif(not LOCAL, reason="ERA_DATA_NT names no local build of era_data.nt.gz")
|
|
14
|
+
|
|
15
|
+
SKOS = rdflib.Namespace("http://www.w3.org/2004/02/skos/core#")
|
|
16
|
+
VOCAB = rdflib.Namespace("https://jayvdb.github.io/era_data/vocab#")
|
|
17
|
+
SOUTHERLY = rdflib.URIRef("https://jayvdb.github.io/era_data/era2010/journal/11637")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@pytest.fixture(scope="module")
|
|
21
|
+
def graph():
|
|
22
|
+
return era_data.graph()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_pinned_checksum():
|
|
26
|
+
"""The package pins the checksum of the file the pipeline builds; `mise run pin` updates it."""
|
|
27
|
+
assert era_data.sha256(LOCAL) == era_data.SHA256
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_triple_count(graph):
|
|
31
|
+
assert len(graph) == 1606400
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_journal(graph):
|
|
35
|
+
title = graph.value(SOUTHERLY, rdflib.URIRef("http://purl.org/dc/terms/title"))
|
|
36
|
+
assert str(title) == "Southerly: a review of Australian literature"
|
|
37
|
+
assert str(graph.value(SOUTHERLY, VOCAB.rank)) == "B"
|
|
38
|
+
fields = sorted(str(o) for o in graph.objects(SOUTHERLY, VOCAB.fieldOfResearch))
|
|
39
|
+
assert fields == [f"http://purl.org/au-research/vocabulary/anzsrc-for/2008/{code}" for code in ("19", "20", "21")]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_concepts(graph):
|
|
43
|
+
for2008 = rdflib.Namespace("http://purl.org/au-research/vocabulary/anzsrc-for/2008/")
|
|
44
|
+
group = for2008["0801"]
|
|
45
|
+
assert str(graph.value(group, SKOS.prefLabel)) == "Artificial Intelligence and Image Processing"
|
|
46
|
+
assert graph.value(group, SKOS.broader) == for2008["08"]
|
|
47
|
+
# Non-ASCII names survive the file's \u escapes.
|
|
48
|
+
field = rdflib.URIRef("http://purl.org/au-research/vocabulary/anzsrc-for/2008/050208")
|
|
49
|
+
assert str(graph.value(field, SKOS.prefLabel)) == "M\u0101ori Environmental Knowledge"
|
|
50
|
+
division = rdflib.URIRef("https://linked.data.gov.au/def/anzsrc-for/2020/46")
|
|
51
|
+
assert str(graph.value(division, SKOS.prefLabel)) == "INFORMATION AND COMPUTING SCIENCES"
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_journal_history_example(graph):
|
|
55
|
+
"""The example's default journal, which changes in every way the lists record."""
|
|
56
|
+
path = Path(__file__).parent.parent / "examples" / "journal_history.py"
|
|
57
|
+
spec = importlib.util.spec_from_file_location("journal_history", path)
|
|
58
|
+
assert spec and spec.loader
|
|
59
|
+
example = importlib.util.module_from_spec(spec)
|
|
60
|
+
spec.loader.exec_module(example)
|
|
61
|
+
entries = dict(example.history(graph, example.DEFAULT))
|
|
62
|
+
assert list(entries) == [
|
|
63
|
+
"ERA 2010 journal list",
|
|
64
|
+
"ERA 2012 journal list",
|
|
65
|
+
"ERA 2015 consultation journal list",
|
|
66
|
+
"ERA 2015 journal list",
|
|
67
|
+
"ERA 2015 submitted journal list",
|
|
68
|
+
"ERA 2018 journal list",
|
|
69
|
+
"ERA 2023 original journal list",
|
|
70
|
+
"ERA 2023 revised journal list",
|
|
71
|
+
]
|
|
72
|
+
first, last = entries["ERA 2010 journal list"], entries["ERA 2018 journal list"]
|
|
73
|
+
# ERA 2023 assigns ANZSRC 2020 groups.
|
|
74
|
+
assert entries["ERA 2023 revised journal list"]["fields"] == [
|
|
75
|
+
("4602", "Artificial intelligence"),
|
|
76
|
+
("4603", "Computer vision and multimedia computation"),
|
|
77
|
+
("4611", "Machine learning"),
|
|
78
|
+
]
|
|
79
|
+
assert first["title"] == "IEEE Transactions on Systems, Man and Cybernetics, Part B: Cybernetics"
|
|
80
|
+
assert first["rank"] == "A"
|
|
81
|
+
assert [code for code, _ in first["fields"]] == ["08", "09", "17"]
|
|
82
|
+
assert entries["ERA 2012 journal list"]["multidisciplinary"]
|
|
83
|
+
assert entries["ERA 2012 journal list"]["fields"] == []
|
|
84
|
+
assert last["title"] == "IEEE Transactions on Cybernetics"
|
|
85
|
+
assert last["rank"] is None
|
|
86
|
+
assert last["fields"] == [
|
|
87
|
+
("0102", "Applied Mathematics"),
|
|
88
|
+
("0801", "Artificial Intelligence and Image Processing"),
|
|
89
|
+
("0906", "Electrical and Electronic Engineering"),
|
|
90
|
+
]
|
|
91
|
+
assert last["issns"] == ["1083-4419", "1941-0492", "2168-2267", "2168-2275"]
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def test_ntriples_is_ascii():
|
|
95
|
+
text = era_data.ntriples()
|
|
96
|
+
assert text.isascii()
|
|
97
|
+
assert text.count("\n") == 1606400
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_fetch_downloads_and_caches(tmp_path):
|
|
101
|
+
"""fetch() downloads, checks and keeps the file, and reuses the kept copy; a file:// URL stands in for GitHub."""
|
|
102
|
+
url = Path(LOCAL).resolve().as_uri()
|
|
103
|
+
dest = tmp_path / "cache" / era_data.FILE
|
|
104
|
+
assert era_data.fetch(url, era_data.SHA256, dest) == dest
|
|
105
|
+
assert era_data.sha256(dest) == era_data.SHA256
|
|
106
|
+
mtime = dest.stat().st_mtime_ns
|
|
107
|
+
assert era_data.fetch("file:///nonexistent", era_data.SHA256, dest) == dest
|
|
108
|
+
assert dest.stat().st_mtime_ns == mtime
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def test_fetch_replaces_a_damaged_copy(tmp_path):
|
|
112
|
+
"""A kept copy that is not gzip is downloaded again, rather than failing every call until it is removed."""
|
|
113
|
+
dest = tmp_path / "cache" / era_data.FILE
|
|
114
|
+
dest.parent.mkdir()
|
|
115
|
+
dest.write_bytes(b"not gzip")
|
|
116
|
+
assert era_data.fetch(Path(LOCAL).resolve().as_uri(), era_data.SHA256, dest) == dest
|
|
117
|
+
assert era_data.sha256(dest) == era_data.SHA256
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def test_fetch_rejects_a_wrong_file(tmp_path):
|
|
121
|
+
wrong = tmp_path / "wrong.nt.gz"
|
|
122
|
+
wrong.write_bytes(gzip.compress(b"<urn:a> <urn:b> <urn:c> .\n"))
|
|
123
|
+
dest = tmp_path / "cache" / era_data.FILE
|
|
124
|
+
with pytest.raises(era_data.ChecksumError):
|
|
125
|
+
era_data.fetch(wrong.as_uri(), era_data.SHA256, dest)
|
|
126
|
+
# Neither the file nor the temporary directory it was downloaded to is left.
|
|
127
|
+
assert list(dest.parent.iterdir()) == []
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def test_cache_dir(monkeypatch, tmp_path):
|
|
131
|
+
monkeypatch.setenv(era_data.CACHE, str(tmp_path))
|
|
132
|
+
assert era_data.cache_dir() == tmp_path / era_data.RELEASE
|
|
133
|
+
monkeypatch.delenv(era_data.CACHE)
|
|
134
|
+
default = era_data.cache_dir()
|
|
135
|
+
assert default.parts[-2:] == ("era_data", era_data.RELEASE)
|
|
136
|
+
assert "Cache" not in default.parts[-3:-1]
|