Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

Awesome Lists containing this project

README

        


🤔


etalpmet



Extract templates from strings in Go.


GoDoc
Travis build Status
Code coverage
Go Report Card
Apache 2.0 license



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.