Skip to content

Commit 5d08d60

Browse files
committed
Initial release
1 parent 31efb20 commit 5d08d60

35 files changed

+1952
-2
lines changed

.github/workflows/ci.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# This software was developed at the National Institute of Standards
2+
# and Technology by employees of the Federal Government in the course
3+
# of their official duties. Pursuant to title 17 Section 105 of the
4+
# United States Code this software is not subject to copyright
5+
# protection and is in the public domain. NIST assumes no
6+
# responsibility whatsoever for its use by other parties, and makes
7+
# no guarantees, expressed or implied, about its quality,
8+
# reliability, or any other characteristic.
9+
#
10+
# We would appreciate acknowledgement if the software is used.
11+
12+
name: Continuous Integration
13+
14+
on:
15+
push:
16+
branches: [ main, develop ]
17+
pull_request:
18+
branches: [ main, develop ]
19+
20+
jobs:
21+
build:
22+
23+
runs-on: ubuntu-latest
24+
strategy:
25+
matrix:
26+
python-version: [3.8]
27+
28+
steps:
29+
- uses: actions/checkout@v2
30+
- name: Set up Python ${{ matrix.python-version }}
31+
uses: actions/setup-python@v2
32+
with:
33+
python-version: ${{ matrix.python-version }}
34+
- name: Install Python virtualenv for Github runner
35+
run: |
36+
python -m pip install --upgrade pip
37+
pip install virtualenv
38+
- name: Start from clean state
39+
run: make clean
40+
- name: Run tests
41+
run: make check

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.done.log
2+
*.swp
3+
.DS_Store
4+
__pycache__
5+
build/
6+
case_utils.egg-info/
7+
dist/

Makefile

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/make -f
2+
3+
# This software was developed at the National Institute of Standards
4+
# and Technology by employees of the Federal Government in the course
5+
# of their official duties. Pursuant to title 17 Section 105 of the
6+
# United States Code this software is not subject to copyright
7+
# protection and is in the public domain. NIST assumes no
8+
# responsibility whatsoever for its use by other parties, and makes
9+
# no guarantees, expressed or implied, about its quality,
10+
# reliability, or any other characteristic.
11+
#
12+
# We would appreciate acknowledgement if the software is used.
13+
14+
SHELL := /bin/bash
15+
16+
all:
17+
18+
.PHONY: \
19+
download
20+
21+
.git_submodule_init.done.log: \
22+
.gitmodules
23+
# Log current submodule pointers.
24+
cd dependencies \
25+
&& git diff . \
26+
| cat
27+
git submodule init dependencies/CASE-Examples-QC
28+
git submodule update dependencies/CASE-Examples-QC
29+
# Build an ontology terms list, which has a side effect of initiating further submodules.
30+
$(MAKE) \
31+
--directory dependencies/CASE-Examples-QC \
32+
download
33+
$(MAKE) \
34+
--directory dependencies/CASE-Examples-QC/tests \
35+
ontology_vocabulary.txt
36+
touch $@
37+
38+
check: \
39+
.git_submodule_init.done.log
40+
$(MAKE) \
41+
--directory tests \
42+
check
43+
44+
clean:
45+
@$(MAKE) \
46+
--directory tests \
47+
clean
48+
49+
distclean: \
50+
clean
51+
@rm -rf \
52+
build \
53+
*.egg-info \
54+
dist
55+
56+
download: \
57+
.git_submodule_init.done.log
58+
$(MAKE) \
59+
--directory tests \
60+
download

