Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lexicon update for the pybind module. #73

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
77 changes: 77 additions & 0 deletions src/Tools/LibRASR/PybindModule.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
#include <string>

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/complex.h>
#include <pybind11/functional.h>
#include <pybind11/chrono.h>
#include <pybind11/iostream.h>

#include <Am/Module.hh>
#include <Audio/Module.hh>
#include <Bliss/CorpusDescription.hh>
#include <Bliss/CorpusParser.hh>
#include <Bliss/Lexicon.hh>
#include <Core/Application.hh>
#include <Flf/Module.hh>
#include <Flow/Module.hh>
#include <Lm/Module.hh>
#include <Math/Module.hh>
#include <Mm/Module.hh>
#include <Modules.hh>
#ifdef MODULE_NN
#include <Nn/Module.hh>
#endif
#ifdef MODULE_ONNX
#include <Onnx/Module.hh>
#endif
#include <Signal/Module.hh>
#include <Speech/Module.hh>
#ifdef MODULE_TENSORFLOW
#include <Tensorflow/Module.hh>
#endif

#include <Python/AllophoneStateFsaBuilder.hh>
#include <Python/Configuration.hh>
Expand All @@ -27,4 +56,52 @@ PYBIND11_MODULE(librasr, m) {
&AllophoneStateFsaBuilder::buildByOrthography);
pyFsaBuilder.def("build_by_segment_name",
&AllophoneStateFsaBuilder::buildBySegmentName);

py::class_<Bliss::Symbol> symbol(m, "Symbol");
symbol
.def(py::init<>())
.def(py::init<const Bliss::Symbol&>())
.def("length", &Bliss::Symbol::length)
.def("__eq__", &Bliss::Symbol::operator==)
.def("__ne__", &Bliss::Symbol::operator!=)
.def("__bool__", [](const Bliss::Symbol &self) { return !self.operator!(); })
NurAd-Din marked this conversation as resolved.
Show resolved Hide resolved
.def("to_bool", &Bliss::Symbol::operator bool)
.def("to_string", &Bliss::Symbol::operator Bliss::Symbol::String)
.def("str", &Bliss::Symbol::str)
NurAd-Din marked this conversation as resolved.
Show resolved Hide resolved
.def_static("cast", &Bliss::Symbol::cast);

py::class_<Bliss::Symbol::Hash>(symbol, "Hash")
.def("__call__", &Bliss::Symbol::Hash::operator());

py::class_<Bliss::Symbol::Equality>(symbol, "Equality")
.def("__call__", &Bliss::Symbol::Equality::operator());

py::class_<Bliss::OrthographicFormList>(m, "OrthographicFormList")
.def(py::init<const Bliss::Symbol*, const Bliss::Symbol*>())
.def(py::init<>())
NurAd-Din marked this conversation as resolved.
Show resolved Hide resolved
NurAd-Din marked this conversation as resolved.
Show resolved Hide resolved
.def(py::init<const Bliss::SymbolSequence<Bliss::OrthographicForm>&>())
.def("valid", &Bliss::SymbolSequence<Bliss::OrthographicForm>::valid)
.def("size", &Bliss::SymbolSequence<Bliss::OrthographicForm>::size)
.def("length", &Bliss::SymbolSequence<Bliss::OrthographicForm>::length)
.def("is_epsilon", &Bliss::SymbolSequence<Bliss::OrthographicForm>::isEpsilon)
.def("front", &Bliss::SymbolSequence<Bliss::OrthographicForm>::front, py::return_value_policy::reference_internal)
.def("begin", &Bliss::SymbolSequence<Bliss::OrthographicForm>::begin, py::return_value_policy::reference_internal)
.def("end", &Bliss::SymbolSequence<Bliss::OrthographicForm>::end, py::return_value_policy::reference_internal)
.def("__getitem__", &Bliss::OrthographicFormList::operator[]);
NurAd-Din marked this conversation as resolved.
Show resolved Hide resolved

py::class_<Bliss::SyntacticTokenSequence>(m, "SyntacticTokenSequence")
.def(py::init<>())
NurAd-Din marked this conversation as resolved.
Show resolved Hide resolved
.def(py::init<const Bliss::SymbolSequence<const Bliss::SyntacticToken*>&>())
.def("valid", &Bliss::SymbolSequence<const Bliss::SyntacticToken*>::valid)
.def("size", &Bliss::SymbolSequence<const Bliss::SyntacticToken*>::size)
.def("length", &Bliss::SymbolSequence<const Bliss::SyntacticToken*>::length)
.def("is_epsilon", &Bliss::SymbolSequence<const Bliss::SyntacticToken*>::isEpsilon)
.def("front", &Bliss::SymbolSequence<const Bliss::SyntacticToken*>::front, py::return_value_policy::reference_internal)
NurAd-Din marked this conversation as resolved.
Show resolved Hide resolved
.def("__getitem__", &Bliss::SymbolSequence<const Bliss::SyntacticToken*>::operator[]);

py::class_<Bliss::Token>(m, "Token")
.def("symbol", &Bliss::Token::symbol)
.def("id", &Bliss::Token::id)
.def_readonly_static("invalid_id", &Bliss::Token::invalidId);

}