Skip to content

Commit bca02a8

Browse files
authored
Merge pull request #7 from d99kris/github-actions-ci
migrate to github actions ci
2 parents 7531fc2 + 05ce294 commit bca02a8

11 files changed

Lines changed: 149 additions & 19 deletions

File tree

.github/workflows/linux.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Linux
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
linux-build:
7+
runs-on: ubuntu-20.04
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v1
11+
- name: Build Linux
12+
run: ./make.sh all

.github/workflows/macos.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: macOS
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
mac-build:
7+
runs-on: macos-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v1
11+
- name: Build macOS
12+
run: ./make.sh all

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
# Project
1111
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
12-
project(spacy-cpp VERSION 1.03 LANGUAGES CXX)
12+
project(spacy-cpp VERSION 1.04 LANGUAGES CXX)
1313
set (CMAKE_CXX_STANDARD 11)
1414
if(MSVC)
1515
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Spacy-cpp
22
=========
33

4-
| **Linux + Mac** |
5-
|-----------------|
6-
| [![Build status](https://travis-ci.com/d99kris/spacy-cpp.svg?branch=master)](https://travis-ci.com/d99kris/spacy-cpp) |
4+
| **Linux** | **Mac** |
5+
|-----------|---------|
6+
| [![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) |
77

88
Spacy-cpp is a C++ wrapper library for the excellent NLP library [spaCy](https://spacy.io/).
99
This project is not affiliated with spaCy, but it is distributed under the same license (MIT).
@@ -33,7 +33,7 @@ import spacy
3333
nlp = spacy.load("en_core_web_sm")
3434
doc = nlp(u"This is a sentence.")
3535
for token in doc:
36-
print token.text + " [" + token.pos_ + "]"
36+
print (token.text + " [" + token.pos_ + "]")
3737
```
3838

3939

make.sh

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/usr/bin/env bash
2+
3+
# make.sh
4+
#
5+
# Copyright (C) 2020 Kristofer Berggren
6+
# All rights reserved.
7+
#
8+
# See LICENSE for redistribution information.
9+
10+
# exiterr
11+
exiterr()
12+
{
13+
>&2 echo "${1}"
14+
exit 1
15+
}
16+
17+
# process arguments
18+
DEPS="0"
19+
BUILD="0"
20+
TESTS="0"
21+
DOC="0"
22+
INSTALL="0"
23+
case "${1%/}" in
24+
deps)
25+
DEPS="1"
26+
;;
27+
28+
build)
29+
BUILD="1"
30+
;;
31+
32+
test*)
33+
BUILD="1"
34+
TESTS="1"
35+
;;
36+
37+
doc)
38+
BUILD="1"
39+
DOC="1"
40+
;;
41+
42+
install)
43+
BUILD="1"
44+
INSTALL="1"
45+
;;
46+
47+
all)
48+
DEPS="1"
49+
BUILD="1"
50+
TESTS="1"
51+
DOC="1"
52+
INSTALL="1"
53+
;;
54+
55+
*)
56+
echo "usage: make.sh <deps|build|tests|doc|install|all>"
57+
echo " deps - install project dependencies"
58+
echo " build - perform build"
59+
echo " tests - perform build and run tests"
60+
echo " doc - perform build and generate documentation"
61+
echo " install - perform build and install"
62+
echo " all - perform all actions above"
63+
exit 1
64+
;;
65+
esac
66+
67+
# deps
68+
if [[ "${DEPS}" == "1" ]]; then
69+
OS="$(uname)"
70+
if [ "${OS}" == "Linux" ]; then
71+
DISTRO="$(lsb_release -i | awk -F':\t' '{print $2}')"
72+
if [[ "${DISTRO}" == "Ubuntu" ]]; then
73+
pip3 install -U spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (linux), exiting."
74+
else
75+
exiterr "deps failed (unsupported linux distro ${DISTRO}), exiting."
76+
fi
77+
elif [ "${OS}" == "Darwin" ]; then
78+
pip3 install -U spacy && python3 -m spacy download en_core_web_sm || exiterr "deps failed (mac), exiting."
79+
else
80+
exiterr "deps failed (unsupported os ${OS}), exiting."
81+
fi
82+
fi
83+
84+
# build
85+
if [[ "${BUILD}" == "1" ]]; then
86+
mkdir -p build && cd build && cmake .. && make && cd .. || exiterr "build failed, exiting."
87+
fi
88+
89+
# tests
90+
if [[ "${TESTS}" == "1" ]]; then
91+
cd build && ctest --output-on-failure && cd .. || exiterr "tests failed, exiting."
92+
fi
93+
94+
# doc
95+
if [[ "${DOC}" == "1" ]]; then
96+
true || exiterr "doc failed, exiting."
97+
fi
98+
99+
# install
100+
if [[ "${INSTALL}" == "1" ]]; then
101+
OS="$(uname)"
102+
if [ "${OS}" == "Linux" ]; then
103+
cd build && sudo make install && cd .. || exiterr "install failed (linux), exiting."
104+
elif [ "${OS}" == "Darwin" ]; then
105+
cd build && make install && cd .. || exiterr "install failed (mac), exiting."
106+
else
107+
exiterr "install failed (unsupported os ${OS}), exiting."
108+
fi
109+
fi
110+
111+
# exit
112+
exit 0

run.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/spacy/nlp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace Spacy
2727
PyObjectPtr text(Python::get_object<std::string>(p_text));
2828
std::vector<PyObjectPtr> args = std::vector<PyObjectPtr>({text});
2929
PyObjectPtr doc(Python::call_method<PyObjectPtr>(m_nlp, args));
30-
return Doc(doc);
30+
return doc;
3131
}
3232

3333
Vocab Nlp::vocab() const

src/spacy/spacy.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace Spacy
2525
{
2626
if (m_spacy.get() == nullptr)
2727
{
28-
throw std::runtime_error("No module named spacy. Try: pip install -U spacy");
28+
throw std::runtime_error("No module named spacy. Try: pip3 install -U spacy");
2929
}
3030
}
3131

@@ -41,9 +41,9 @@ namespace Spacy
4141
if (nlp.get() == nullptr)
4242
{
4343
throw std::runtime_error("Can't find model '" + p_model + "'. "
44-
"Try: python -m spacy download " + p_model);
44+
"Try: python3 -m spacy download " + p_model);
4545
}
46-
return Nlp(nlp);
46+
return nlp;
4747
}
4848

4949
const Attrs& Spacy::attrs()

src/spacy/token.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ namespace Spacy
223223
return Python::get_attr_value<double>(m_token, "prob");
224224
}
225225

226-
long Token::rank() const
226+
double Token::rank() const
227227
{
228-
return Python::get_attr_value<long>(m_token, "rank");
228+
return Python::get_attr_value<double>(m_token, "rank");
229229
}
230230

231231
double Token::sentiment() const

src/spacy/token.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ namespace Spacy
6969
long pos() const;
7070
std::string pos_() const;
7171
double prob() const;
72-
long rank() const;
72+
double rank() const;
7373
double sentiment() const;
7474
long shape() const;
7575
std::string shape_() const;

0 commit comments

Comments
 (0)