Skip to content

Commit

Permalink
adjustments for new spacy api and model
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Nov 15, 2019
1 parent e57bc60 commit 451c73a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
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.01 LANGUAGES CXX)
project(spacy-cpp VERSION 1.02 LANGUAGES CXX)
set (CMAKE_CXX_STANDARD 11)
if(MSVC)
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
Expand Down
16 changes: 15 additions & 1 deletion src/spacy/python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace Spacy
template <>
double Python::Convert<double>::get_value(PyObjectPtr p_obj)
{
assert(PyFloat_Check(p_obj.get()));
assert(Custom_PyFloat_Check(p_obj));
return PyFloat_AsDouble(p_obj.get());
}

Expand Down Expand Up @@ -112,4 +112,18 @@ namespace Spacy
{
return PyObjectPtr(PyUnicode_FromStringAndSize(p_val.c_str(), p_val.size()));
}

bool Python::Custom_PyFloat_Check(PyObjectPtr p_obj)
{
if (PyFloat_Check(p_obj.get()))
{
return true;
}
else
{
PyObjectPtr __float__(PyObject_HasAttrString(p_obj.get(), "__float__") ?
PyObject_GetAttrString(p_obj.get(), "__float__") : nullptr);
return (__float__.get() != nullptr) ? PyCallable_Check(__float__.get()) : false;
}
}
}
4 changes: 3 additions & 1 deletion src/spacy/python.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ namespace Spacy
assert(0);
}
};


static bool Custom_PyFloat_Check(PyObjectPtr p_obj);

private:
std::shared_ptr<char*> m_argv;
};
Expand Down
4 changes: 2 additions & 2 deletions tests/test_token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ int main()
Spacy::Token back = doc.tokens().at(2);
unittest::ExpectEqual(std::string, give.pos_(), "VERB");
unittest::ExpectEqual(std::string, it.pos_(), "PRON");
unittest::ExpectEqual(std::string, back.pos_(), "PART");
unittest::ExpectEqual(std::string, back.pos_(), "ADV");
}

// Token::prob
Expand Down 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 451c73a

Please sign in to comment.