Code Monkey home page Code Monkey logo

spacy-cpp's Introduction

Spacy-cpp

Linux Mac
Linux macOS

Spacy-cpp is a C++ wrapper library for the NLP library spaCy. This project is not affiliated with spaCy, it is however distributed under the same type of license (MIT).

The goal of spacy-cpp is to expose the functionality of spaCy to C++ applications, and to provide an API that is similar to that of spaCy, enabling rapid development in Python and simple porting to C++.

Spacy-cpp is under development and does not yet support all API's of spaCy, refer to the API Documentation section below.

Example Usage

Simple POS tagging example using spacy-cpp:

Spacy::Spacy spacy;
auto nlp = spacy.load("en_core_web_sm");
auto doc = nlp.parse("This is a sentence.");
for (auto& token : doc.tokens())
    std::cout << token.text() << " [" << token.pos_() << "]\n";

For reference - doing the same using the spaCy API in Python:

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_ + "]")

Supported Platforms

Spacy-cpp is implemented using C++11 with the intention of being portable. Current version has been tested on:

  • macOS Ventura 13.1
  • Ubuntu 22.04 LTS

Pre-requisites

Spacy-cpp requires python development library, pip, spaCy and typically a spaCy model.

macOS

Install build dependencies:

brew install cmake python

Install spaCy and an English model:

pip3 install -U spacy
python3 -m spacy download en_core_web_sm

Ubuntu

Install build dependencies:

sudo apt install cmake python3-pip libpython3-dev

Install spaCy and an English model:

pip3 install -U spacy
python3 -m spacy download en_core_web_sm

Installation

Spacy-cpp can be used either as a shared library or as a header-only library.

Shared Library

Build and install spacy-cpp:

mkdir -p build && cd build && cmake .. && make && sudo make install

Link library:

-lspacy

Include header (convenience header including all modules):

#include <spacy/spacy>

Header-only Library

Copy the src/spacy directory to the source directory of your project. Then define SPACY_HEADER_ONLY and include headers needed (spacy/spacy includes all headers):

#define SPACY_HEADER_ONLY
#include <spacy/spacy>

CMake Usage

The source tree includes two CMake project examples:

FAQ

No module named spacy. Why does spacy-cpp not find spacy?

If a system has more than one Python installation, each of the installations will have its own set of pip-installed Python packages. One must ensure that spacy is installed for the Python version used by spacy-cpp (alternatively point spacy-cpp to the desired Python installation). When building spacy-cpp using CMake (example: ./make.sh tests) the Python version used will be output, for example PYTHON_EXECUTABLE="/usr/local/bin/python3.11". Use this interpreter to ensure spacy works correctly in Python, example: /usr/local/bin/python3.11 ./examples/python-spacy-usage.py. If not working, use this Python version to install spacy and a language model:

/usr/local/bin/python3.11 -m pip install -U spacy
/usr/local/bin/python3.11 -m spacy download en_core_web_sm

API Documentation

Spacy-cpp is under development and does not support the complete spaCy API yet.

Supported Classes

Supported Methods / Attributes

Attrs supports all attribute constants.

Doc supports the following methods / attributes:

  • count_by()
  • ents()
  • has_vector()
  • is_parsed()
  • is_tagged()
  • noun_chunks()
  • sentiment()
  • sents()
  • similarity()
  • text()
  • text_with_ws()
  • tokens()
  • vector_norm()

MorphAnalysis supports the following methods / attributes:

  • get()
  • str()
  • to_dict()

Nlp supports the following methods / attributes:

  • parse()
  • vocab()

Spacy supports the following methods / attributes:

  • load()
  • attrs()

Span supports the following methods / attributes:

  • doc()
  • label()
  • label_()
  • lemma_()
  • orth_()
  • root()
  • sentiment()
  • text()
  • text_with_ws()
  • tokens()
  • vector_norm()

StringStore supports the following methods / attributes:

  • add()

Token supports the following methods / attributes:

  • check_flag()
  • children()
  • cluster()
  • dep()
  • dep_()
  • ent_iob_()
  • has_vector()
  • head()
  • i()
  • idx()
  • is_alpha()
  • is_ascii()
  • is_bracket()
  • is_digit()
  • is_left_punct()
  • is_lower()
  • is_oov()
  • is_punct()
  • is_quote()
  • is_right_punct()
  • is_space()
  • is_stop()
  • is_title()
  • is_upper()
  • lang()
  • lang_()
  • lemma()
  • lemma_()
  • like_email()
  • like_num()
  • like_url()
  • lower()
  • lower_()
  • morph()
  • nbor()
  • norm()
  • norm_()
  • orth()
  • orth_()
  • pos()
  • pos_()
  • prob()
  • rank()
  • sentiment()
  • shape()
  • shape_()
  • tag()
  • tag_()
  • text()
  • text_with_ws()
  • whitespace_()

Vocab supports the following methods / attributes:

  • strings()

Key Differences with spaCy

  1. In spacy-cpp Nlp cannot be called as a method in order to perform parsing. Instead one need to use Nlp::parse().
  2. In spacy-cpp Doc is not an iterable, instead one need to use Doc::token() to get a std::vector of the tokens in the Doc. Likewise for Span.
  3. In spacy-cpp non-ASCII strings must be UTF-8 encoded in order to be correctly processed.

Technical Details

Spacy-cpp uses cmake for its tests. Commands to build and execute the test suite:

mkdir -p build && cd build && cmake -DSPACYCPP_BUILD_TESTS=ON .. && make && ctest --output-on-failure ; cd -

License

Spacy-cpp is distributed under the MIT license. See LICENSE file.

Contributions

Bugs, PRs, etc are welcome on the GitHub project page https://github.com/d99kris/spacy-cpp

Keywords

c++, c++11, natural language processing, nlp, spacy.

spacy-cpp's People

Contributors

d99kris avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spacy-cpp's Issues

Would iOS Support Be Possible?

Out of curiosity, can you imagine any way in which we could embed python and run your library on iOS? I currently use an external Python server to generate spacy output that I send back to the client, but it would be great to keep everything on-device. If it’s possible, would it be worth it? It would definitely need to run in a background thread. I also think the model might be an issue since it’s unclear where that would be stored/how it would be accessed. I’m not sure if an ios device could handle all of this.

Failed to build (Xcode)

I believe I have all the pre-requisites in place. But after running mkdir -p build && cd build && cmake .. && make && sudo make install, I got the following output:

Scanning dependencies of target test_header_spacy
[  2%] Building CXX object CMakeFiles/test_header_spacy.dir/tests/test_spacy.cpp.o
In file included from /Volumes/Workspace/spacy-cpp-master/tests/test_spacy.cpp:11:
In file included from /Volumes/Workspace/spacy-cpp-master/src/spacy/spacy:13:
In file included from /Volumes/Workspace/spacy-cpp-master/src/spacy/doc.h:55:
/Volumes/Workspace/spacy-cpp-master/src/spacy/doc.cpp:38:65: warning: 'mem_fun_ref<void, Spacy::Span, Spacy::Doc *>' is deprecated [-Wdeprecated-declarations]
    std::for_each(spans.begin(), spans.end(), std::bind2nd(std::mem_fun_ref(&Span::set_parent), this));
                                                                ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/functional:1187:1: note: 'mem_fun_ref<void, Spacy::Span, Spacy::Doc *>' has been explicitly marked deprecated
      here
_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:1101:39: note: expanded from macro '_LIBCPP_DEPRECATED_IN_CXX11'
#  define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
                                      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:1090:48: note: expanded from macro '_LIBCPP_DEPRECATED'
#    define _LIBCPP_DEPRECATED __attribute__ ((deprecated))
                                               ^
