Skip to main content

Analyse an RDF graph to find URI's without human readable labels.

Project description

labelify

[!WARNING] All labelify functionality has been absorbed into kurra, the more general-purpose RDF management tool

Please use kurra as labelify will no longer be maintained and will eventually be removed.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

labelify-0.6.2.tar.gz (198.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

labelify-0.6.2-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file labelify-0.6.2.tar.gz.

File metadata

  • Download URL: labelify-0.6.2.tar.gz
  • Upload date:
  • Size: 198.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.1

File hashes

Hashes for labelify-0.6.2.tar.gz
Algorithm Hash digest
SHA256 7814c1bb0b79726c705e5a27472990345e1b1b91a3473d927795c0aa280a9109
MD5 6549719c9f2ac790594f0c9f905efb69
BLAKE2b-256 34f3edf908c74a645e94a99f3040c35e3931c593001bee9d24ef824c799909fd

See more details on using hashes here.

File details

Details for the file labelify-0.6.2-py3-none-any.whl.

File metadata

  • Download URL: labelify-0.6.2-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.1

File hashes

Hashes for labelify-0.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 405c99eb4268a675c7fede8d3bdea318bff024bdd234502f1aa89f44547ebc30
MD5 b852aab7e202a9024c7f4ca9984ee312
BLAKE2b-256 68f1ed9bba007ed9e7b3a84e688d0465d629fa32c1b9e93936fe36352de76846

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page