Sitelet https://github.com/kitsuyui/python-template-analysis
Skip to content

template-analysis

Python PyPI version Coverage License

Generate template and extract variables from texts. In other words, template-analysis makes reverse template (untemplate).

Usage

Currently, this supports analyzing one or more texts.

from template_analysis import analyze
result = analyze([
    "A dog is a good pet",
    "A cat is a good pet",
    "A cat is a pretty pet",
    "A bird is a great pet",
])
result.to_format_string()  # => "A {0} is a {1} pet"
result.args[0]  # => ["dog", "good"]
result.args[1]  # => ["cat", "good"]
result.args[2]  # => ["cat", "pretty"]
result.args[3]  # => ["bird", "great"]

Concepts / Future plans

Development plans

  • 1. Untemplate two texts.
  • 2. Untemplate multiple / complex texts.
  • 3. Untemplate nested / tree-structured texts.
  • 4. Support several features for scraping.
  • 5. Implement a more efficient algorithm.

Image boards

1-templating 2-untemplating 3-template-deriving 4-template-deriving-2 4-automated-scraping

Development

This repository uses lefthook to run the same checks as CI locally, so problems surface before they reach CI.

# Install dependencies
uv sync

# Install the Git hooks (once; requires lefthook on your PATH)
lefthook install

Once installed, the hooks run automatically:

  • pre-commit: uv run poe check
  • pre-push: uv run poe check and uv run poe test

You can also run the checks manually:

uv run poe check
uv run poe test

CI still runs the full matrix (see .github/workflows/); the hooks only bring that feedback earlier on your machine.

Release notes

See CHANGELOG.md for release history and upgrade notes.

License

The 3-Clause BSD License. See also LICENSE file.

About

Generate template string from formatted strings.

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages