Skip to content

Commit

Permalink
major code refactoring PLUS we now create a libmbtserver
Browse files Browse the repository at this point in the history
  • Loading branch information
Ko van der Sloot authored and Ko van der Sloot committed Aug 13, 2019
1 parent d3b7205 commit 703a9d9
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ ACLOCAL_AMFLAGS = -I m4 --install

SUBDIRS = src include docs example

EXTRA_DIST = bootstrap.sh AUTHORS TODO NEWS README.md
EXTRA_DIST = bootstrap.sh AUTHORS TODO NEWS README.md mbtserver.pc

pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = mbtserver.pc

ChangeLog: NEWS
git pull; git2cl > ChangeLog
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ LIBS="$LIBS $mbt_LIBS"

AC_CONFIG_FILES([
Makefile
mbtserver.pc
src/Makefile
include/Makefile
include/mbtserver/Makefile
Expand Down
2 changes: 0 additions & 2 deletions include/mbtserver/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# $Id$
# $URL$

pkginclude_HEADERS = MbtServerBase.h
4 changes: 4 additions & 0 deletions include/mbtserver/MbtServerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,9 @@ namespace MbtServer {

void StartServer( TiCC::CL_Options& );
void StartJSONServer( TiCC::CL_Options& );
nlohmann::json TR_to_json( const Tagger::TaggerClass *,
const std::vector<Tagger::TagResult>& );
std::vector<Tagger::TagResult> json_to_TR( const nlohmann::json& );

}
#endif
12 changes: 12 additions & 0 deletions mbtserver.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@

Name: mbt
Version: @VERSION@
Description: mbt server library.
Requires.private: mbt >= 3.5
Libs: -L${libdir} -lmbtserver
Libs.private: @LIBS@
Cflags: -I${includedir}
9 changes: 8 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
AM_CPPFLAGS = -I@top_srcdir@/include
AM_CXXFLAGS = -std=c++11

LDADD = libmbtserver.la

bin_PROGRAMS = mbtserver

mbtserver_SOURCES = MbtServer.cxx MbtServerBase.cxx MbtJSONServerBase.cxx
mbtserver_SOURCES = MbtServer.cxx

lib_LTLIBRARIES = libmbtserver.la
libmbtserver_la_LDFLAGS= -version-info 1:0:0

libmbtserver_la_SOURCES = MbtServerBase.cxx MbtJSONServerBase.cxx
59 changes: 57 additions & 2 deletions src/MbtJSONServerBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,61 @@ using TiCC::operator<<;

namespace MbtServer {

nlohmann::json TR_to_json( const TaggerClass *context,
const vector<TagResult>& trs ){
nlohmann::json result = nlohmann::json::array();
for ( const auto& tr : trs ){
// lookup the assigned category
nlohmann::json one_entry;
one_entry["word"] = tr.word();
one_entry["known"] = tr.is_known();
if ( context->enriched() ){
one_entry["enrichment"] = tr.enrichment();
}
one_entry["tag"] = tr.assigned_tag();
if ( context->confidence_is_set() ){
one_entry["confidence"] = tr.confidence();
}
if ( context->distrib_is_set() ){
one_entry["distribution"] = tr.distribution();
}
if ( context->distance_is_set() ){
one_entry["distance"] = tr.distance();
}
result.push_back( one_entry );
} // end of output loop through one sentence
return result;
}

vector<TagResult> json_to_TR( const nlohmann::json& in ){
// cerr << "json_to_TR( " << in << ")" << endl;
vector<TagResult> result;
for ( auto& i : in ){
// cerr << "looping json_to_TR( " << i << ")" << endl;
TagResult tr;
tr.set_word( i["word"] );
if ( i.find("known") != i.end() ){
tr.set_known( i["known"] == "true" );
}
tr.set_tag( i["tag"] );
if ( i.find("confidence") != i.end() ){
tr.set_confidence( i["confidence"] );;
}
if ( i.find("distance") != i.end() ){
tr.set_distance( i["distance"] );
}
if ( i.find("distribution") != i.end() ){
tr.set_distribution( i["distribution"] );
}
if ( i.find("enrichment") != i.end() ){
tr.set_enrichment( i["enrichment"] );
}
result.push_back( tr );
}
return result;
}


string extract_text( nlohmann::json& my_json ){
string result;
if ( my_json.is_array() ){
Expand Down Expand Up @@ -169,7 +224,7 @@ namespace MbtServer {
SDBG << "ALIVE, got " << num << " tags" << endl;
if ( num > 0 ){
nw += num;
nlohmann::json got_json = exp->TR_to_json( v );
nlohmann::json got_json = TR_to_json( exp, v );
SDBG << "voor WRiTE json! " << got_json << endl;
args->os() << got_json << endl;
SDBG << "WROTE json!" << endl;
Expand All @@ -186,7 +241,7 @@ namespace MbtServer {
int num = v.size();
if ( num > 0 ){
nw += num;
nlohmann::json got_json = exp->TR_to_json( v );
nlohmann::json got_json = TR_to_json( exp, v );
SDBG << "voor WRiTE json!: " << got_json << endl;
args->os() << got_json << endl;
SDBG << "WROTE json!" << endl;
Expand Down

0 comments on commit 703a9d9

Please sign in to comment.