This commit is contained in:
Rafał Jaworski 2019-02-22 17:39:40 +01:00
parent b7da815f74
commit 8a365ec8be
8 changed files with 118 additions and 1 deletions

View File

@ -296,7 +296,19 @@ std::string ConcordiaServer::handleRequest(std::string & requestString) {
jsonWriter.String("newTmId"); jsonWriter.String("newTmId");
jsonWriter.Int(newId); jsonWriter.Int(newId);
jsonWriter.EndObject(); 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 { } else {
JsonGenerator::signalError(jsonWriter, "no such operation: " + operation); JsonGenerator::signalError(jsonWriter, "no such operation: " + operation);
} }

View File

@ -12,6 +12,7 @@
#include "rapidjson/error/en.h" #include "rapidjson/error/en.h"
#include "tm_dao.hpp" #include "tm_dao.hpp"
#include "source_dao.hpp"
#include "request_dao.hpp" #include "request_dao.hpp"
#include "language_dao.hpp" #include "language_dao.hpp"
#include "index_controller.hpp" #include "index_controller.hpp"
@ -50,6 +51,8 @@ private:
TmDAO _tmDAO; TmDAO _tmDAO;
SourceDAO _sourceDAO;
RequestDAO _requestDAO; RequestDAO _requestDAO;
LanguageDAO _languageDAO; LanguageDAO _languageDAO;

View File

@ -28,6 +28,8 @@
#define NAME_PARAM "name" #define NAME_PARAM "name"
#define TYPE_PARAM "type" #define TYPE_PARAM "type"
#define INTERVALS_PARAM "intervals" #define INTERVALS_PARAM "intervals"
#define EXTERNAL_ID_PARAM "externalId"
#define LINK_PARAM "link"
#define ADD_SENTENCE_OP "addSentence" #define ADD_SENTENCE_OP "addSentence"
#define ADD_SENTENCES_OP "addSentences" #define ADD_SENTENCES_OP "addSentences"
@ -46,5 +48,6 @@
#define CONCORDIA_SEARCH_OP "concordiaSearch" #define CONCORDIA_SEARCH_OP "concordiaSearch"
#define CONCORDIA_PHRASE_SEARCH_OP "concordiaPhraseSearch" #define CONCORDIA_PHRASE_SEARCH_OP "concordiaPhraseSearch"
#define ADD_TM_OP "addTm" #define ADD_TM_OP "addTm"
#define ADD_SOURCE_OP "addSource"
#define LEMMATIZER_DELIMITER "@#@" #define LEMMATIZER_DELIMITER "@#@"

View File

@ -0,0 +1,37 @@
#include "source_dao.hpp"
#include "query_param.hpp"
#include "string_param.hpp"
#include "int_param.hpp"
#include "logger.hpp"
#include <boost/foreach.hpp>
#include <libpq-fe.h>
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<QueryParam*> 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;
}

View File

@ -0,0 +1,24 @@
#ifndef SOURCE_DAO_HDR
#define SOURCE_DAO_HDR
#include <string>
#include <concordia/common/config.hpp>
#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

View File

@ -33,6 +33,7 @@ DROP TABLE IF EXISTS unit;
CREATE TABLE unit ( CREATE TABLE unit (
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
tm_id integer, tm_id integer,
source_id integer,
source_segment text, source_segment text,
target_segment text, target_segment text,
source_tokens integer[], source_tokens integer[],
@ -41,3 +42,14 @@ CREATE TABLE unit (
); );
CREATE INDEX ON unit(tm_id); 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);

View File

@ -1,6 +1,6 @@
SRC_LANG=pl SRC_LANG=pl
TRG_LANG=en TRG_LANG=en
CORPUS_NAME=opensubtitles_sample CORPUS_NAME=opensubtitles
SEPARATOR=@\#@ SEPARATOR=@\#@
DICTIONARY_WEIGHT=3 DICTIONARY_WEIGHT=3

26
tests/addSource.py Normal file
View File

@ -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