README.md

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,79 @@
1-
# opensource-repo
2-
This repository is the recommended template repository for NIST opensource contributions.
1+
# CASE Python Utilities
2+
3+
This project provides various specialized utilities for producing data in the [CASE](https://caseontology.org/) format.
4+
5+
6+
## Disclaimer
7+
8+
Participation by NIST in the creation of the documentation of mentioned software is not intended to imply a recommendation or endorsement by the National Institute of Standards and Technology, nor is it intended to imply that any specific software is necessarily the best available for the purpose.
9+
10+
11+
## Installation
12+
13+
1. Clone this repository.
14+
2. (Optional) Create and activate a virtual environment.
15+
3. Run `python setup.py`.
16+
17+
Installation is demonstrated in the `.venv.done.log` target of the [`tests/`](tests/) directory.
18+
19+
20+
## Usage
21+
22+
23+
### `case_file`
24+
25+
To characterize a file, including hashes:
26+
27+
```bash
28+
case_file sample.txt.json sample.txt
29+
```
30+
31+
To characterize a file, but skip hashing it:
32+
33+
```bash
34+
case_file --disable-hashes sample.txt.json sample.txt
35+
```
36+
37+
38+
### `local_uuid`
39+
40+
This [module](case_utils/local_uuid.py) provides a wrapper UUID generator, `local_uuid()`. Its main purpose is making example data generate consistent identifiers, and intentionally includes mechanisms to make it difficult to activate this mode without awareness of the caller.
41+
42+
43+
## Development status
44+
45+
This repository follows [CASE community guidance on describing development status](https://caseontology.org/resources/software.html#development_status), by adherence to noted support requirements.
46+
47+
The status of this repository is:
48+
49+
4 - Beta
50+
51+
52+
## Versioning
53+
54+
This project follows [SEMVER 2.0.0](https://semver.org/) where versions are declared.
55+
56+
57+
## Ontology versions supported
58+
59+
This repository supports the ontology versions that are linked as submodules in the [CASE Examples QC](https://github.com/ajnelson-nist/CASE-Examples-QC) repository. Currently, the ontology versions are:
60+
61+
* CASE - 0.3.0
62+
* UCO - 0.5.0
63+
64+
65+
## Repository locations
66+
67+
This repository is available at the following locations:
68+
* [https://github.com/casework/CASE-Utilities-Python](https://github.com/casework/CASE-Utilities-Python)
69+
* [https://github.com/usnistgov/CASE-Utilities-Python](https://github.com/usnistgov/CASE-Utilities-Python) (a mirror)
70+
71+
Releases and issue tracking will be handled at the [casework location](https://github.com/casework/CASE-Utilities-Python).
72+
73+
74+
## Make targets
75+
76+
Some `make` targets are defined for this repository:
77+
* `check` - Run unit tests.
78+
* `clean` - Remove test build files, but not downloaded files.
79+
* `download` - Download files sufficiently to run the unit tests offline. This will *not* include the ontology repositories tracked as submodules. Note if you do need to work offline, be aware touching the `setup.cfg` file in the project root directory, or `tests/requirements.txt`, will trigger a virtual environment rebuild.

case_utils/__init__.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python3
2+
3+
# This software was developed at the National Institute of Standards
4+
# and Technology by employees of the Federal Government in the course
5+
# of their official duties. Pursuant to title 17 Section 105 of the
6+
# United States Code this software is not subject to copyright
7+
# protection and is in the public domain. NIST assumes no
8+
# responsibility whatsoever for its use by other parties, and makes
9+
# no guarantees, expressed or implied, about its quality,
10+
# reliability, or any other characteristic.
11+
#
12+
# We would appreciate acknowledgement if the software is used.
13+
14+
__version__ = "0.1.0"
15+
16+
import rdflib.util
17+
18+
from . import local_uuid
19+
20+
def guess_format(fpath, fmap=None):
21+
"""
22+
This function is a wrapper around rdflib.util.guess_format(), adding that the .json extension should be recognized as JSON-LD.
23+
24+
:param fpath: File path.
25+
:type fpath: string
26+
27+
:param fmap: Mapper dictionary; see rdflib.util.guess_format() for further description. Note that as in rdflib 5.0.0, supplying this argument overwrites, not augments, the suffix format map used by rdflib.
28+
:type fmap: dict
29+
30+
:returns: RDF file format, fit for rdflib.Graph.parse() or .serialize(); or, None if file extension not mapped.
31+
:rtype: string
32+
"""
33+
34+
assert fmap is None or isinstance(fmap, dict), "Type check failed"
35+
36+
if fmap is None:
37+
updated_fmap = {key:rdflib.util.SUFFIX_FORMAT_MAP[key] for key in rdflib.util.SUFFIX_FORMAT_MAP}
38+
if not "json" in updated_fmap:
39+
updated_fmap["json"] = "json-ld"
40+
else:
41+
updated_fmap = {k:fmap[k] for k in fmap}
42+
43+
return rdflib.util.guess_format(fpath, updated_fmap)

0 commit comments

Comments
 (0)