Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#

CXX = c++
CXXFLAGS = -pthread -std=c++0x
CXXFLAGS = -pthread -std=c++0x -fPIC -m64
OBJS = args.o dictionary.o productquantizer.o matrix.o shmem_matrix.o qmatrix.o vector.o model.o utils.o fasttext.o
INCLUDES = -I.
ifneq ($(shell uname),Darwin)
Expand Down Expand Up @@ -54,5 +54,11 @@ fasttext.o: src/fasttext.cc src/*.h
fasttext: $(OBJS) src/fasttext.cc
$(CXX) $(CXXFLAGS) $(OBJS) src/main.cc -o fasttext $(LINK_RT)

sent2vec.o: $(OBJS) src/sent2vec.cc src/*.h
$(CXX) $(CXXFLAGS) -c src/sent2vec.cc

so: $(OBJS) sent2vec.o
$(CXX) $(CXXFLAGS) $(OBJS) sent2vec.o -shared -o libsent2vec.so $(LINK_RT)

clean:
rm -rf *.o fasttext
rm -rf *.o *.so fasttext
38 changes: 38 additions & 0 deletions src/sent2vec.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

#include "fasttext.h"

using namespace fasttext;

extern "C" void* loadModel(char* path)
{
FastText* fastText = new FastText();
(*fastText).loadModel(std::string(path));
return fastText;
}

extern "C" void freeModel(void* modelPtr)
{
FastText* model = (FastText*)modelPtr;
free(model);
}

extern "C" int getDimension(void* modelPtr)
{
FastText* model = (FastText*)modelPtr;
return (*model).getDimension();
}

extern "C" void getSentenceVector(
void* modelPtr,
char* input,
float* svec
)
{
FastText* model = (FastText*)modelPtr;
int dim = (*model).getDimension();
std::vector<std::string> strList(1);
strList[0] = std::string(input);
std::vector<float> vector(dim);
(*model).textVectors(strList, 1, vector);
memcpy(svec, &vector[0], vector.size() * sizeof(float));
}