Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vmarkovtsev/etalpmet
Template reverser for Go
https://github.com/vmarkovtsev/etalpmet
longest-common-substring reverse-template
Last synced: 22 days ago
JSON representation
Template reverser for Go
- Host: GitHub
- URL: https://github.com/vmarkovtsev/etalpmet
- Owner: vmarkovtsev
- License: apache-2.0
- Created: 2018-10-21T08:46:46.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-23T18:55:55.000Z (about 6 years ago)
- Last Synced: 2024-06-20T12:46:12.253Z (5 months ago)
- Topics: longest-common-substring, reverse-template
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: contributing.md
- License: LICENSE
- Code of conduct: code_of_conduct.md
Awesome Lists containing this project
README
etalpmet
Extract templates from strings in Go.
Overview •
How To Use •
Installation •
Contributions •
License--------
## Overview
Given some byte strings, this library extracts the common template between them -- some people call
it "reverse templating". For example, given the following list of file names:```
IMG_20180930_171704.jpg
IMG_20181001_150308.jpg
IMG_20181001_190338.jpg
IMG_20181021_122346.jpg
```we can infer the common file name template: `IMG_2018*_1*.jpg`.
Idea credits: [turicas/templater](https://github.com/turicas/templater/).
## How To Use
There are two functions: "basic" and "advanced". Both return a slice of byte slices which correspond to
template constant blocks.
The former function is straightforward:```go
import "gopkg.in/vmarkovtsev/etalpmet.v1"template := etalpmet.ReverseTemplate(
[]byte(" spam and eggs "),
[]byte(" ham and spam "),
[]byte(" white and black "))
// ["", "and", ""]
```The "advanced" function allows to change some parameters of the template extraction.
```go
import "gopkg.in/vmarkovtsev/etalpmet.v1"
template := etalpmet.ReverseTemplateWithParameters(
5, // min block length
false, // trim
[]byte(" spam and eggs "),
[]byte(" ham and spam "),
[]byte(" white and black "))
// [nil, " and ", " "]
```Note `nil` which signals that there is text before the leftmost template block `" and "`.
## Installation
```
go get gopkg.in/vmarkovtsev/etalpmet.v1
```The code supports building under Go >= 1.8.
## Contributions
...are pretty much welcome! See [contributing.md](contributing.md) and [code_of_conduct.md](code_of_conduct.md).
## License
Apache 2.0, see [LICENSE](LICENSE). It allows you to use this code in proprietary projects.