In file included from /Volumes/Workspace/spacy-cpp-master/tests/test_spacy.cpp:11:
In file included from /Volumes/Workspace/spacy-cpp-master/src/spacy/spacy:13:
In file included from /Volumes/Workspace/spacy-cpp-master/src/spacy/doc.h:55:
/Volumes/Workspace/spacy-cpp-master/src/spacy/doc.cpp:38:52: warning: 'bind2nd<std::__1::mem_fun1_ref_t<void, Spacy::Span, Spacy::Doc *>, const Spacy::Doc *>' is deprecated [-Wdeprecated-declarations]
    std::for_each(spans.begin(), spans.end(), std::bind2nd(std::mem_fun_ref(&Span::set_parent), this));
                                                   ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/functional:1079:1: note: 'bind2nd<std::__1::mem_fun1_ref_t<void, Spacy::Span, Spacy::Doc *>, const Spacy::Doc
      *>' has been explicitly marked deprecated here
_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:1101:39: note: expanded from macro '_LIBCPP_DEPRECATED_IN_CXX11'
#  define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
                                      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:1090:48: note: expanded from macro '_LIBCPP_DEPRECATED'
#    define _LIBCPP_DEPRECATED __attribute__ ((deprecated))
                                               ^
In file included from /Volumes/Workspace/spacy-cpp-master/tests/test_spacy.cpp:11:
In file included from /Volumes/Workspace/spacy-cpp-master/src/spacy/spacy:13:
In file included from /Volumes/Workspace/spacy-cpp-master/src/spacy/doc.h:55:
/Volumes/Workspace/spacy-cpp-master/src/spacy/doc.cpp:60:65: warning: 'mem_fun_ref<void, Spacy::Span, Spacy::Doc *>' is deprecated [-Wdeprecated-declarations]
    std::for_each(spans.begin(), spans.end(), std::bind2nd(std::mem_fun_ref(&Span::set_parent), this));
                                                                ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/functional:1187:1: note: 'mem_fun_ref<void, Spacy::Span, Spacy::Doc *>' has been explicitly marked deprecated
      here
_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:1101:39: note: expanded from macro '_LIBCPP_DEPRECATED_IN_CXX11'
#  define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
                                      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:1090:48: note: expanded from macro '_LIBCPP_DEPRECATED'
#    define _LIBCPP_DEPRECATED __attribute__ ((deprecated))
                                               ^
In file included from /Volumes/Workspace/spacy-cpp-master/tests/test_spacy.cpp:11:
In file included from /Volumes/Workspace/spacy-cpp-master/src/spacy/spacy:13:
In file included from /Volumes/Workspace/spacy-cpp-master/src/spacy/doc.h:55:
/Volumes/Workspace/spacy-cpp-master/src/spacy/doc.cpp:60:52: warning: 'bind2nd<std::__1::mem_fun1_ref_t<void, Spacy::Span, Spacy::Doc *>, const Spacy::Doc *>' is deprecated [-Wdeprecated-declarations]
    std::for_each(spans.begin(), spans.end(), std::bind2nd(std::mem_fun_ref(&Span::set_parent), this));
                                                   ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/functional:1079:1: note: 'bind2nd<std::__1::mem_fun1_ref_t<void, Spacy::Span, Spacy::Doc *>, const Spacy::Doc
      *>' has been explicitly marked deprecated here
_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:1101:39: note: expanded from macro '_LIBCPP_DEPRECATED_IN_CXX11'
#  define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
                                      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:1090:48: note: expanded from macro '_LIBCPP_DEPRECATED'
#    define _LIBCPP_DEPRECATED __attribute__ ((deprecated))
                                               ^
In file included from /Volumes/Workspace/spacy-cpp-master/tests/test_spacy.cpp:11:
In file included from /Volumes/Workspace/spacy-cpp-master/src/spacy/spacy:13:
In file included from /Volumes/Workspace/spacy-cpp-master/src/spacy/doc.h:55:
/Volumes/Workspace/spacy-cpp-master/src/spacy/doc.cpp:72:65: warning: 'mem_fun_ref<void, Spacy::Span, Spacy::Doc *>' is deprecated [-Wdeprecated-declarations]
    std::for_each(spans.begin(), spans.end(), std::bind2nd(std::mem_fun_ref(&Span::set_parent), this));
                                                                ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/functional:1187:1: note: 'mem_fun_ref<void, Spacy::Span, Spacy::Doc *>' has been explicitly marked deprecated
      here
