Analyse an RDF graph to find URI's without human readable labels.
Project description
labelify
labelify is a Python module and command line utility that identifies unlabelled resources in RDF graphs and can extract labels for them from external resources.
If you would like to use the labelify tool directly, we provide an online GUI for it here.
Installation
Command line use
Try installing it from PyPI:
uv add labelify
Or clone the labelify repository:
git clone https://github.com/Kurrawong/labelify somewhere
Then, install it using uv:
uv tool install labelify
If you don't install it this way, you can still use it as a Command Line Interface by running it as a Python script. From within the cloned repository's root directory:
python -m labelify -h
...for the help command.
Pyton library
labelify is on PyPI at https://pypi.org/project/labelify/.
Use
Command Line
To run labelify from the command line, you must have labelify installed as a script or you run it via Python - see above. Then, labelify can tell you all about its command line options, just run:
labelify -h
for "help".
Simple use
Find all missing labels in data.ttl:
labelify data.ttl
Find all missing labels in data.ttl taking into account the
labels which have been defined in another file called labels.ttl.
but don’t check for missing labels in supportingVocab.ttl
labelify data.ttl --context labels.ttl
Same as above but use the additional labelling predicates given in predicates.txt to find labels:
labelify data.ttl --context supportingVocab.ttl --labels predicates.txt
By default, only rdfs:label, dcterms:title, schema:name and skos:prefLabel` are used to find labels.
predicates.txt needs to be a list of labelling predicates - one per line and un-prefixed - e.g.:
http://xmlns.com/foaf/0.1/givenName
http://example.com/mySpecialLabel
http://www.w3.org/2008/05/skos-xl#altLabel
Find all the missing labels in the graph http://example-graph.com at the sparql endpoint http://mytriplestore/sparql
using basic HTTP auth to connect:
labelify http://mytriplestore/sparql --graph http://example-graph --username admin
labelify will prompt for the password or it can be provided with the --password flag if you don't mind it being
saved to your shell's history.
Label Extraction
Get all the IRIs with missing labels from a local RDF file and put them into a text file with one IRI per line:
labelify all my_file.ttl -r > iris-missing-labels.txt
note use of -r for simple IRI printing
Use the output file to generate an RDF file containing the labels, extracted from either another RDF file, a directory of RDF files or a SPARQL endpoint:
labelify -x iris-missing-labels.txt other-rdf-file.ttl > labels.ttl
# or
labelify -x iris-missing-labels.txt dir-of-rdf-files/ > labels.ttl
# or
labelify -x iris-missing-labels.txt http://some-sparql-endpoint.com/sparql > labels.ttl
Command line output formats
By default, labelify will print helpful progress and configuration messages and attempt to group the missing labels by namespace, making it easier to quickly understand the output.
The --raw/-r option can be appended to any of the examples above to tell labelify to only print the uris of objects
with missing labels (one per line) and no other messages. This is useful for command line composition if you wish to
pipe the output into another process.
More command line options
For more help and the complete list of command line options just run
labelify --help
# or
labelfy -h
As per unix conventions all the flags shown above can also be used with short codes. i.e. -g is the same as --graph.
Python module
Print missing labels for all the objects (not subjects or predicates) in data.ttl, taking into account any labels
which have been defined in RDF files in the supportingVocabs directory.
Using skos:prefLabel and rdfs:label, but not dcterms:title and schema:name (as per default) as the labelling
predicates.
from labelify import find_missing_labels
from rdflib import Graph
import glob
data = Graph().parse("tests/manifest.ttl")
context = Graph()
for context_file in glob.glob("tests/one/background/*.ttl"):
context.parse(context_file)
missing_labels = find_missing_labels(
data,
context
)
print(missing_labels)
And, to extract labels, descriptions & seeAlso details for given IRIs from a given directory of RDF files:
from pathlib import Path
from labelify import extract_labels
iris = Path("tests/get_iris/iris.txt").read_text().splitlines()
lbls = extract_labels(iris, Path("tests/one/background/"))
Development
Installing from source
Clone the repository and install the dependencies:
labelify uses uv to manage its dependencies.
uv tool install labelify
You can then use labelify from the command line.
Running tests
uv run pytest
or
task test
Several of the tests require a Fuseki triplestore instance to be available, so you need Docker running as the tests will attempt to use testcontainers to create throwaway containers for this purpose.
Formatting the codebase
task format
License
BSD-3-Clause. See the LICENSE file in the codebase.
Contact
KurrawongAI
info@kurrawong.ai
https://kurrawong.ai
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file labelify-0.6.1.tar.gz.
File metadata
- Download URL: labelify-0.6.1.tar.gz
- Upload date:
- Size: 198.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a06cefc69a5912ed853a931c738ca5e38061785caacb12a9f808791f3af45968
|
|
| MD5 |
ba0c0653f900eb2026c94b71694f6257
|
|
| BLAKE2b-256 |
c059ae23e92bfb8124304b91a5d66640bde8db4ce2fef4cb74835361fd2bf83e
|
File details
Details for the file labelify-0.6.1-py3-none-any.whl.
File metadata
- Download URL: labelify-0.6.1-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b8935d42ac14a0410c4663580920d734a4900339c67d2d3a1436cdd7a0801f5
|
|
| MD5 |
def405233ca9beedbde8355abe20e87c
|
|
| BLAKE2b-256 |
d1a329602671b909197c74d98d14d0777777f0379dbdd0c1b245a2c28b8b9718
|