Skip to main content

sesg

SeSG (Search String Generator) python package repository.

PyPI version Documentation Status CI codecov Code style: black Ruff Docstring Style License: GPL v3

SeSG is a tool developed to help Systematic Literature Review researchers, specifically at the step of building a search string.

Installation

You can install with pip, poetry, or any other package manager:

poetry add sesg

Usage

For a more extensive example, please refer to this repository.

Generating a search string

from dataclasses import dataclass
from random import sample

from sesg.search_string import (
    SimilarWordsFinder,
    create_enrichment_text,
    generate_search_string,
    set_pub_year_boundaries,
)
from sesg.topic_extraction import create_docs, extract_topics_with_bertopic
from transformers import BertForMaskedLM, BertTokenizer


@dataclass
class Study:
    title: str
    abstract: str
    keywords: str


GS: list[Study] = []
QGS: list[Study] = sample(GS, len(GS) // 3)


def main():
    docs = create_docs(
        [
            {
                "title": s.title,
                "abstract": s.abstract,
                "keywords": s.keywords,
            }
            for s in QGS
        ]
    )

    enrichment_text = create_enrichment_text(
        [
            {
                "title": s.title,
                "abstract": s.abstract,
            }
            for s in QGS
        ]
    )

    similar_words_finder = SimilarWordsFinder(
        enrichment_text=enrichment_text,
        bert_model=BertForMaskedLM.from_pretrained("bert-base-uncased"),
        bert_tokenizer=BertTokenizer.from_pretrained("bert-base-uncased"),
    )

    topics = extract_topics_with_bertopic(
        docs,
        kmeans_n_clusters=2,
        umap_n_neighbors=5,
    )

    search_string = generate_search_string(
        topics,
        n_words_per_topic=5,
        n_similar_words_per_word=1,
        similar_words_finder=similar_words_finder,
    )

    search_string = f"TITLE-ABS-KEY({search_string})"
    search_string = set_pub_year_boundaries(search_string, min_year=2010, max_year=2020)

    print(search_string)
    # TITLE-ABS-KEY((("antipatterns") AND ("detection" OR "management") AND ("bdtex") AND ("approach" OR "algorithm") AND ("smurf")) OR (("code" OR "pattern") AND ("detection" OR "management") AND ("design" OR "software") AND ("software" OR "computer") AND ("learning" OR "translation"))) AND PUBYEAR > 1999 AND PUBYEAR < 2018  # noqa: E501


if __name__ == "__main__":
    main()

Assessing the quality of a search string

import trio
from sesg.evaluation import EvaluationFactory, Study
from sesg.scopus import InvalidStringError, Page, ScopusClient


API_KEYS: list[str] = []

GS: list[Study] = []
QGS: list[Study] = []


async def main():
    string = 'TITLE-ABS-KEY("machine learning" and "code smell") AND PUBYEAR > 2010 AND PUBYEAR < 2020'  # noqa: E501
    evaluation_factory = EvaluationFactory(gs=GS, qgs=QGS)

    client = ScopusClient(API_KEYS)

    entries: list[Page.Entry] = []
    try:
        async for page in client.search(string):
            entries.extend(page.entries)

    except InvalidStringError:
        print("Invalid string")

    evaluation = evaluation_factory.evaluate([e.title for e in entries])

    print(evaluation.start_set_recall)
    # 0.7


if __name__ == "__main__":
    trio.run(main)

Credits

This project is a continuation of Leo Fuchs' work. Most of my work in this project consisted in refactoring the codebase, adding tests, improving the documentation and optimizing the performance, along with the addition of some new features.

Highlights

Below you can find the major improvements over the original project:

  • Added BERTopic as a topic extraction strategy.
  • Improved snowballing performance by 100x~120x (thanks to rapidfuzz and multiprocessing).
  • Improved scopus search performance by 30x~40x (thanks to httpx and Eduardo Mendes' help).
  • Improved search string generation performance by ~1.5x (thanks to a caching system).
  • Improved code quality by adopting the use of lint and formatting tools. Also, added type hints to try to catch errors before runtime.
  • Added tests to prevent bugs when refactoring or adding new features.
  • Added docs to help users and contributors.

Contributing

You can contribute in many ways, such as creating issues and submitting pull requests. If you wish to contribute with code, please read the contributor guide.

License

This project is licensed under the terms of the GPL-3.0-only license.

Metadata

Release files for sesg 0.0.59

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sesg 0.0.59
File Size Uploaded Provenance Actions
sesg-0.0.59.tar.gz 37.5 kB Without provenance Details for sesg-0.0.59.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sesg 0.0.59
File Interpreter ABI Platform Actions
sesg-0.0.59-py3-none-any.whl Python 3 none any Details for sesg-0.0.59-py3-none-any.whl

Total release size: 78.4 kB

Release files / sesg-0.0.59.tar.gz

Download URL sesg-0.0.59.tar.gz
Size 37.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e4c5a4c989b9bea9996d9819a2ce4581ff9b9638212842f252db03b4f9e349c0
BLAKE2b-256 checksum
How to use checksums
4f540ceb8a4bb61296433092c075c5a0e939be428a95924530fda043a2eaef27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.10.10 Linux/5.15.0-78-generic

Release files / sesg-0.0.59-py3-none-any.whl

Download URL sesg-0.0.59-py3-none-any.whl
Size 41.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f7937f51d04a82d8bc9d0dc9c90555e3efcf996a58a54b330bcdf2d4c94d3244
BLAKE2b-256 checksum
How to use checksums
58457f7bbf3719e7b5aa68ab59f6de9819a89dede0b5a1176cca482477f8e0c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.10.10 Linux/5.15.0-78-generic

Security for sesg 0.0.59

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.59 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page