_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:1101:39: note: expanded from macro '_LIBCPP_DEPRECATED_IN_CXX11'
#  define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
                                      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:1090:48: note: expanded from macro '_LIBCPP_DEPRECATED'
#    define _LIBCPP_DEPRECATED __attribute__ ((deprecated))
                                               ^
In file included from /Volumes/Workspace/spacy-cpp-master/tests/test_spacy.cpp:11:
In file included from /Volumes/Workspace/spacy-cpp-master/src/spacy/spacy:13:
In file included from /Volumes/Workspace/spacy-cpp-master/src/spacy/doc.h:55:
/Volumes/Workspace/spacy-cpp-master/src/spacy/doc.cpp:72:52: warning: 'bind2nd<std::__1::mem_fun1_ref_t<void, Spacy::Span, Spacy::Doc *>, const Spacy::Doc *>' is deprecated [-Wdeprecated-declarations]
    std::for_each(spans.begin(), spans.end(), std::bind2nd(std::mem_fun_ref(&Span::set_parent), this));
                                                   ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/functional:1079:1: note: 'bind2nd<std::__1::mem_fun1_ref_t<void, Spacy::Span, Spacy::Doc *>, const Spacy::Doc
      *>' has been explicitly marked deprecated here
_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:1101:39: note: expanded from macro '_LIBCPP_DEPRECATED_IN_CXX11'
#  define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
                                      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:1090:48: note: expanded from macro '_LIBCPP_DEPRECATED'
#    define _LIBCPP_DEPRECATED __attribute__ ((deprecated))
                                               ^
In file included from /Volumes/Workspace/spacy-cpp-master/tests/test_spacy.cpp:10:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iostream:38:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__locale:15:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:505:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string_view:176:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__string:57:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:645:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/functional:1082:13: error: no matching constructor for initialization of
      'binder2nd<std::__1::mem_fun1_ref_t<void, Spacy::Span, Spacy::Doc *> >'
    {return binder2nd<__Operation>(__op, __x);}
            ^                      ~~~~~~~~~
/Volumes/Workspace/spacy-cpp-master/src/spacy/doc.cpp:38:52: note: in instantiation of function template specialization 'std::__1::bind2nd<std::__1::mem_fun1_ref_t<void, Spacy::Span, Spacy::Doc *>, const Spacy::Doc
      *>' requested here
    std::for_each(spans.begin(), spans.end(), std::bind2nd(std::mem_fun_ref(&Span::set_parent), this));
                                                   ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/functional:1068:5: note: candidate constructor not viable: 2nd argument ('const Spacy::Doc *const') would lose
      const qualifier
    binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/functional:1059:56: note: candidate constructor (the implicit copy constructor) not viable: requires 1
      argument, but 2 were provided
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder2nd
                                                       ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/functional:1059:56: note: candidate constructor (the implicit move constructor) not viable: requires 1
      argument, but 2 were provided
6 warnings and 1 error generated.
make[2]: *** [CMakeFiles/test_header_spacy.dir/tests/test_spacy.cpp.o] Error 1
make[1]: *** [CMakeFiles/test_header_spacy.dir/all] Error 2
make: *** [all] Error 2

For reference:
-- The CXX compiler identification is AppleClang 11.0.0.11000033

I've never built a c++ project before and am a total newb in c++ world. So apologies if this is my fault.

Adding this as a library in bazel is creating segmentation fault(core dumped) error

I don't know if you have worked with bazel or not but if you could help me make it work in bazel then it would be awesome. Thanks.

This is the build file I am using for spacy:

