work-set-clustering

A Python script to perform a clustering based on descriptive keys.

https://github.com/kbrbe/work-set-clustering

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 1 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.3%) to scientific vocabulary

Keywords

bibliographic-data clustering frbr frbrization ifla-lrm inverted-index
Last synced: 6 months ago · JSON representation ·

Repository

A Python script to perform a clustering based on descriptive keys.

Basic Info
  • Host: GitHub
  • Owner: kbrbe
  • License: agpl-3.0
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 78.1 KB
Statistics
  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • Open Issues: 6
  • Releases: 6
Topics
bibliographic-data clustering frbr frbrization ifla-lrm inverted-index
Created over 2 years ago · Last pushed about 1 year ago
Metadata Files
Readme Changelog License Citation

README.md

Work-set Clustering

DOI

A Python script to perform a clustering based on descriptive keys. It can be used to identify work clusters for manifestations according to the FRBR (IFLA-LRM) model. Alternatively it can be used to cluster authority records.

This repository contains several scripts:

  • clustering to perform the clustering based on a list of manifestation identifiers and their descriptive keys
  • get-descriptive-keys-xml to extract manifestation identifiers and description keys directly from MARCXML files
  • get-descriptive-keys-csv to extract manifestation identifiers and description keys from CSV files containing Python lists

If already computed cluster identifiers and descriptive keys from a previous run are provided, they can be reused to extend the initial clustering.

Usage via the command line

Create and activate a Python virtual environment ```bash

Create a new Python virtual environment

python3 -m venv py-request-isni-env

Activate the virtual environment

source py-request-isni-env/bin/activate

Install dependencies

pip install -r requirements.txt

install the tool

pip install . ```

descriptive key extraction

The command-line parameters for both the XML and the CSV extraction script are the same, only the JSON configuration looks slightly different. Please have a look at the provided example configurations.

Descriptive keys are created of combinations between combinations of the datafields specified in part1 and part2 in the config, e.g. names and dates like john doe/birthdate/1970-01-01. Data fields specified in singlePart form a descriptive key on their own, e.g. the ISNI identifier of a person, created with a prefix, e.g. isni/0000000000000001

If one specifies the dataType date, additional year descriptive keys are created. For example john doe/birthyear/1970.

Available options

``` usage: getdescriptivekeysfromxml.py [-h] -c CONFIGFILE -o OUTPUTFILE inputFiles [inputFiles ...]

This script reads one or more XML files and based on a config creates descriptive keys of available field values

positional arguments: inputFiles The inputs file containing XML records

optional arguments: -h, --help show this help message and exit -c CONFIGFILE, --config-file CONFIGFILE The config file with XPath expressions to extract -o OUTPUTFILE, --output-file OUTPUTFILE The output CSV file containing possible descriptive keys based on the key composition config

```

clustering script

Available options:

``` usage: clustering.py [-h] -i INPUTFILE -o OUTPUTFILE --id-column IDCOLUMN --key-column KEYCOLUMN [--delimiter DELIMITER] [--existing-clusters EXISTINGCLUSTERS] [--existing-clusters-keys EXISTINGCLUSTERS_KEYS]

optional arguments: -h, --help show this help message and exit -i INPUTFILE, --input-file INPUTFILE The CSV file(s) with columns for elements and descriptive keys, one row is one element and descriptive key relationship -o OUTPUTFILE, --output-file OUTPUTFILE The name of the output CSV file containing two columns: elementID and clusterID --id-column IDCOLUMN The name of the column with element identifiers --key-column KEYCOLUMN The name of the column that contains a descriptive key --delimiter DELIMITER Optional delimiter of the input/output CSV, default is ',' --existing-clusters EXISTINGCLUSTERS Optional file with existing element-cluster mapping --existing-clusters-keys EXISTINGCLUSTERS_KEYS Optional file with element-descriptive key mapping for existing clusters mapping

```

Clustering from scratch

Given a CSV file where each row contains the relationship between one manifestation identifier and one descriptive key, the tool can be called the following to create cluster assignments.

python python -m work_set_clustering.clustering \ --input-file "descriptive-keys.csv" \ --output-file "clusters.csv" \ --id-column "elementID" \ --key-column "descriptiveKey"

Example CSV which should result in two clusters, one for book1 and book2 (due to a similar key) and one for book3:

|elementID|descriptiveKey| |---------|--------------| |book1|theTitle/author1| |book1|isbnOfTheBook/author1| |book2|isbnOfTheBook/author1| |book3|otherBookTitle/author1|

