Coder Social home page Coder Social logo

etalpmet's Introduction

🤔

etalpmet

Extract templates from strings in Go.

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

OverviewHow To UseInstallationContributionsLicense


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.

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:

import "gopkg.in/vmarkovtsev/etalpmet.v1"

template := etalpmet.ReverseTemplate(
	[]byte("<b> spam and eggs </b>"),
	[]byte("<b> ham and spam </b>"),
    []byte("<b> white and black </b>"))
// ["<b>", "and", "</b>"]

The "advanced" function allows to change some parameters of the template extraction.

import "gopkg.in/vmarkovtsev/etalpmet.v1"


template := etalpmet.ReverseTemplateWithParameters(
	5,     // min block length
	false, // trim
	[]byte("<b> spam and eggs </b>"),
	[]byte("<b> ham and spam </b>"),
    []byte("<b> white and black </b>"))
// [nil, " and ", " </b>"]

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 and code_of_conduct.md.

License

Apache 2.0, see LICENSE. It allows you to use this code in proprietary projects.

etalpmet's People

Contributors

vmarkovtsev avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.