Skip to content

Commit 451c73a

Browse files
committed
adjustments for new spacy api and model
1 parent e57bc60 commit 451c73a

4 files changed

Lines changed: 21 additions & 5 deletions

File tree

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.01 LANGUAGES CXX)
12+
project(spacy-cpp VERSION 1.02 LANGUAGES CXX)
1313
set (CMAKE_CXX_STANDARD 11)
1414
if(MSVC)
1515
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")

src/spacy/python.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace Spacy
4848
template <>
4949
double Python::Convert<double>::get_value(PyObjectPtr p_obj)
5050
{
51-
assert(PyFloat_Check(p_obj.get()));
51+
assert(Custom_PyFloat_Check(p_obj));
5252
return PyFloat_AsDouble(p_obj.get());
5353
}
5454

@@ -112,4 +112,18 @@ namespace Spacy
112112
{
113113
return PyObjectPtr(PyUnicode_FromStringAndSize(p_val.c_str(), p_val.size()));
114114
}
115+
116+
bool Python::Custom_PyFloat_Check(PyObjectPtr p_obj)
117+
{
118+
if (PyFloat_Check(p_obj.get()))
119+
{
120+
return true;
121+
}
122+
else
123+
{
124+
PyObjectPtr __float__(PyObject_HasAttrString(p_obj.get(), "__float__") ?
125+
PyObject_GetAttrString(p_obj.get(), "__float__") : nullptr);
126+
return (__float__.get() != nullptr) ? PyCallable_Check(__float__.get()) : false;
127+
}
128+
}
115129
}

src/spacy/python.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ namespace Spacy
142142
assert(0);
143143
}
144144
};
145-
145+
146+
static bool Custom_PyFloat_Check(PyObjectPtr p_obj);
147+
146148
private:
147149
std::shared_ptr<char*> m_argv;
148150
};

tests/test_token.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ int main()
330330
Spacy::Token back = doc.tokens().at(2);
331331
unittest::ExpectEqual(std::string, give.pos_(), "VERB");
332332
unittest::ExpectEqual(std::string, it.pos_(), "PRON");
333-
unittest::ExpectEqual(std::string, back.pos_(), "PART");
333+
unittest::ExpectEqual(std::string, back.pos_(), "ADV");
334334
}
335335

336336
// Token::prob
@@ -385,7 +385,7 @@ int main()
385385
Spacy::Token back = doc.tokens().at(2);
386386
unittest::ExpectEqual(std::string, give.tag_(), "VB");
387387
unittest::ExpectEqual(std::string, it.tag_(), "PRP");
388-
unittest::ExpectEqual(std::string, back.tag_(), "RP");
388+
unittest::ExpectEqual(std::string, back.tag_(), "RB");
389389
}
390390

391391
// Token::text

0 commit comments

Comments
 (0)