##
##  fasttext.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package version
%define       V_base  0.9.2
%define       V_snap  20230625

#   package information
Name:         fasttext
Summary:      Facebook Text Representation and Classification
URL:          https://fasttext.cc/
Vendor:       Facebook
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Text
License:      BSD
Version:      %{V_base}.%{V_snap}
Release:      20230625

#   list of sources
Source0:      http://download.openpkg.org/components/versioned/fasttext/fasttext-%{V_snap}.tar.xz
Source1:      http://download.openpkg.org/components/versioned/fasttext/lid.176.ftz
Source2:      fasttext-lid.sh

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, gcc, gcc::with_cxx = yes
PreReq:       OpenPKG, openpkg >= 20160101

%description
    FastText is an open-source, free, lightweight C++ library and
    companion CLI for (1) Word Representation Learning (via Skipgram and
    CBOW methods) and (2) Text Classification. It works on standard,
    generic hardware. Models can later be reduced in size to even fit on
    mobile devices. FastText is better than the classical Word2Vec in
    two major aspects: (1) FastText uses N-grams instead of whole words
    and hence can also work on rare words and (2) FastText can generate
    vectors for Out-Of-Vocabulary (OOV) words (words not present in the
    dictionary during training).

%track
    prog fasttext:base = {
        version   = %{V_base}
        url       = https://github.com/facebookresearch/fastText/releases
        regex     = tree/v(__VER__)
    }
    prog fasttext:snap = {
        version   = %{V_snap}
        url       = http://download.openpkg.org/components/versioned/fasttext/
        regex     = fasttext-(__VER__)\.tar\.xz
    }

%prep
    %setup -q -n fasttext

%build
    %{l_make} %{l_mflags -O} \
        CXX=%{l_cxx} \
        CXXFLAGS="%{l_cxxflags} -O3 -I. -pthread -funroll-loops -std=c++17 -Wno-deprecated-declarations"

%install
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/share/fasttext
    %{l_shtool} install -c -s -m 755 \
        fasttext $RPM_BUILD_ROOT%{l_prefix}/bin/
    %{l_shtool} install -c -m 644 \
        %{SOURCE lid.176.ftz} $RPM_BUILD_ROOT%{l_prefix}/share/fasttext/
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE fasttext-lid.sh} $RPM_BUILD_ROOT%{l_prefix}/bin/fasttext-lid
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