cc_library(
    name = "spacy",
    srcs=["attrs.cpp", "doc.cpp", "nlp.cpp", "pyobjectptr.cpp", "python.cpp", "spacy.cpp", "span.cpp", "stringstore.cpp", "token.cpp", "vocab.cpp"],
    hdrs =["attrs.h","doc.h","nlp.h","pyobjectptr.h","python.h","spacy.h","span.h","stringstore.h","token.h","vocab.h"],
    visibility= ["//visibility:public"],
    copts = ["-std=c++11"],
)

In my main proj build file , I am adding this as a dependency:
//spacy:spacy

And in my project files
I am including them as
#include "attrs.h"
#include "doc.h"
#include "nlp.h"
#include "pyobjectptr.h"
#include "python.h"
#include "spacy.h"
#include "span.h"
#include "stringstore.h"
#include "token.h"
#include "vocab.h"

But when the code reaches the line:
Spacy::Spacy spacy;

It is giving error

Segmentation fault(Core dumped)

Calling c++ code from python using pybind11 creates an error when creating Spacy::Spacy object on stack but not as a pointer

Here's a minimal example to reproduce this error:

cmake-add-subdirectory-hdr.zip

To reproduce this

cd build
cmake .. && make
cd ../src/
python pyTest.py 

Why does the following code (creating Spacy::Spacy object on stack) creates an error:

  Spacy::Spacy spacy;
  auto nlp = spacy.load("en_core_web_sm");
Fatal Python error: PyThreadState_Get: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL)
Python runtime state: finalizing (tstate=0x00000001029b63c8)

Abort trap: 6

But this one works?

  Spacy::Spacy* spacy = new Spacy::Spacy();
  auto nlp = spacy->load("en_core_web_sm");

exception of type std::runtime_error: No module named spacy. Try: pip3 install -U spacy

I'm getting the same error after building the header only example.

I'm running ./exprog1
And get:

libc++abi: terminating with uncaught exception of type std::runtime_error: No module named spacy. Try: pip3 install -U spacy
Abort trap: 6

I can successfully reproduce the Python example usage:

>>> 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_ + "]")
... 
This [PRON]
is [AUX]
a [DET]
sentence [NOUN]
. [PUNCT]

Some more info - Cmake:

-- The C compiler identification is AppleClang 13.0.0.13000029
-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonLibs: /usr/local/Frameworks/Python.framework/Versions/3.11/lib/libpython3.11.dylib (found suitable version "3.11.0", minimum required is "3") 
-- Found PythonInterp: /Users/ruby/venv11_2/bin/python3 (found suitable version "3.11.1", minimum required is "3") 
-- Build tests: OFF
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/ruby/Downloads/test/cmake-add-subdirectory-hdr/build

Make:

[  7%] Building CXX object CMakeFiles/exprog1.dir/src/exprog1.cpp.o
In file included from /Users/ruby/Downloads/test/cmake-add-subdirectory-hdr/src/exprog1.cpp:5:
In file included from /Users/ruby/Downloads/test/cmake-add-subdirectory-hdr/spacy-cpp/src/spacy/spacy:12:
In file included from /Users/ruby/Downloads/test/cmake-add-subdirectory-hdr/spacy-cpp/src/spacy/attrs.h:72:
In file included from /Users/ruby/Downloads/test/cmake-add-subdirectory-hdr/spacy-cpp/src/spacy/attrs.cpp:13:
In file included from /Users/ruby/Downloads/test/cmake-add-subdirectory-hdr/spacy-cpp/src/spacy/python.h:210:
/Users/ruby/Downloads/test/cmake-add-subdirectory-hdr/spacy-cpp/src/spacy/python.cpp:42:5: warning: 'PySys_SetArgv' is deprecated [-Wdeprecated-declarations]
    PySys_SetArgv(0, m_argv.get());
    ^
