diff --git a/concordia-server/concordia_server.cpp b/concordia-server/concordia_server.cpp index f399c1a..1019693 100644 --- a/concordia-server/concordia_server.cpp +++ b/concordia-server/concordia_server.cpp @@ -296,7 +296,19 @@ std::string ConcordiaServer::handleRequest(std::string & requestString) { jsonWriter.String("newTmId"); jsonWriter.Int(newId); jsonWriter.EndObject(); + } else if (operation == ADD_SOURCE_OP) { + int externalId = _getIntParameter(d, EXTERNAL_ID_PARAM); + std::string name = _getStringParameter(d, NAME_PARAM); + std::string link = _getStringParameter(d, LINK_PARAM); + int newId = _sourceDAO.addSource(externalId, name, link); + + jsonWriter.StartObject(); + jsonWriter.String("status"); + jsonWriter.String("success"); + jsonWriter.String("newTmId"); + jsonWriter.Int(newId); + jsonWriter.EndObject(); } else { JsonGenerator::signalError(jsonWriter, "no such operation: " + operation); } diff --git a/concordia-server/concordia_server.hpp b/concordia-server/concordia_server.hpp index 635f07b..101965b 100644 --- a/concordia-server/concordia_server.hpp +++ b/concordia-server/concordia_server.hpp @@ -12,6 +12,7 @@ #include "rapidjson/error/en.h" #include "tm_dao.hpp" +#include "source_dao.hpp" #include "request_dao.hpp" #include "language_dao.hpp" #include "index_controller.hpp" @@ -50,6 +51,8 @@ private: TmDAO _tmDAO; + SourceDAO _sourceDAO; + RequestDAO _requestDAO; LanguageDAO _languageDAO; diff --git a/concordia-server/config.hpp.in b/concordia-server/config.hpp.in index 26bb711..88bb67d 100644 --- a/concordia-server/config.hpp.in +++ b/concordia-server/config.hpp.in @@ -28,6 +28,8 @@ #define NAME_PARAM "name" #define TYPE_PARAM "type" #define INTERVALS_PARAM "intervals" +#define EXTERNAL_ID_PARAM "externalId" +#define LINK_PARAM "link" #define ADD_SENTENCE_OP "addSentence" #define ADD_SENTENCES_OP "addSentences" @@ -46,5 +48,6 @@ #define CONCORDIA_SEARCH_OP "concordiaSearch" #define CONCORDIA_PHRASE_SEARCH_OP "concordiaPhraseSearch" #define ADD_TM_OP "addTm" +#define ADD_SOURCE_OP "addSource" #define LEMMATIZER_DELIMITER "@#@" diff --git a/concordia-server/source_dao.cpp b/concordia-server/source_dao.cpp new file mode 100644 index 0000000..a40fb84 --- /dev/null +++ b/concordia-server/source_dao.cpp @@ -0,0 +1,37 @@ +#include "source_dao.hpp" + +#include "query_param.hpp" +#include "string_param.hpp" +#include "int_param.hpp" +#include "logger.hpp" + +#include +#include + +SourceDAO::SourceDAO() { +} + +SourceDAO::~SourceDAO() { +} + +int SourceDAO::addSource(const int externalId, const std::string & name, const std::string & link) { + DBconnection connection; + connection.startTransaction(); + + std::string query = "INSERT INTO source(external_id, name, link) values($1::integer,$2::text,$3::text) RETURNING id"; + std::vector params; + params.push_back(new IntParam(externalId)); + params.push_back(new StringParam(name)); + params.push_back(new StringParam(link)); + + PGresult * result = connection.execute(query, params); + int newId = connection.getIntValue(result, 0, 0); + connection.clearResult(result); + connection.endTransaction(); + BOOST_FOREACH (QueryParam * param, params) { + delete param; + } + + return newId; + +} \ No newline at end of file diff --git a/concordia-server/source_dao.hpp b/concordia-server/source_dao.hpp new file mode 100644 index 0000000..09cd89e --- /dev/null +++ b/concordia-server/source_dao.hpp @@ -0,0 +1,24 @@ +#ifndef SOURCE_DAO_HDR +#define SOURCE_DAO_HDR + +#include + +#include +#include "db_connection.hpp" + +class SourceDAO { +public: + /*! Constructor. + */ + SourceDAO(); + /*! Destructor. + */ + virtual ~SourceDAO(); + + int addSource(const int externalId, const std::string & name, const std::string & link); + +private: + +}; + +#endif diff --git a/db/concordia_server.sql b/db/concordia_server.sql index 43d873e..aaf3bf4 100644 --- a/db/concordia_server.sql +++ b/db/concordia_server.sql @@ -33,6 +33,7 @@ DROP TABLE IF EXISTS unit; CREATE TABLE unit ( id SERIAL PRIMARY KEY, tm_id integer, + source_id integer, source_segment text, target_segment text, source_tokens integer[], @@ -41,3 +42,14 @@ CREATE TABLE unit ( ); CREATE INDEX ON unit(tm_id); +CREATE INDEX ON unit(source_id); + +DROP TABLE IF EXISTS source; +CREATE TABLE source ( + id SERIAL PRIMARY KEY, + external_id integer, + name text, + link text +); + +CREATE INDEX ON source(external_id); diff --git a/fast-aligner/Makefile b/fast-aligner/Makefile index 1ba1f54..6e2cf9f 100644 --- a/fast-aligner/Makefile +++ b/fast-aligner/Makefile @@ -1,6 +1,6 @@ SRC_LANG=pl TRG_LANG=en -CORPUS_NAME=opensubtitles_sample +CORPUS_NAME=opensubtitles SEPARATOR=@\#@ DICTIONARY_WEIGHT=3 diff --git a/tests/addSource.py b/tests/addSource.py new file mode 100644 index 0000000..a475ede --- /dev/null +++ b/tests/addSource.py @@ -0,0 +1,26 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import json +import urllib2 +import sys +import time +import host + +address = 'http://'+host.concordia_host +if len(host.concordia_port) > 0: + address += ':'+host.concordia_port + + +data = { + 'operation': 'addSource', + 'externalId':56, + 'name':'test ' + 'tmLemmatized':bool(int(sys.argv[4])) +} + +req = urllib2.Request(address) +req.add_header('Content-Type', 'application/json') +response = json.loads(urllib2.urlopen(req, json.dumps(data)).read()) + +print response