Replies: 2 comments
-
Hi @VirArman - spacy-cpp is implemented as a simple wrapper around the python library spacy, so all calls goes through a Python run-time and some interfacing like library import are not exactly the same as when using a Python interpreter. Ideally your code example should work, but I think I'll need to exclude it from the scope of spacy-cpp. You may work around the issue by using a single Spacy instance, for example: int main()
{
Spacy::Spacy spacy;
for(int i = 0; i < 2; ++i ) {
auto nlp = spacy.load("en_core_web_sm");
auto doc0 = nlp.parse("he fire his house");
for (auto& token : doc0.tokens())
{
std::cout << token.text() << " [" << token.pos_() << "],";
std::cout << "[" << token.lemma_() << "]," << "\n";
}
std::cout << std::endl;
}
} You'll likely also want to bring out the |
Beta Was this translation helpful? Give feedback.
-
Thanks @d99kris, the solution you offered worked |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When I try to create spacy object in for loop during the second iteration the spacy constructor does not see the spacy import path.
Tried to reproduce same error in spacy python version and the code worked without any problem.
I would like to know the possible cause or solution for this problem
int main()
{
for(int i = 0; i < 2; ++i ) {
Spacy::Spacy spacy;
auto nlp = spacy.load("en_core_web_sm");
auto doc0 = nlp.parse("he fire his house");
for (auto& token : doc0.tokens())
{
std::cout << token.text() << " [" << token.pos_() << "],";
std::cout << "[" << token.lemma_() << "]," << "\n";
}
std::cout << std::endl;
}
}
Beta Was this translation helpful? Give feedback.
All reactions