Struct askalono::Store
[−]
[src]
pub struct Store { /* fields omitted */ }
A representation of a collection of known licenses.
This struct is generally what you want to start with if you're looking to
match text against a database of licenses. Load a cache from disk using
from_cache
, then use the analyze
function to determine what a text most
closely matches.
Examples
use askalono::{Store, TextData}; let store = Store::from_cache(File::open("askalono-cache.bin.gz")?)?; let result = store.analyze(&TextData::from("what's this"))?;
Methods
impl Store
[src]
pub fn analyze(&self, text: &TextData) -> Result<Match, Error>
[src]
Compare the given TextData
against all licenses in the Store
.
This parallelizes the search as much as it can to find the best match.
Once a match is obtained, it can be optimized further; see methods on
TextData
for more information.
impl Store
[src]
pub fn new() -> Store
[src]
Create a new Store
.
More often, you probably want to use from_cache
instead of creating
an empty store.
pub fn len(&self) -> usize
[src]
Get the number of licenses in the store.
This only counts licenses by name -- headers, aliases, and alternates aren't included in the count.
impl Store
[src]
pub fn from_cache<R>(readable: R) -> Result<Store, Error> where
R: Read + Sized,
[src]
R: Read + Sized,
Create a store from a cache file.
This method is highly useful for quickly loading a cache, as creating one from text data is rather slow. This method can typically load the full SPDX set from disk in 200-300 ms. The cache will be sanity-checked to ensure it was generated with a similar version of askalono.
pub fn to_cache<W>(&self, writable: W) -> Result<(), Error> where
W: Write + Sized,
[src]
W: Write + Sized,
Serialize the current store.
The output will be a MessagePack'd gzip'd binary stream that should be written to disk.
impl Store
[src]
pub fn load_spdx(
&mut self,
dir: &Path,
include_texts: bool
) -> Result<(), Error>
[src]
&mut self,
dir: &Path,
include_texts: bool
) -> Result<(), Error>
Fill the store with SPDX JSON data.
This function is very specific to the format of SPDX's
license-list-data
repository. It reads all JSON files in the
json/details
directory and creates entries inside the store for
matching.
This is intended to be used during build of askalono, so it's not
available unless the spdx
feature is enabled.
include_texts
, if true, will keep normalized license text data inside
the store. This yields a larger store when serialized, but has the
benefit of allowing you to diff your result against what askalono has
stored.