/usr/local/Frameworks/Python.framework/Versions/3.11/include/python3.11/sysmodule.h:13:1: note: 'PySys_SetArgv' has been explicitly marked deprecated here
Py_DEPRECATED(3.11) PyAPI_FUNC(void) PySys_SetArgv(int, wchar_t **);
^
/usr/local/Frameworks/Python.framework/Versions/3.11/include/python3.11/pyport.h:336:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                     ^
1 warning generated.
[ 15%] Linking CXX executable exprog1
[ 15%] Built target exprog1
[ 23%] Building CXX object spacy-cpp/CMakeFiles/spacy.dir/src/spacy/attrs.cpp.o
[ 30%] Building CXX object spacy-cpp/CMakeFiles/spacy.dir/src/spacy/nlp.cpp.o
[ 38%] Building CXX object spacy-cpp/CMakeFiles/spacy.dir/src/spacy/python.cpp.o
/Users/ruby/Downloads/test/cmake-add-subdirectory-hdr/spacy-cpp/src/spacy/python.cpp:42:5: warning: 'PySys_SetArgv' is deprecated [-Wdeprecated-declarations]
    PySys_SetArgv(0, m_argv.get());
    ^
/usr/local/Frameworks/Python.framework/Versions/3.11/include/python3.11/sysmodule.h:13:1: note: 'PySys_SetArgv' has been explicitly marked deprecated here
Py_DEPRECATED(3.11) PyAPI_FUNC(void) PySys_SetArgv(int, wchar_t **);
^
/usr/local/Frameworks/Python.framework/Versions/3.11/include/python3.11/pyport.h:336:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                     ^
1 warning generated.
[ 46%] Building CXX object spacy-cpp/CMakeFiles/spacy.dir/src/spacy/span.cpp.o
[ 53%] Building CXX object spacy-cpp/CMakeFiles/spacy.dir/src/spacy/doc.cpp.o
[ 61%] Building CXX object spacy-cpp/CMakeFiles/spacy.dir/src/spacy/pyobjectptr.cpp.o
[ 69%] Building CXX object spacy-cpp/CMakeFiles/spacy.dir/src/spacy/spacy.cpp.o
[ 76%] Building CXX object spacy-cpp/CMakeFiles/spacy.dir/src/spacy/stringstore.cpp.o
[ 84%] Building CXX object spacy-cpp/CMakeFiles/spacy.dir/src/spacy/token.cpp.o
[ 92%] Building CXX object spacy-cpp/CMakeFiles/spacy.dir/src/spacy/vocab.cpp.o
[100%] Linking CXX shared library libspacy.dylib
[100%] Built target spacy

No module named spacy. Try: pip install -U spacy

I got this when I want to instantiate a Spacy object. But I'm sure I have installed spacy and I can run python -m spacy correctly. Cloud you please provide some possible reasons for this situation?

Does this still build?

Hi!

I want to use this library in an app but I can't get it to work.

The first obstacle was two error: 'runtime_error' is not a member of 'std' thrown in src/spacy/spacy.cpp file. I overcame this by adding #include <stdexcept> in this file.

The thing is that even after this, I can't seem to be able to use it in my project. #include <spacy/spacy> throws No such file or directory error.

My CMakeLists.txt is

cmake_minimum_required(VERSION 3.12)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# create project
project(myapp VERSION 0.1)

# add executable
add_executable(hello src/main.cpp)

# add CPM
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM.cmake")

if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
    message(STATUS "Downloading CPM.cmake")
    file(DOWNLOAD https://github.com/TheLartians/CPM.cmake/releases/latest/download/CPM.cmake ${CPM_DOWNLOAD_LOCATION})
endif()

include(${CPM_DOWNLOAD_LOCATION})

# add spacy
CPMAddPackage(
  NAME spacy
  GITHUB_REPOSITORY d99kris/spacy-cpp
  VERSION 1.04
)
target_link_libraries(hello PUBLIC spacy)

I would appreciate it if you gave me some insight.

Windows build?

Hi,

Is there a Windows build? Are there steps to follow to for Windows? Please advise. Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.