Skip to content

Commit

Permalink
Merge pull request #7 from d99kris/github-actions-ci
Browse files Browse the repository at this point in the history
migrate to github actions ci
  • Loading branch information
d99kris authored Dec 11, 2020
2 parents 7531fc2 + 05ce294 commit bca02a8
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 19 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Linux

on: [push, pull_request]

jobs:
linux-build:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Build Linux
run: ./make.sh all
12 changes: 12 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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]")
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down Expand Up @@ -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_ + "]")
```


Expand Down
112 changes: 112 additions & 0 deletions make.sh
Original file line number Diff line number Diff line change
@@ -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 <deps|build|tests|doc|install|all>"
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
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
6 changes: 0 additions & 6 deletions run.sh

This file was deleted.

2 changes: 1 addition & 1 deletion src/spacy/nlp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Spacy
PyObjectPtr text(Python::get_object<std::string>(p_text));
std::vector<PyObjectPtr> args = std::vector<PyObjectPtr>({text});
PyObjectPtr doc(Python::call_method<PyObjectPtr>(m_nlp, args));
return Doc(doc);
return doc;
}

Vocab Nlp::vocab() const
Expand Down
6 changes: 3 additions & 3 deletions src/spacy/spacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/spacy/token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ namespace Spacy
return Python::get_attr_value<double>(m_token, "prob");
}

long Token::rank() const
double Token::rank() const
{
return Python::get_attr_value<long>(m_token, "rank");
return Python::get_attr_value<double>(m_token, "rank");
}

double Token::sentiment() const
Expand Down
2 changes: 1 addition & 1 deletion src/spacy/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/test_token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bca02a8

Please sign in to comment.