From cf9dd41d253c0a36b3e0348c8b979696860e8a67 Mon Sep 17 00:00:00 2001 From: Kristofer Berggren Date: Thu, 10 Dec 2020 19:18:09 +0800 Subject: [PATCH 1/9] github actions ci implementation --- .github/workflows/linux.yml | 12 ++++ .github/workflows/macos.yml | 12 ++++ README.md | 6 +- make.sh | 112 ++++++++++++++++++++++++++++++++++++ run.sh | 6 -- 5 files changed, 139 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/linux.yml create mode 100644 .github/workflows/macos.yml create mode 100755 make.sh delete mode 100755 run.sh diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml new file mode 100644 index 0000000..d00ed70 --- /dev/null +++ b/.github/workflows/linux.yml @@ -0,0 +1,12 @@ +name: Linux + +on: [push, pull_request] + +jobs: + linux-build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Build Linux + run: ./make.sh all diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml new file mode 100644 index 0000000..275c3c2 --- /dev/null +++ b/.github/workflows/macos.yml @@ -0,0 +1,12 @@ +name: macOS + +on: [push, pull_request] + +jobs: + mac-build: + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Build macOS + run: ./make.sh all diff --git a/README.md b/README.md index 80e418f..1d74141 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ Spacy-cpp ========= -| **Linux + Mac** | -|-----------------| -| [![Build status](https://travis-ci.com/d99kris/spacy-cpp.svg?branch=master)](https://travis-ci.com/d99kris/spacy-cpp) | +| **Linux** | **Mac** | +|-----------|---------| +| [![Linux](https://github.com/d99kris/spacy-cpp/workflows/Linux/badge.svg)](https://github.com/d99kris/spacy-cpp/actions?query=workflow%3ALinux) | [![macOS](https://github.com/d99kris/spacy-cpp/workflows/macOS/badge.svg)](https://github.com/d99kris/spacy-cpp/actions?query=workflow%3AmacOS) | Spacy-cpp is a C++ wrapper library for the excellent NLP library [spaCy](https://spacy.io/). This project is not affiliated with spaCy, but it is distributed under the same license (MIT). diff --git a/make.sh b/make.sh new file mode 100755 index 0000000..e87f606 --- /dev/null +++ b/make.sh @@ -0,0 +1,112 @@ +#!/usr/bin/env bash + +# make.sh +# +# Copyright (C) 2020 Kristofer Berggren +# All rights reserved. +# +# See LICENSE for redistribution information. + +# exiterr +exiterr() +{ + >&2 echo "${1}" + exit 1 +} + +# process arguments +DEPS="0" +BUILD="0" +TESTS="0" +DOC="0" +INSTALL="0" +case "${1%/}" in + deps) + DEPS="1" + ;; + + build) + BUILD="1" + ;; + + test*) + BUILD="1" + TESTS="1" + ;; + + doc) + BUILD="1" + DOC="1" + ;; + + install) + BUILD="1" + INSTALL="1" + ;; + + all) + DEPS="1" + BUILD="1" + TESTS="1" + DOC="1" + INSTALL="1" + ;; + + *) + echo "usage: make.sh " + echo " deps - install project dependencies" + echo " build - perform build" + echo " tests - perform build and run tests" + echo " doc - perform build and generate documentation" + echo " install - perform build and install" + echo " all - perform all actions above" + exit 1 + ;; +esac + +# deps +if [[ "${DEPS}" == "1" ]]; then + OS="$(uname)" + if [ "${OS}" == "Linux" ]; then + DISTRO="$(lsb_release -i | awk -F':\t' '{print $2}')" + if [[ "${DISTRO}" == "Ubuntu" ]]; then + sudo apt -y install python3-pip libpython3-dev && pip3 install -U spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (linux), exiting." + else + exiterr "deps failed (unsupported linux distro ${DISTRO}), exiting." + fi + elif [ "${OS}" == "Darwin" ]; then + pip3 install -U spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (mac), exiting." + else + exiterr "deps failed (unsupported os ${OS}), exiting." + fi +fi + +# build +if [[ "${BUILD}" == "1" ]]; then + mkdir -p build && cd build && cmake .. && make && cd .. || exiterr "build failed, exiting." +fi + +# tests +if [[ "${TESTS}" == "1" ]]; then + cd build && ctest --output-on-failure && cd .. || exiterr "tests failed, exiting." +fi + +# doc +if [[ "${DOC}" == "1" ]]; then + true || exiterr "doc failed, exiting." +fi + +# install +if [[ "${INSTALL}" == "1" ]]; then + OS="$(uname)" + if [ "${OS}" == "Linux" ]; then + cd build && sudo make install && cd .. || exiterr "install failed (linux), exiting." + elif [ "${OS}" == "Darwin" ]; then + cd build && make install && cd .. || exiterr "install failed (mac), exiting." + else + exiterr "install failed (unsupported os ${OS}), exiting." + fi +fi + +# exit +exit 0 diff --git a/run.sh b/run.sh deleted file mode 100755 index e826fe4..0000000 --- a/run.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -# run tests -mkdir -p build && cd build && cmake .. && make && ctest --output-on-failure - -exit ${?} From cf561c77c2442d183cf2fb719bb7bdae0446d5cc Mon Sep 17 00:00:00 2001 From: Kristofer Berggren Date: Thu, 10 Dec 2020 19:21:09 +0800 Subject: [PATCH 2/9] add linux dependency --- make.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make.sh b/make.sh index e87f606..1ddfe88 100755 --- a/make.sh +++ b/make.sh @@ -70,7 +70,7 @@ if [[ "${DEPS}" == "1" ]]; then if [ "${OS}" == "Linux" ]; then DISTRO="$(lsb_release -i | awk -F':\t' '{print $2}')" if [[ "${DISTRO}" == "Ubuntu" ]]; then - sudo apt -y install python3-pip libpython3-dev && pip3 install -U spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (linux), exiting." + sudo apt -y install python3-pip libpython3-dev python3-setuptools && pip3 install -U spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (linux), exiting." else exiterr "deps failed (unsupported linux distro ${DISTRO}), exiting." fi From d11ef6c7697c23ca9c7231b5f5faf9c4ab18fa03 Mon Sep 17 00:00:00 2001 From: Kristofer Berggren Date: Thu, 10 Dec 2020 19:28:08 +0800 Subject: [PATCH 3/9] add numpy dependency --- make.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/make.sh b/make.sh index 1ddfe88..7f37e0d 100755 --- a/make.sh +++ b/make.sh @@ -70,12 +70,12 @@ if [[ "${DEPS}" == "1" ]]; then if [ "${OS}" == "Linux" ]; then DISTRO="$(lsb_release -i | awk -F':\t' '{print $2}')" if [[ "${DISTRO}" == "Ubuntu" ]]; then - sudo apt -y install python3-pip libpython3-dev python3-setuptools && pip3 install -U spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (linux), exiting." + sudo apt -y install python3-pip libpython3-dev python3-setuptools && pip3 install -U numpy spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (linux), exiting." else exiterr "deps failed (unsupported linux distro ${DISTRO}), exiting." fi elif [ "${OS}" == "Darwin" ]; then - pip3 install -U spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (mac), exiting." + pip3 install -U numpy spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (mac), exiting." else exiterr "deps failed (unsupported os ${OS}), exiting." fi From e8a6de6c65c42b9b71dd35c559f7fae0ff60371f Mon Sep 17 00:00:00 2001 From: Kristofer Berggren Date: Thu, 10 Dec 2020 19:36:15 +0800 Subject: [PATCH 4/9] new linux deps --- make.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make.sh b/make.sh index 7f37e0d..f5329ae 100755 --- a/make.sh +++ b/make.sh @@ -70,7 +70,7 @@ if [[ "${DEPS}" == "1" ]]; then if [ "${OS}" == "Linux" ]; then DISTRO="$(lsb_release -i | awk -F':\t' '{print $2}')" if [[ "${DISTRO}" == "Ubuntu" ]]; then - sudo apt -y install python3-pip libpython3-dev python3-setuptools && pip3 install -U numpy spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (linux), exiting." + sudo apt -y install python3-pip libpython3-dev python3-setuptools && pip3 install -U numpy && pip3 install -U spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (linux), exiting." else exiterr "deps failed (unsupported linux distro ${DISTRO}), exiting." fi From aab80eaead8992578e907588175627b5fe9908bf Mon Sep 17 00:00:00 2001 From: Kristofer Berggren Date: Thu, 10 Dec 2020 19:42:02 +0800 Subject: [PATCH 5/9] add linux deps --- make.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make.sh b/make.sh index f5329ae..2229680 100755 --- a/make.sh +++ b/make.sh @@ -70,7 +70,7 @@ if [[ "${DEPS}" == "1" ]]; then if [ "${OS}" == "Linux" ]; then DISTRO="$(lsb_release -i | awk -F':\t' '{print $2}')" if [[ "${DISTRO}" == "Ubuntu" ]]; then - sudo apt -y install python3-pip libpython3-dev python3-setuptools && pip3 install -U numpy && pip3 install -U spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (linux), exiting." + sudo apt -y install python3-pip libpython3-dev python3-setuptools && pip3 install -U numpy cython && pip3 install -U spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (linux), exiting." else exiterr "deps failed (unsupported linux distro ${DISTRO}), exiting." fi From 449bdbc72f0fe61dabe4fc8c6e681eba79c6ce9a Mon Sep 17 00:00:00 2001 From: Kristofer Berggren Date: Thu, 10 Dec 2020 20:14:07 +0800 Subject: [PATCH 6/9] switch to ubuntu 20.04 --- .github/workflows/linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index d00ed70..6ea49c9 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -4,7 +4,7 @@ on: [push, pull_request] jobs: linux-build: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - name: Checkout uses: actions/checkout@v1 From c07ca3a73e6179933eccd77cc214242ea58fe60b Mon Sep 17 00:00:00 2001 From: Kristofer Berggren Date: Thu, 10 Dec 2020 20:20:38 +0800 Subject: [PATCH 7/9] try simplify deps --- make.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/make.sh b/make.sh index 2229680..d166f99 100755 --- a/make.sh +++ b/make.sh @@ -70,12 +70,14 @@ if [[ "${DEPS}" == "1" ]]; then if [ "${OS}" == "Linux" ]; then DISTRO="$(lsb_release -i | awk -F':\t' '{print $2}')" if [[ "${DISTRO}" == "Ubuntu" ]]; then - sudo apt -y install python3-pip libpython3-dev python3-setuptools && pip3 install -U numpy cython && pip3 install -U spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (linux), exiting." + #sudo apt -y install python3-pip libpython3-dev python3-setuptools && pip3 install -U numpy cython && pip3 install -U spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (linux), exiting." + pip3 install -U spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (linux), exiting." else exiterr "deps failed (unsupported linux distro ${DISTRO}), exiting." fi elif [ "${OS}" == "Darwin" ]; then - pip3 install -U numpy spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (mac), exiting." + #pip3 install -U numpy spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (mac), exiting." + pip3 install -U spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (mac), exiting." else exiterr "deps failed (unsupported os ${OS}), exiting." fi From 9f523df63fafea95a559ab27945c2ab8cc562d84 Mon Sep 17 00:00:00 2001 From: Kristofer Berggren Date: Thu, 10 Dec 2020 20:45:43 +0800 Subject: [PATCH 8/9] cleaned up make.sh --- make.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/make.sh b/make.sh index d166f99..7527a96 100755 --- a/make.sh +++ b/make.sh @@ -70,13 +70,11 @@ if [[ "${DEPS}" == "1" ]]; then if [ "${OS}" == "Linux" ]; then DISTRO="$(lsb_release -i | awk -F':\t' '{print $2}')" if [[ "${DISTRO}" == "Ubuntu" ]]; then - #sudo apt -y install python3-pip libpython3-dev python3-setuptools && pip3 install -U numpy cython && pip3 install -U spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (linux), exiting." pip3 install -U spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (linux), exiting." else exiterr "deps failed (unsupported linux distro ${DISTRO}), exiting." fi elif [ "${OS}" == "Darwin" ]; then - #pip3 install -U numpy spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (mac), exiting." pip3 install -U spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (mac), exiting." else exiterr "deps failed (unsupported os ${OS}), exiting." From 05ce294af882ff20c2f8ec7e1bf0d140525a7070 Mon Sep 17 00:00:00 2001 From: Kristofer Berggren Date: Fri, 11 Dec 2020 18:21:56 +0800 Subject: [PATCH 9/9] fix failing tests and do minor python3 touch ups --- CMakeLists.txt | 2 +- README.md | 2 +- src/spacy/nlp.cpp | 2 +- src/spacy/spacy.cpp | 6 +++--- src/spacy/token.cpp | 4 ++-- src/spacy/token.h | 2 +- tests/test_token.cpp | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index beb8d4f..7c7bfff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ # Project cmake_minimum_required(VERSION 3.1 FATAL_ERROR) -project(spacy-cpp VERSION 1.03 LANGUAGES CXX) +project(spacy-cpp VERSION 1.04 LANGUAGES CXX) set (CMAKE_CXX_STANDARD 11) if(MSVC) if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") diff --git a/README.md b/README.md index 1d74141..0aaacd1 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ import spacy nlp = spacy.load("en_core_web_sm") doc = nlp(u"This is a sentence.") for token in doc: - print token.text + " [" + token.pos_ + "]" + print (token.text + " [" + token.pos_ + "]") ``` diff --git a/src/spacy/nlp.cpp b/src/spacy/nlp.cpp index dac792f..87c9bd7 100644 --- a/src/spacy/nlp.cpp +++ b/src/spacy/nlp.cpp @@ -27,7 +27,7 @@ namespace Spacy PyObjectPtr text(Python::get_object(p_text)); std::vector args = std::vector({text}); PyObjectPtr doc(Python::call_method(m_nlp, args)); - return Doc(doc); + return doc; } Vocab Nlp::vocab() const diff --git a/src/spacy/spacy.cpp b/src/spacy/spacy.cpp index e9e02cf..017265a 100644 --- a/src/spacy/spacy.cpp +++ b/src/spacy/spacy.cpp @@ -25,7 +25,7 @@ namespace Spacy { if (m_spacy.get() == nullptr) { - throw std::runtime_error("No module named spacy. Try: pip install -U spacy"); + throw std::runtime_error("No module named spacy. Try: pip3 install -U spacy"); } } @@ -41,9 +41,9 @@ namespace Spacy if (nlp.get() == nullptr) { throw std::runtime_error("Can't find model '" + p_model + "'. " - "Try: python -m spacy download " + p_model); + "Try: python3 -m spacy download " + p_model); } - return Nlp(nlp); + return nlp; } const Attrs& Spacy::attrs() diff --git a/src/spacy/token.cpp b/src/spacy/token.cpp index 7b31cbb..9c1e290 100644 --- a/src/spacy/token.cpp +++ b/src/spacy/token.cpp @@ -223,9 +223,9 @@ namespace Spacy return Python::get_attr_value(m_token, "prob"); } - long Token::rank() const + double Token::rank() const { - return Python::get_attr_value(m_token, "rank"); + return Python::get_attr_value(m_token, "rank"); } double Token::sentiment() const diff --git a/src/spacy/token.h b/src/spacy/token.h index 8499dd9..43723f1 100644 --- a/src/spacy/token.h +++ b/src/spacy/token.h @@ -69,7 +69,7 @@ namespace Spacy long pos() const; std::string pos_() const; double prob() const; - long rank() const; + double rank() const; double sentiment() const; long shape() const; std::string shape_() const; diff --git a/tests/test_token.cpp b/tests/test_token.cpp index 097d6fe..6041df7 100644 --- a/tests/test_token.cpp +++ b/tests/test_token.cpp @@ -385,7 +385,7 @@ int main() Spacy::Token back = doc.tokens().at(2); unittest::ExpectEqual(std::string, give.tag_(), "VB"); unittest::ExpectEqual(std::string, it.tag_(), "PRP"); - unittest::ExpectEqual(std::string, back.tag_(), "RP"); + unittest::ExpectEqual(std::string, back.tag_(), "RB"); } // Token::text