Jay Taylor's notes
back to listing indexsrc-d/go-license-detector
[web search]cmd/license-detector | Add more tests | 10 days ago | |
licensedb | Scan for license files in README | a day ago | |
vendor | Add Siva input format support | a month ago | |
.gitignore | Fix html2text on PGA | a month ago | |
.travis.yml | Add html2text tests | 10 days ago | |
CODE_OF_CONDUCT.md | Initial commit | 3 months ago | |
CONTRIBUTING.md | Rebrand the contributions doc | 3 months ago | |
DCO | Initial commit | 3 months ago | |
FAILURES.md | Fix failures formatting | 3 months ago | |
Gopkg.lock | Add Siva input format support | a month ago | |
Gopkg.toml | Francesc's refactoring: first steps | 3 months ago | |
LICENSE.md | Initial commit | 3 months ago | |
Makefile | Fix NLP license detection | 3 days ago | |
README.md | Compare to other projects | 3 days ago | |
appveyor.yml | v1 -> v2 | 2 months ago |
README.md
go-license-detector
Project license detector - a command line application and a library, written in Go. It scans the given directory for license files, normalizes and hashes them and outputs all the fuzzy matches with the list of reference texts. The returned names follow SPDX standard. Read the blog post.
Why? There are no similar projects which can be compiled into a native binary without dependencies and also support the whole SPDX license database (≈400 items). This implementation is also fast, requires little memory, and the API is easy to use.
The license texts are taken directly from license-list-data repository. The detection algorithm is not template matching; this directly implies that go-license-detector does not provide any legal guarantees. The intended area of it's usage is data mining.
Installation
go get -v gopkg.in/src-d/go-license-detector.v2/...
Contributions
...are welcome, see CONTRIBUTING.md and code of conduct.
License
Apache 2.0, see LICENSE.md.
Algorithm
- Find files in the root directory which may represent a license. E.g.
LICENSE
orlicense.md
. - If the file is Markdown or reStructuredText, render to HTML and then convert to plain text. Original HTML files are also converted.
- Normalize the text according to SPDX recommendations.
- Split the text into unigrams and build the weighted bag of words.
- Calculate Weighted MinHash.
- Apply Locality Sensitive Hashing and pick the reference licenses which are close.
- For each of the candidate, calculate the Levenshtein distance -
D
. the corresponding text is the single line with each unigram represented by a single rune (character). - Set the similarity as
1 - D / L
whereL
is the number of unigrams in the quieried license.
This pipeline guarantees constant time queries, though requires some initialization to preprocess the reference licenses.
If there are not license files found:
- Look for README files.
- If the file is Markdown or reStructuredText, render to HTML and then convert to plain text. Original HTML files are also converted.
- Scan for words like "copyright", "license" and "released under". Take the neighborhood.
- Run Named Entity Recognition (NER) over that surrounding context and extract the possible license name.
- Match it against the list of license names from SPDX.
Usage
Command line:
license-detector /path/to/project license-detector https://github.com/src-d/go-git
Library:
import ( "gopkg.in/src-d/go-license-detector.v2/licensedb" "gopkg.in/src-d/go-license-detector.v2/licensedb/filer" ) func main() { licenses, err := licensedb.Detect(filer.FromDirectory("/path/to/project")) }
Quality
On the dataset of ~1000 most starred repositories on GitHub as of early February 2018 (list), 99% of the licenses are detected. The analysis of detection failures is going in FAILURES.md.
Comparison to other projects on that dataset:
Detector | Detection rate | Time to scan, sec |
---|---|---|
go-license-detector | 99% (897/902) | 13.5 |
benbalter/licensee | 75% (673/902) | 111 |
google/licenseclassifier | 76% (682/902) | 907 |
boyter/lc | 88% (797/902) | 548 |
amzn/askalono | 87% (785/902) | 165 |
LiD | 94% (847/902) | 3660 |
Regenerate binary data
The SPDX licenses are included into the binary. To update them, run
make bindata.go