The script can also read descriptive keys that are distributed across several files. Therefore you only have to use the --input-file parameter several times. Please note that all of those input files should have the same column names specified with --id-column and --key-column.

You can find more examples of cluster input in the test/resources directory.

Reuse existing clusters

You can reuse the clusters created from an earlier run, but you also have to provide the mapping between the previous elements and optionally their descriptive keys.

python python -m work_set_clustering.clustering \ --input-file "descriptive-keys.csv" \ --output-file "clusters.csv" \ --id-column "elementID" \ --key-column "descriptiveKey" \ --existing-clusters "existing-clusters.csv" \ --existing-cluster-keys "initial-descriptive-keys.csv"

Please note that with the two parameters --existing-clusters and --existing-cluster-keys the data from a previous run are provided.

Similar to the initial clustering, you can provide several input files.

[!NOTE] When skipping existing descriptive keys, existing cluster identifiers and assigments are kept, even if their elements have overlapping descriptive keys. Additionally, none of the new elements can be mapped to the existing clusters, because no descriptive keys are provided (more info in https://github.com/kbrbe/work-set-clustering/issues/9)

Usage as a library

The tool can also be used as a library within another Python script or a Jupyter notebook.

clustering script

```python from worksetclustering.clustering import clusterFromScratch as clustering

clustering( inputFilename=["descriptive-keys.csv"], outputFilename="cluster-assignments.csv", idColumnName="elementID", keyColumnName="descriptiveKey", delimiter=',') ```

Or if you want to reuse existing clusters:

```python from worksetclustering.clustering import updateClusters as clustering

clustering( inputFilename=["descriptive-keys.csv"], outputFilename="cluster-assignments.csv", idColumnName="elementID", keyColumnName="descriptiveKey", delimiter=',', existingClustersFilename="existing-clusters.csv", existingClusterKeysFilename="initial-descriptive-keys.csv") ```

Software Tests

  • You can execute the unit tests of the lib.py file with the following command: python work_set_clustering.lib.
  • You can execute the integration tests with the following command: python -m unittest discover -s test

Contact

Sven Lieber - Sven.Lieber@kbr.be - Royal Library of Belgium (KBR) - https://www.kbr.be/en/

Owner

  • Name: KBR (Royal Library of Belgium)
  • Login: kbrbe
  • Kind: organization
  • Email: Sven.Lieber@kbr.be
  • Location: Belgium

Open source projects of KBR, the national scientific library which collects all Belgian publications.

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Lieber"
  given-names: "Sven"
  orcid: "https://orcid.org/0000-0002-7304-3787"
title: "Work-set clustering"
version: 0.4.0
doi: 10.5281/zenodo.10011417
date-released: 2024-06-28
url: "https://github.com/kbrbe/work-set-clustering"

GitHub Events

Total
  • Create event: 2
  • Release event: 1
  • Issues event: 7
  • Watch event: 1
  • Push event: 2
  • Pull request event: 2
Last Year
  • Create event: 2
  • Release event: 1
  • Issues event: 7
  • Watch event: 1
  • Push event: 2
  • Pull request event: 2

Committers

Last synced: about 2 years ago

All Time
  • Total Commits: 19
  • Total Committers: 3
  • Avg Commits per committer: 6.333
  • Development Distribution Score (DDS): 0.105
Past Year
  • Commits: 19
  • Committers: 3
  • Avg Commits per committer: 6.333
  • Development Distribution Score (DDS): 0.105
Top Committers
Name Email Commits
Sven Lieber S****r@u****e 17
Sven Lieber S****r@g****m 1
Sven Lieber S****r@k****e 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 12
  • Total pull requests: 5
  • Average time to close issues: 1 day
  • Average time to close pull requests: 1 minute
  • Total issue authors: 1
  • Total pull request authors: 1
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 5
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 7
  • Pull requests: 1
  • Average time to close issues: 2 days
  • Average time to close pull requests: less than a minute
  • Issue authors: 1
  • Pull request authors: 1
  • Average comments per issue: 0.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • SvenLieber (11)
Pull Request Authors
  • SvenLieber (7)
Top Labels
Issue Labels
enhancement (3) documentation (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 6 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 5
  • Total maintainers: 1
pypi.org: work-set-clustering

A Python script to perform a clustering based on descriptive keys.

  • Versions: 5
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 6 Last month
Rankings
Dependent packages count: 10.0%
Average: 38.7%
Dependent repos count: 67.5%
Maintainers (1)
Last synced: 6 months ago